+ index &= capacitymask;
+ if (index==oindex)
+ break;
+ } while (true);
+ return (_Val)0;
+ }
+
+ /**
+ * @brief Remove the given key and return the corresponding value
+ * @param key The key for finding the value; must not be 0 or NULL
+ * @return The value in the table, if the key is found; otherwise 0
+ */
+ _Val remove(_Key key) {
+ struct hashlistnode<_Key, _Val> *search;
+ struct hashlistnode<_Key, _Val> *replace;
+
+ /* HashTable cannot handle 0 as a key */
+ if (!key) {
+ if (!zero) {
+ return (_Val)0;
+ } else {
+ _Val v=zero->val;
+ _free(zero);
+ zero=NULL;
+ size--;
+ return v;
+ }
+ }
+
+
+ unsigned int index = hash_function(key);
+ do {
+ index &= capacitymask;
+ search = &table[index];
+ if (!search->key) {
+ if (!search->val)
+ break;
+ } else {
+ // The case where an item is found
+ if (equals(search->key, key)) {
+ unsigned int j = index;
+ _Val v = search->val;
+ size--;
+
+ // Idea: keep bins contiguous
+ while (true) {
+ search->val = 0;
+ search->key = 0;
+
+ while (true) {
+ j = (j + 1) & capacitymask;
+ replace = &table[j];
+
+ if (!replace->key && !replace->val) {
+ return v;
+ }
+
+ unsigned int hash = hash_function(replace->key) & capacitymask;
+ if (index <= j && index < hash && hash <= j)
+ continue;
+ else if (index > j && (index < hash || hash <= j) )
+ continue;
+ else
+ break;
+ }
+
+ table[index] = table[j];
+ index = j;
+ search = &table[index];
+ }
+ }
+ }
+ index++;
+ } while (true);