aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorAlberto Gonzalez <boqwxp@airmail.cc>2020-04-20 02:16:55 +0000
committerAlberto Gonzalez <boqwxp@airmail.cc>2020-04-20 02:18:30 +0000
commit95b94ad19b025cef0617610a2605f23688a48a2f (patch)
tree0fde9353488abab74371fbf1f41299fb1386a2f5 /kernel
parent2b1fb8c0a06e6f7b2107c9f623ed9e55b002a7f6 (diff)
downloadyosys-95b94ad19b025cef0617610a2605f23688a48a2f.tar.gz
yosys-95b94ad19b025cef0617610a2605f23688a48a2f.tar.bz2
yosys-95b94ad19b025cef0617610a2605f23688a48a2f.zip
In `pool`, construct `entry_t`s in-place and add an rvalue-accepting-and-forwarding `insert()` method.
Diffstat (limited to 'kernel')
-rw-r--r--kernel/hashlib.h27
1 files changed, 25 insertions, 2 deletions
diff --git a/kernel/hashlib.h b/kernel/hashlib.h
index 996bda38e..1a21494a7 100644
--- a/kernel/hashlib.h
+++ b/kernel/hashlib.h
@@ -745,11 +745,24 @@ protected:
int do_insert(const K &value, int &hash)
{
if (hashtable.empty()) {
- entries.push_back(entry_t(value, -1));
+ entries.emplace_back(value, -1);
+ do_rehash();
+ hash = do_hash(value);
+ } else {
+ entries.emplace_back(value, hashtable[hash]);
+ hashtable[hash] = entries.size() - 1;
+ }
+ return entries.size() - 1;
+ }
+
+ int do_insert(K &&value, int &hash)
+ {
+ if (hashtable.empty()) {
+ entries.emplace_back(std::forward<K>(value), -1);
do_rehash();
hash = do_hash(value);
} else {
- entries.push_back(entry_t(value, hashtable[hash]));
+ entries.emplace_back(std::forward<K>(value), hashtable[hash]);
hashtable[hash] = entries.size() - 1;
}
return entries.size() - 1;
@@ -847,6 +860,16 @@ public:
return std::pair<iterator, bool>(iterator(this, i), true);
}
+ std::pair<iterator, bool> insert(K &&value)
+ {
+ int hash = do_hash(value);
+ int i = do_lookup(value, hash);
+ if (i >= 0)
+ return std::pair<iterator, bool>(iterator(this, i), false);
+ i = do_insert(std::forward<K>(value), hash);
+ return std::pair<iterator, bool>(iterator(this, i), true);
+ }
+
int erase(const K &key)
{
int hash = do_hash(key);