MapRemovePair
Description
Remove and destroy the first matching key/value pair.
Parameters
| Name | Direction | Description |
|---|---|---|
m |
in,out | Map. |
lookup_key |
in | Key to remove. |
lookup_value |
in | Value to remove. Uses value_compare for equality. |
Success
Returns true. The first matching (key, value) entry has been removed; its slot is now a tombstone, and key_copy_deinit / value_copy_deinit (if configured) have been invoked. Map length shrinks by one.
Failure
Returns false when no matching pair exists. The map is not modified. A NULL value_compare is a caller bug and aborts via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Map.c:1228:
if (!map->value_compare) {
LOG_FATAL("MapRemovePair requires a value comparator");
}- In
Deadend.c:165:
static bool test_map_remove_pair_without_value_compare_fails(void) {
WriteFmt("Testing MapRemovePair without value comparator\n");
typedef Map(int, int) IntIntMap;- In
Deadend.c:171:
IntIntMap map = MapInit(i32_hash, i32_compare, &alloc);
MapRemovePair(&map, 1, 10);
MapDeinit(&map);- In
Remove.c:93:
MapInsertR(&map, 5, 52);
bool result = MapRemovePair(&map, 5, 51);
result = result && MapContainsPair(&map, 5, 50);
result = result && !MapContainsPair(&map, 5, 51);- In
Remove.c:119:
// Key present, value absent.
bool result = !MapRemovePair(&map, 5, 999);
// Key absent entirely.
result = result && !MapRemovePair(&map, 6, 50);- In
Remove.c:121:
bool result = !MapRemovePair(&map, 5, 999);
// Key absent entirely.
result = result && !MapRemovePair(&map, 6, 50);
result = result && (MapPairCount(&map) == length_before);- In
Remove.c:352:
// Exercise every removal path against the deep-copy map.
result = result && MapRemoveFirst(&map, "alpha"); // one clone pair freed
result = result && MapRemovePair(&map, "alpha", "two"); // remaining alpha freed
result = result && (MapRemoveAll(&map, "beta") == 1); // beta freed
result = result && !MapContainsKey(&map, "alpha");
Last updated on