| 86 | }; |
| 87 | |
| 88 | class Iterator { |
| 89 | public: |
| 90 | Iterator(Entry *entries, size_t capacity, size_t index) |
| 91 | : entries_(entries), capacity_(capacity), index_(index) { |
| 92 | while (index_ < capacity_ && entries_[index_].key == k_empty) |
| 93 | ++index_; |
| 94 | } |
| 95 | std::pair<K, V> operator*() const { |
| 96 | return {entries_[index_].key, entries_[index_].value}; |
| 97 | } |
| 98 | const Entry *operator->() const { return &entries_[index_]; } |
| 99 | Iterator &operator++() { |
| 100 | ++index_; |
| 101 | while (index_ < capacity_ && entries_[index_].key == k_empty) |
| 102 | ++index_; |
| 103 | return *this; |
| 104 | } |
| 105 | bool operator==(const Iterator &other) const { |
| 106 | return index_ == other.index_; |
| 107 | } |
| 108 | bool operator!=(const Iterator &other) const { return !(*this == other); } |
| 109 | |
| 110 | private: |
| 111 | Entry *entries_; |
| 112 | size_t capacity_; |
| 113 | size_t index_; |
| 114 | }; |
| 115 | |
| 116 | explicit FlatIntMap(size_t initial_capacity = 64, |
| 117 | float load_factor = k_default_load_factor) |