MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _HashTableExpandIfNeeded

Function _HashTableExpandIfNeeded

src/util/dict.c:1051–1075  ·  view source on GitHub ↗

Expand the hash table if needed */

Source from the content-addressed store, hash-verified

1049
1050/* Expand the hash table if needed */
1051static int _HashTableExpandIfNeeded
1052(
1053 dict *d
1054) {
1055 /* Incremental rehashing already in progress. Return. */
1056 if (dictIsRehashing(d)) return DICT_OK;
1057
1058 /* If the hash table is empty expand it to the initial size. */
1059 if (DICTHT_SIZE(d->ht_size_exp[0]) == 0) return HashTableExpand(d, DICT_HT_INITIAL_SIZE);
1060
1061 /* If we reached the 1:1 ratio, and we are allowed to resize the hash
1062 * table (global setting) or we should avoid it but the ratio between
1063 * elements/buckets is over the "safe" threshold, we resize doubling
1064 * the number of buckets. */
1065 if (!dictTypeExpandAllowed(d))
1066 return DICT_OK;
1067 if ((dict_can_resize == DICT_RESIZE_ENABLE &&
1068 d->ht_used[0] >= DICTHT_SIZE(d->ht_size_exp[0])) ||
1069 (dict_can_resize != DICT_RESIZE_FORBID &&
1070 d->ht_used[0] / DICTHT_SIZE(d->ht_size_exp[0]) > dict_force_resize_ratio))
1071 {
1072 return HashTableExpand(d, d->ht_used[0] + 1);
1073 }
1074 return DICT_OK;
1075}
1076
1077/* TODO: clz optimization */
1078/* Our hash table capability is a power of two */

Callers 1

_dictKeyIndexFunction · 0.85

Calls 2

HashTableExpandFunction · 0.85
dictTypeExpandAllowedFunction · 0.85

Tested by

no test coverage detected