From 5eb1f83d2d8da1f5390ed1a2658793a4e25809ba Mon Sep 17 00:00:00 2001 From: Alberto Gonzalez Date: Wed, 15 Apr 2020 16:22:22 +0000 Subject: [PATCH] Rename overloaded `insert()` to `emplace()` and add overloaded versions for all possible lvalue/rvalue combinationsfor its arguments. --- kernel/hashlib.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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(this, i), true); } - std::pair insert(K const &key, T &&rvalue) + std::pair 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(this, i), false); + i = do_insert(std::make_pair(key, value), hash); + return std::pair(iterator(this, i), true); + } + + std::pair 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(this, i), true); } + std::pair emplace(K &&rkey, T const &value) + { + int hash = do_hash(rkey); + int i = do_lookup(rkey, hash); + if (i >= 0) + return std::pair(iterator(this, i), false); + i = do_insert(std::make_pair(std::forward(rkey), value), hash); + return std::pair(iterator(this, i), true); + } + + std::pair emplace(K &&rkey, T &&rvalue) + { + int hash = do_hash(rkey); + int i = do_lookup(rkey, hash); + if (i >= 0) + return std::pair(iterator(this, i), false); + i = do_insert(std::make_pair(std::forward(rkey), std::forward(rvalue)), hash); + return std::pair(iterator(this, i), true); + } + int erase(const K &key) { int hash = do_hash(key); -- 2.30.2