45 return owner->elements[i];
50 return owner->elements.data()+i;
53 bool operator==(
const Iterator& it)
const {
57 bool operator!=(
const Iterator& it)
const {
90 return owner->elements[i];
95 return owner->elements.data()+i;
106 const HashSet<T>* owner;
110 HashSet(
int sizeHint = 10) {
111 elements.reserve(sizeHint);
112 idxMap.reserve(sizeHint);
121 if (elements.size()==elements.capacity()) {
122 size_t newSize = std::max(elements.size(),
size_t(1)) * 2;
140 if (
it != idxMap.end()) {
145 auto itLast = idxMap.find(elements.back());
148 std::swap(elements[
itLast->second], elements[
it->second]);
180 idxMap.reserve(
count);
181 elements.reserve(
count);
189 if (
it != idxMap.end()) {
201 if (
it != idxMap.end()) {
210 return elements.empty();
215 return elements.size();
220 return elements.capacity();
235 return Iterator(
this,
int(elements.size()));
245 std::vector<T> elements;
248 std::unordered_map<T, int> idxMap;
void freeMem()
Definition hashSet.h:168
size_t size() const
Definition hashSet.h:214
ConstIterator find(const T &newElement) const
Definition hashSet.h:199
void clear()
Definition hashSet.h:161
size_t capacity() const
Definition hashSet.h:219
Iterator begin()
Definition hashSet.h:224
bool insert(const T &newElement)
Definition hashSet.h:118
ConstIterator begin() const
Definition hashSet.h:229
void erase(const T &element)
Definition hashSet.h:138
ConstIterator end() const
Definition hashSet.h:239
bool empty() const
Definition hashSet.h:209
Iterator end()
Definition hashSet.h:234
void reserve(size_t count)
Definition hashSet.h:179
Iterator find(const T &element)
Definition hashSet.h:187
Iterator to iterate through the elements of a const HashSet.
Definition hashSet.h:66
const T * operator->()
Definition hashSet.h:94
ConstIterator(const HashSet< T > *owner, int i)
Definition hashSet.h:72
ConstIterator & operator++()
Definition hashSet.h:76
const T & operator*()
Definition hashSet.h:89
ConstIterator operator++(int)
Definition hashSet.h:83
Iterator to iterate through the elements of a non-const HashSet.
Definition hashSet.h:21
Iterator(HashSet< T > *owner, int i)
Definition hashSet.h:27
T & operator*()
Definition hashSet.h:44
Iterator operator++(int)
Definition hashSet.h:38
T * operator->()
Definition hashSet.h:49
Iterator & operator++()
Definition hashSet.h:31