Rename overloaded `insert()` to `emplace()` and add overloaded versions for all possi...
authorAlberto Gonzalez <boqwxp@airmail.cc>
Wed, 15 Apr 2020 16:22:22 +0000 (16:22 +0000)
committerAlberto Gonzalez <boqwxp@airmail.cc>
Thu, 16 Apr 2020 03:54:33 +0000 (03:54 +0000)
kernel/hashlib.h

index f15a9d611ef92bc0b309f9896896dc5a5f57c073..996bda38e560aeb496c826fb7410c345bf3e7972 100644 (file)
@@ -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);