+template<typename KeyT, typename ValueT, typename KeyInfoT>
+class DenseMapIterator {
+ typedef std::pair<KeyT, ValueT> BucketT;
+protected:
+ const BucketT *Ptr, *End;
+public:
+ DenseMapIterator(const BucketT *Pos, const BucketT *E) : Ptr(Pos), End(E) {
+ AdvancePastEmptyBuckets();
+ }
+
+ std::pair<KeyT, ValueT> &operator*() const {
+ return *const_cast<BucketT*>(Ptr);
+ }
+ std::pair<KeyT, ValueT> *operator->() const {
+ return const_cast<BucketT*>(Ptr);
+ }
+
+ bool operator==(const DenseMapIterator &RHS) const {
+ return Ptr == RHS.Ptr;
+ }
+ bool operator!=(const DenseMapIterator &RHS) const {
+ return Ptr != RHS.Ptr;
+ }
+
+ inline DenseMapIterator& operator++() { // Preincrement
+ ++Ptr;
+ AdvancePastEmptyBuckets();
+ return *this;
+ }
+ DenseMapIterator operator++(int) { // Postincrement
+ DenseMapIterator tmp = *this; ++*this; return tmp;
+ }
+
+private:
+ void AdvancePastEmptyBuckets() {
+ const KeyT Empty = KeyInfoT::getEmptyKey();
+ const KeyT Tombstone = KeyInfoT::getTombstoneKey();
+
+ while (Ptr != End && (Ptr->first == Empty || Ptr->first == Tombstone))
+ ++Ptr;
+ }
+};
+
+template<typename KeyT, typename ValueT, typename KeyInfoT>
+class DenseMapConstIterator : public DenseMapIterator<KeyT, ValueT, KeyInfoT> {
+public:
+ DenseMapConstIterator(const std::pair<KeyT, ValueT> *Pos,
+ const std::pair<KeyT, ValueT> *E)
+ : DenseMapIterator<KeyT, ValueT, KeyInfoT>(Pos, E) {
+ }
+ const std::pair<KeyT, ValueT> &operator*() const {
+ return *this->Ptr;
+ }
+ const std::pair<KeyT, ValueT> *operator->() const {
+ return this->Ptr;
+ }
+};
+