Returns the index of a free slot that can be populated with * a hash entry for the given 'key'. * If the key already exists, -1 is returned * and the optional output parameter may be filled. * * Note that if we are in the process of rehashing the hash table, the * index is always returned in the context of the second (new) hash table. */
| 1096 | * Note that if we are in the process of rehashing the hash table, the |
| 1097 | * index is always returned in the context of the second (new) hash table. */ |
| 1098 | static long _dictKeyIndex |
| 1099 | ( |
| 1100 | dict *d, |
| 1101 | const void *key, |
| 1102 | uint64_t hash, |
| 1103 | dictEntry **existing |
| 1104 | ) { |
| 1105 | unsigned long idx, table; |
| 1106 | dictEntry *he; |
| 1107 | if (existing) *existing = NULL; |
| 1108 | |
| 1109 | /* Expand the hash table if needed */ |
| 1110 | if (_HashTableExpandIfNeeded(d) == DICT_ERR) |
| 1111 | return -1; |
| 1112 | for (table = 0; table <= 1; table++) { |
| 1113 | idx = hash & DICTHT_SIZE_MASK(d->ht_size_exp[table]); |
| 1114 | /* Search if this slot does not already contain the given key */ |
| 1115 | he = d->ht_table[table][idx]; |
| 1116 | while(he) { |
| 1117 | if (key==he->key || dictCompareKeys(d, key, he->key)) { |
| 1118 | if (existing) *existing = he; |
| 1119 | return -1; |
| 1120 | } |
| 1121 | he = he->next; |
| 1122 | } |
| 1123 | if (!dictIsRehashing(d)) break; |
| 1124 | } |
| 1125 | return idx; |
| 1126 | } |
| 1127 | |
| 1128 | void HashTableEmpty(dict *d, void(callback)(dict*)) { |
| 1129 | _dictClear(d,0,callback); |
no test coverage detected