diff options
author | Clifford Wolf <clifford@clifford.at> | 2014-12-31 14:52:46 +0100 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2014-12-31 14:52:46 +0100 |
commit | 1e08621e7e2c219169b3b6c5fe1d581052e4d429 (patch) | |
tree | b02812520effc8454740652f8ea5c5a89ad0127d /kernel | |
parent | 539dd805f44ece3e39f4c68e4ea1bdc9b662e83f (diff) | |
download | yosys-1e08621e7e2c219169b3b6c5fe1d581052e4d429.tar.gz yosys-1e08621e7e2c219169b3b6c5fe1d581052e4d429.tar.bz2 yosys-1e08621e7e2c219169b3b6c5fe1d581052e4d429.zip |
Added hashlib .count(key, iterator) and it1 < it2
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/hashlib.h | 87 |
1 files changed, 50 insertions, 37 deletions
diff --git a/kernel/hashlib.h b/kernel/hashlib.h index 29f4f68b1..5e00e89d6 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -287,38 +287,41 @@ class dict } 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() @@ -398,6 +401,13 @@ public: 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); @@ -475,13 +485,6 @@ public: const_iterator end() const { return const_iterator(nullptr, -1); } }; -// ******************************************************************************** -// ******************************************************************************** -// ******************************************************************************** -// ******************************************************************************** -// ******************************************************************************** - - template<typename K, typename OPS = hash_ops<K>> class pool { @@ -606,36 +609,39 @@ 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() @@ -715,6 +721,13 @@ public: 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); |