22 #ifndef HPL1_STD_SET_H 23 #define HPL1_STD_SET_H 25 #include "common/rb_tree.h" 30 template<
class T,
class CompFn = Common::Less<T> >
39 return _items.
begin();
46 const_iterator begin()
const {
47 return _items.
begin();
50 const_iterator end()
const {
59 return _items.
size() == 0;
69 iterator
find(
const T &item) {
71 if (it != _items.
end() && CompareEq(*it, item)) {
82 if (it == _items.
end() || !CompareEq(*it, item)) {
83 const auto position = _items.
insert(it, item);
84 return {position,
true};
89 void erase(iterator item) {
93 void erase(iterator first, iterator last) {
94 _items.
erase(first, last);
97 size_t erase(
const T &item) {
98 iterator it =
find(item);
111 for (
auto it = _items.
lowerBound(item); it != end() && CompareEq(*it, item); ++it)
117 static bool CompareEq(
const T &a,
const T &b) {
118 return !CompFn()(a, b) && !CompFn()(b, a);
BasicIterator lowerBound(const Key &key)
Definition: rb_tree.h:181
BasicIterator insert(const ValueType &val)
Definition: rb_tree.h:302
size_t count(const T &item) const
Definition: set.h:109
iterator find(const T &item)
Definition: set.h:69
Iterator< const T &, const T *> ConstIterator
Definition: rb_tree.h:123
Iterator< T &, T *> BasicIterator
Definition: rb_tree.h:122
BasicIterator erase(BasicIterator it)
Definition: rb_tree.h:250
void clear()
Definition: rb_tree.h:158
Common::Pair< iterator, bool > insert(const T &item)
Definition: set.h:80
size_t size() const
Definition: rb_tree.h:327
Definition: algorithm.h:37
BasicIterator begin()
Definition: rb_tree.h:166
Definition: algorithms.h:27
BasicIterator end()
Definition: rb_tree.h:172