aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorEddie Hung <eddie@fpgeh.com>2020-04-22 12:10:42 -0700
committerGitHub <noreply@github.com>2020-04-22 12:10:42 -0700
commitbf22cda91294d56419f7e157081acf0cf36e40f2 (patch)
tree6b34bb057052f44f0f3d290bff6781931612a92b /kernel
parentdb27f2f3786fa867bf7524aff6a5b72c89932620 (diff)
parenta7c66fdc61508017113a93b51ea79827fb67adfc (diff)
downloadyosys-bf22cda91294d56419f7e157081acf0cf36e40f2.tar.gz
yosys-bf22cda91294d56419f7e157081acf0cf36e40f2.tar.bz2
yosys-bf22cda91294d56419f7e157081acf0cf36e40f2.zip
Merge pull request #1969 from boqwxp/pool_emplace
kernel: Add `pool` support for rvalue references and C++11 move semantics.
Diffstat (limited to 'kernel')
-rw-r--r--kernel/hashlib.h34
1 files changed, 32 insertions, 2 deletions
diff --git a/kernel/hashlib.h b/kernel/hashlib.h
index 97fadea0e..592d6e577 100644
--- a/kernel/hashlib.h
+++ b/kernel/hashlib.h
@@ -642,6 +642,7 @@ protected:
entry_t() { }
entry_t(const K &udata, int next) : udata(udata), next(next) { }
+ entry_t(K &&udata, int next) : udata(std::move(udata)), next(next) { }
};
std::vector<int> hashtable;
@@ -745,11 +746,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.push_back(entry_t(value, hashtable[hash]));
+ entries.emplace_back(value, hashtable[hash]);
+ hashtable[hash] = entries.size() - 1;
+ }
+ return entries.size() - 1;
+ }
+
+ int do_insert(K &&rvalue, int &hash)
+ {
+ if (hashtable.empty()) {
+ entries.emplace_back(std::forward<K>(rvalue), -1);
+ do_rehash();
+ hash = do_hash(rvalue);
+ } else {
+ entries.emplace_back(std::forward<K>(rvalue), hashtable[hash]);
hashtable[hash] = entries.size() - 1;
}
return entries.size() - 1;
@@ -847,6 +861,22 @@ public:
return std::pair<iterator, bool>(iterator(this, i), true);
}
+ std::pair<iterator, bool> insert(K &&rvalue)
+ {
+ int hash = do_hash(rvalue);
+ int i = do_lookup(rvalue, hash);
+ if (i >= 0)
+ return std::pair<iterator, bool>(iterator(this, i), false);
+ i = do_insert(std::forward<K>(rvalue), hash);
+ return std::pair<iterator, bool>(iterator(this, i), true);
+ }
+
+ template<typename... Args>
+ std::pair<iterator, bool> emplace(Args&&... args)
+ {
+ return insert(K(std::forward<Args>(args)...));
+ }
+
int erase(const K &key)
{
int hash = do_hash(key);