add support for bidirectional iterators on non-parallel hashmaps - issue #58

This commit is contained in:
greg
2020-08-16 21:49:26 -04:00
parent d8ee7f5901
commit c8a0e5a2b8
+28 -2
View File
@@ -880,6 +880,25 @@ public:
return tmp;
}
#if PHMAP_BIDIRECTIONAL
// PRECONDITION: not a begin() iterator.
iterator& operator--() {
assert(ctrl_);
do {
--ctrl_;
--slot_;
} while (IsEmptyOrDeleted(*ctrl_));
return *this;
}
// PRECONDITION: not a begin() iterator.
iterator operator--(int) {
auto tmp = *this;
--*this;
return tmp;
}
#endif
friend bool operator==(const iterator& a, const iterator& b) {
return a.ctrl_ == b.ctrl_;
}
@@ -904,7 +923,7 @@ public:
}
ctrl_t* ctrl_ = nullptr;
// To avoid uninitialized member warnigs, put slot_ in an anonymous union.
// To avoid uninitialized member warnings, put slot_ in an anonymous union.
// The member is not initialized on singleton and end iterators.
union {
slot_type* slot_;
@@ -1143,7 +1162,14 @@ public:
it.skip_empty_or_deleted();
return it;
}
iterator end() { return {ctrl_ + capacity_}; }
iterator end()
{
#if PHMAP_BIDIRECTIONAL
return iterator_at(capacity_);
#else
return {ctrl_ + capacity_};
#endif
}
const_iterator begin() const {
return const_cast<raw_hash_set*>(this)->begin();