3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-08-03 18:00:24 +00:00

Make pool const lookup methods take a lookup path that never rehashes the table.

This avoids the need to cast away `const` and makes these methods thread-compatible.
This commit is contained in:
Robert O'Callahan 2025-07-15 03:02:35 +00:00
parent cf9720ecab
commit 4bf7c23e2b

View file

@ -919,16 +919,21 @@ protected:
return 1; return 1;
} }
int do_lookup(const K &key, Hasher::hash_t &hash) const int do_lookup(const K &key, Hasher::hash_t &hash)
{ {
if (hashtable.empty()) if (hashtable.empty())
return -1; return -1;
if (entries.size() * hashtable_size_trigger > hashtable.size()) { if (entries.size() * hashtable_size_trigger > hashtable.size()) {
((pool*)this)->do_rehash(); do_rehash();
hash = do_hash(key); hash = do_hash(key);
} }
return do_lookup_internal(key, hash);
}
int do_lookup_internal(const K &key, Hasher::hash_t hash) const
{
int index = hashtable[hash]; int index = hashtable[hash];
while (index >= 0 && !ops.cmp(entries[index].udata, key)) { while (index >= 0 && !ops.cmp(entries[index].udata, key)) {
@ -939,6 +944,14 @@ protected:
return index; return index;
} }
int do_lookup_no_rehash(const K &key, Hasher::hash_t hash) const
{
if (hashtable.empty())
return -1;
return do_lookup_internal(key, hash);
}
int do_insert(const K &value, Hasher::hash_t &hash) int do_insert(const K &value, Hasher::hash_t &hash)
{ {
if (hashtable.empty()) { if (hashtable.empty()) {
@ -1100,14 +1113,14 @@ public:
int count(const K &key) const int count(const K &key) const
{ {
Hasher::hash_t hash = do_hash(key); Hasher::hash_t hash = do_hash(key);
int i = do_lookup(key, hash); int i = do_lookup_no_rehash(key, hash);
return i < 0 ? 0 : 1; return i < 0 ? 0 : 1;
} }
int count(const K &key, const_iterator it) const int count(const K &key, const_iterator it) const
{ {
Hasher::hash_t hash = do_hash(key); Hasher::hash_t hash = do_hash(key);
int i = do_lookup(key, hash); int i = do_lookup_no_rehash(key, hash);
return i < 0 || i > it.index ? 0 : 1; return i < 0 || i > it.index ? 0 : 1;
} }
@ -1123,7 +1136,7 @@ public:
const_iterator find(const K &key) const const_iterator find(const K &key) const
{ {
Hasher::hash_t hash = do_hash(key); Hasher::hash_t hash = do_hash(key);
int i = do_lookup(key, hash); int i = do_lookup_no_rehash(key, hash);
if (i < 0) if (i < 0)
return end(); return end();
return const_iterator(this, i); return const_iterator(this, i);
@ -1235,7 +1248,7 @@ public:
int at(const K &key) const int at(const K &key) const
{ {
Hasher::hash_t hash = database.do_hash(key); Hasher::hash_t hash = database.do_hash(key);
int i = database.do_lookup(key, hash); int i = database.do_lookup_no_rehash(key, hash);
if (i < 0) if (i < 0)
throw std::out_of_range("idict::at()"); throw std::out_of_range("idict::at()");
return i + offset; return i + offset;
@ -1244,7 +1257,7 @@ public:
int at(const K &key, int defval) const int at(const K &key, int defval) const
{ {
Hasher::hash_t hash = database.do_hash(key); Hasher::hash_t hash = database.do_hash(key);
int i = database.do_lookup(key, hash); int i = database.do_lookup_no_rehash(key, hash);
if (i < 0) if (i < 0)
return defval; return defval;
return i + offset; return i + offset;
@ -1253,7 +1266,7 @@ public:
int count(const K &key) const int count(const K &key) const
{ {
Hasher::hash_t hash = database.do_hash(key); Hasher::hash_t hash = database.do_hash(key);
int i = database.do_lookup(key, hash); int i = database.do_lookup_no_rehash(key, hash);
return i < 0 ? 0 : 1; return i < 0 ? 0 : 1;
} }