Skip to content

Instantly share code, notes, and snippets.

@Milerius
Created December 19, 2019 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Milerius/4f4f889400307e16d1eb5ab80ca56311 to your computer and use it in GitHub Desktop.
Save Milerius/4f4f889400307e16d1eb5ab80ca56311 to your computer and use it in GitHub Desktop.
class ConstIterator {
public:
friend class ConcurrentHashMap;
const value_type& operator*() const {
return *it_;
}
const value_type* operator->() const {
return &*it_;
}
ConstIterator& operator++() {
++it_;
next();
return *this;
}
bool operator==(const ConstIterator& o) const {
return it_ == o.it_ && segment_ == o.segment_;
}
bool operator!=(const ConstIterator& o) const {
return !(*this == o);
}
ConstIterator& operator=(const ConstIterator& o) = delete;
ConstIterator& operator=(ConstIterator&& o) noexcept {
if (this != &o) {
it_ = std::move(o.it_);
segment_ = std::exchange(o.segment_, uint64_t(NumShards));
parent_ = std::exchange(o.parent_, nullptr);
}
return *this;
}
ConstIterator(const ConstIterator& o) = delete;
ConstIterator(ConstIterator&& o) noexcept
: it_(std::move(o.it_)),
segment_(std::exchange(o.segment_, uint64_t(NumShards))),
parent_(std::exchange(o.parent_, nullptr)) {}
ConstIterator(const ConcurrentHashMap* parent, uint64_t segment)
: segment_(segment), parent_(parent) {}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment