edits
[iotcloud.git] / version2 / src / C / hashtable.h
index 513d31198e5e379b6576c941a353e5b789080240..c642804f99433c1ab221ae6c220c2345459d2346 100644 (file)
@@ -190,16 +190,19 @@ public:
         * @param key The key for the new value; must not be 0 or NULL
         * @param val The value to store in the table
         */
-       void put(_Key key, _Val val) {
+       _Val put(_Key key, _Val val) {
                /* Hashtable cannot handle 0 as a key */
                if (!key) {
+                       _Val oldval;
                        if (!zero) {
                                zero = (struct Hashlistnode<_Key, _Val> *)ourmalloc(sizeof(struct Hashlistnode<_Key, _Val>));
                                size++;
-                       }
+                               oldval = (_Val) 0;
+                       } else
+                               oldval = zero->val;
                        zero->key = key;
                        zero->val = val;
-                       return;
+                       return oldval;
                }
 
                if (size > threshold)
@@ -218,8 +221,9 @@ public:
                        }
                        if (search->hashcode == hashcode)
                                if (equals(search->key, key)) {
+                                       _Val oldval = search->val;
                                        search->val = val;
-                                       return;
+                                       return oldval;
                                }
                        index++;
                } while (true);
@@ -228,6 +232,7 @@ public:
                search->val = val;
                search->hashcode = hashcode;
                size++;
+               return (_Val) 0;
        }
 
        /**