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
Map.Deadend.c:46:
static bool test_map_remove_pair_without_value_compare_fails(void) {
WriteFmt("Testing MapRemovePair without value comparator\n");
typedef Map(int, int) IntIntMap;- In
Map.Deadend.c:52:
IntIntMap map = MapInit(i32_hash, i32_compare, &alloc);
MapRemovePair(&map, 1, 10);
MapDeinit(&map);- In
Map.Remove.c:50:
MapInsertR(&map, 5, 52);
bool result = MapRemovePair(&map, 5, 51);
result = result && MapContainsPair(&map, 5, 50);
result = result && !MapContainsPair(&map, 5, 51);
Last updated on