Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class allocator;
- template<typename K, typename T,
- typename Hash = std::hash<K>,
- typename Pred = std::equal_to<K>,
- typename Alloc = allocator<std::pair<const K, T>>>
- class hash_map;
- template<typename ValueType>
- class hash_map_iterator {
- public:
- using iterator_category = std::forward_iterator_tag;
- using value_type = ValueType;
- using difference_type = std::ptrdiff_t;
- using reference = ValueType&;
- using pointer = ValueType*;
- hash_map_iterator() noexcept {
- }
- hash_map_iterator(const hash_map_iterator &other) noexcept {
- point = other.point;
- state = other.state;
- position = other.position;
- }
- reference operator*() const {
- return &point + position;
- }
- pointer operator->() const {
- return point + position;
- }
- // prefix ++
- hash_map_iterator &operator++() {
- int i = 1;
- while (*(state->begin() + i + position) != State::_using) {
- ++i;
- }
- position += i;
- point = point + position;
- }
- // postfix ++
- hash_map_iterator operator++(int) {
- hash_map_iterator res(*this);
- ++this;
- return res;
- }
- friend bool operator==(const hash_map_iterator<ValueType> &a, const hash_map_iterator<ValueType> &b) {
- return a.position == b.position;
- }
- friend bool operator!=(const hash_map_iterator<ValueType> &a, const hash_map_iterator<ValueType> &b) {
- return a.position != b.position;
- }
- template<typename K, typename T,
- typename Hash,
- typename Pred,
- typename Alloc>
- friend
- class hash_map;
- private:
- hash_map_iterator(value_type *map_cell, size_t pos, std::vector<State> *states) noexcept {
- point = map_cell;
- position = pos;
- state = states;
- }
- value_type *point;
- std::vector<State> *state;
- size_t position;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement