}
public:
- class iterator
+ class const_iterator
{
friend class dict;
protected:
- dict *ptr;
+ const dict *ptr;
int index;
+ const_iterator(const dict *ptr, int index) : ptr(ptr), index(index) { }
public:
- iterator() { }
- iterator(dict *ptr, int index) : ptr(ptr), index(index) { }
- iterator operator++() { index--; return *this; }
- bool operator==(const iterator &other) const { return index == other.index; }
- bool operator!=(const iterator &other) const { return index != other.index; }
- std::pair<K, T> &operator*() { return ptr->entries[index].udata; }
- std::pair<K, T> *operator->() { return &ptr->entries[index].udata; }
+ const_iterator() { }
+ const_iterator operator++() { index--; return *this; }
+ bool operator<(const const_iterator &other) const { return index > other.index; }
+ bool operator==(const const_iterator &other) const { return index == other.index; }
+ bool operator!=(const const_iterator &other) const { return index != other.index; }
const std::pair<K, T> &operator*() const { return ptr->entries[index].udata; }
const std::pair<K, T> *operator->() const { return &ptr->entries[index].udata; }
};
- class const_iterator
+ class iterator
{
friend class dict;
protected:
- const dict *ptr;
+ dict *ptr;
int index;
+ iterator(dict *ptr, int index) : ptr(ptr), index(index) { }
public:
- const_iterator() { }
- const_iterator(const dict *ptr, int index) : ptr(ptr), index(index) { }
- const_iterator operator++() { index--; return *this; }
- bool operator==(const const_iterator &other) const { return index == other.index; }
- bool operator!=(const const_iterator &other) const { return index != other.index; }
+ iterator() { }
+ iterator operator++() { index--; return *this; }
+ bool operator<(const iterator &other) const { return index > other.index; }
+ bool operator==(const iterator &other) const { return index == other.index; }
+ bool operator!=(const iterator &other) const { return index != other.index; }
+ std::pair<K, T> &operator*() { return ptr->entries[index].udata; }
+ std::pair<K, T> *operator->() { return &ptr->entries[index].udata; }
const std::pair<K, T> &operator*() const { return ptr->entries[index].udata; }
const std::pair<K, T> *operator->() const { return &ptr->entries[index].udata; }
+ operator const_iterator() const { return const_iterator(ptr, index); }
};
dict()
return i < 0 ? 0 : 1;
}
+ int count(const K &key, const_iterator it) const
+ {
+ int hash = do_hash(key);
+ int i = do_lookup(key, hash);
+ return i < 0 || i > it.index ? 0 : 1;
+ }
+
iterator find(const K &key)
{
int hash = do_hash(key);
const_iterator end() const { return const_iterator(nullptr, -1); }
};
-// ********************************************************************************
-// ********************************************************************************
-// ********************************************************************************
-// ********************************************************************************
-// ********************************************************************************
-
-
template<typename K, typename OPS = hash_ops<K>>
class pool
{
}
public:
- class iterator
+ class const_iterator
{
friend class pool;
protected:
- pool *ptr;
+ const pool *ptr;
int index;
+ const_iterator(const pool *ptr, int index) : ptr(ptr), index(index) { }
public:
- iterator() { }
- iterator(pool *ptr, int index) : ptr(ptr), index(index) { }
- iterator operator++() { index--; return *this; }
- bool operator==(const iterator &other) const { return index == other.index; }
- bool operator!=(const iterator &other) const { return index != other.index; }
+ const_iterator() { }
+ const_iterator operator++() { index--; return *this; }
+ bool operator==(const const_iterator &other) const { return index == other.index; }
+ bool operator!=(const const_iterator &other) const { return index != other.index; }
const K &operator*() const { return ptr->entries[index].udata; }
const K *operator->() const { return &ptr->entries[index].udata; }
};
- class const_iterator
+ class iterator
{
friend class pool;
protected:
- const pool *ptr;
+ pool *ptr;
int index;
+ iterator(pool *ptr, int index) : ptr(ptr), index(index) { }
public:
- const_iterator() { }
- const_iterator(const pool *ptr, int index) : ptr(ptr), index(index) { }
- const_iterator operator++() { index--; return *this; }
- bool operator==(const const_iterator &other) const { return index == other.index; }
- bool operator!=(const const_iterator &other) const { return index != other.index; }
+ iterator() { }
+ iterator operator++() { index--; return *this; }
+ bool operator==(const iterator &other) const { return index == other.index; }
+ bool operator!=(const iterator &other) const { return index != other.index; }
+ K &operator*() { return ptr->entries[index].udata; }
+ K *operator->() { return &ptr->entries[index].udata; }
const K &operator*() const { return ptr->entries[index].udata; }
const K *operator->() const { return &ptr->entries[index].udata; }
+ operator const_iterator() const { return const_iterator(ptr, index); }
};
pool()
return i < 0 ? 0 : 1;
}
+ int count(const K &key, const_iterator it) const
+ {
+ int hash = do_hash(key);
+ int i = do_lookup(key, hash);
+ return i < 0 || i > it.index ? 0 : 1;
+ }
+
iterator find(const K &key)
{
int hash = do_hash(key);