diff options
author | Alberto Gonzalez <boqwxp@airmail.cc> | 2020-04-15 16:22:22 +0000 |
---|---|---|
committer | Alberto Gonzalez <boqwxp@airmail.cc> | 2020-04-16 03:54:33 +0000 |
commit | 5eb1f83d2d8da1f5390ed1a2658793a4e25809ba (patch) | |
tree | bbd2e269175861a47fc945a3f1aac1c6bfea6708 /kernel/hashlib.h | |
parent | c479fdeb85a3b3b607228a729cc2ead40caab50c (diff) | |
download | yosys-5eb1f83d2d8da1f5390ed1a2658793a4e25809ba.tar.gz yosys-5eb1f83d2d8da1f5390ed1a2658793a4e25809ba.tar.bz2 yosys-5eb1f83d2d8da1f5390ed1a2658793a4e25809ba.zip |
Rename overloaded `insert()` to `emplace()` and add overloaded versions for all possible lvalue/rvalue combinationsfor its arguments.
Diffstat (limited to 'kernel/hashlib.h')
-rw-r--r-- | kernel/hashlib.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/kernel/hashlib.h b/kernel/hashlib.h index f15a9d611..996bda38e 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -465,7 +465,17 @@ public: return std::pair<iterator, bool>(iterator(this, i), true); } - std::pair<iterator, bool> insert(K const &key, T &&rvalue) + std::pair<iterator, bool> emplace(K const &key, T const &value) + { + int hash = do_hash(key); + int i = do_lookup(key, hash); + if (i >= 0) + return std::pair<iterator, bool>(iterator(this, i), false); + i = do_insert(std::make_pair(key, value), hash); + return std::pair<iterator, bool>(iterator(this, i), true); + } + + std::pair<iterator, bool> emplace(K const &key, T &&rvalue) { int hash = do_hash(key); int i = do_lookup(key, hash); @@ -475,6 +485,26 @@ public: return std::pair<iterator, bool>(iterator(this, i), true); } + std::pair<iterator, bool> emplace(K &&rkey, T const &value) + { + int hash = do_hash(rkey); + int i = do_lookup(rkey, hash); + if (i >= 0) + return std::pair<iterator, bool>(iterator(this, i), false); + i = do_insert(std::make_pair(std::forward<K>(rkey), value), hash); + return std::pair<iterator, bool>(iterator(this, i), true); + } + + std::pair<iterator, bool> emplace(K &&rkey, T &&rvalue) + { + int hash = do_hash(rkey); + int i = do_lookup(rkey, hash); + if (i >= 0) + return std::pair<iterator, bool>(iterator(this, i), false); + i = do_insert(std::make_pair(std::forward<K>(rkey), std::forward<T>(rvalue)), hash); + return std::pair<iterator, bool>(iterator(this, i), true); + } + int erase(const K &key) { int hash = do_hash(key); |