MapRehashWithPolicy
Description
Remap using a specific probing policy.
Parameters
| Name | Direction | Description |
|---|---|---|
m |
in,out | Hash map. |
n |
in | Minimum number of entries expected after rehash. |
Success
Returns true. The map is rebuilt with the new probing policy (copied into the map by value), sized to fit at least n entries plus the current length. Every live entry has been re-hashed under the new policy; tombstones are gone.
Failure
Returns false on allocation failure during the new probe table build. The map and its existing policy are unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Memory.h:161:
#define MapMustRehashWithPolicy(m, n, policy_value) \
do { \
if (!MapRehashWithPolicy((m), (n), (policy_value))) { \
LOG_FATAL("MapMustRehashWithPolicy failed"); \
} \- In
Ops.c:96:
MapSetOnlyR(&map, "yellow", "banana");
MapSetOnlyR(&map, "green", "pear");
MapRehashWithPolicy(&map, MapPairCount(&map), MapPolicyQuadratic);
bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&- In
Init.c:91:
}
MapRehashWithPolicy(&map, MapPairCount(&map), MapPolicyQuadratic);
bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&- In
Insert.c:710:
// installing the policy, and nothing aborts -> deadend FAILS = mutant killed.
static bool test_rehash_rejects_invalid_policy(void) {
WriteFmt("Testing MapRehashWithPolicy validates the new policy up front\n");
typedef Map(int, int) IntIntMap;- In
Insert.c:721:
MapPolicy bad = make_validate_only_reject_policy();
MapRehashWithPolicy(&map, 1, bad); // real: LOG_FATAL on the stuck-probe check
MapDeinit(&map);- In
Insert.c:805:
MapPolicy tight = make_tight_policy();
bool result = MapRehashWithPolicy(&map, 0, tight);
result = result && (MapPairCount(&map) == 3);- In
Insert.c:821:
// [n, length), the real code must reject it (length is required).
static bool test_rehash_rejects_insufficient_with_small_n(void) {
WriteFmt("Testing MapRehashWithPolicy rejects under-sized capacity for n<length\n");
typedef Map(int, int) IntIntMap;- In
Insert.c:831:
MapPolicy sab = make_sabotage_policy();
MapRehashWithPolicy(&map, 2, sab); // must LOG_FATAL "insufficient capacity"
MapDeinit(&map);- In
Insert.c:1039:
MapInsertR(&map, keys[i], keys[i] + 1);
MapRehashWithPolicy(&map, 8, policy);
bool result = (MapPairCount(&map) == 5);- In
Access.c:134:
MapRemoveFirst(&map, 10);
MapRehashWithPolicy(&map, 5, policy);
bool result = ok && (MapValuePtrFromCursor(&map, cursor) == NULL);
Last updated on