MapCompact
Description
Rebuild the map using the current policy and current pair count. This removes tombstones and re-packs the probe table.
Parameters
| Name | Direction | Description |
|---|---|---|
m |
in,out | Map. |
Success
Returns true. Tombstones have been removed and every live entry has been re-hashed into a fresh probe table sized for the current length. Map length is preserved; probe distances may decrease.
Failure
Returns false on allocation failure for the new probe table. The map and existing entries are unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Memory.h:117:
#define MapMustCompact(m) \
do { \
if (!MapCompact((m))) { \
LOG_FATAL("MapMustCompact failed"); \
} \- In
Ops.c:133:
bool result = (MapTombstones(&first) == 1);
MapCompact(&first);
result = result && (MapTombstones(&first) == 0);- In
Insert.c:735:
IntIntMap map = MapInit(i32_hash, i32_compare, &alloc);
bool result = MapCompact(&map); // empty map: must succeed via fast path
result = result && (MapPairCount(&map) == 0);- In
Insert.c:753:
IntIntMap map = MapInit(i32_hash, i32_compare, &alloc);
bool result = MapCompact(&map);
MapInsertR(&map, 7, 70);
result = result && MapGetFirstPtr(&map, 7) && (*MapGetFirstPtr(&map, 7) == 70);- In
Insert.c:767:
IntIntMap map = MapInit(i32_hash, i32_compare, &alloc);
bool result = MapCompact(&map);
MapInsertR(&map, 8, 80);
MapInsertR(&map, 9, 90);- In
Insert.c:783:
IntIntMap map = MapInit(i32_hash, i32_compare, &alloc);
bool result = MapCompact(&map);
MapInsertR(&map, 11, 110);
result = result && MapGetFirstPtr(&map, 11) && (*MapGetFirstPtr(&map, 11) == 110);- In
Insert.c:850:
fa.fail_now = true; // force the new-table allocation to fail
bool failed = !MapCompact(&map); // must return false
fa.fail_now = false;- In
Insert.c:878:
bool result = (MapPairCount(&map) == 6);
result = result && MapCompact(&map);
result = result && (MapCapacity(&map) == 16);
Last updated on