MapRemoveIf
Description
Remove and destroy all entries that match a predicate.
Parameters
| Name | Direction | Description |
|---|---|---|
m |
in,out | Map. |
predicate_fn |
in | Callback returning true for entries to remove. |
ctx_ptr |
in,out | Optional user context passed to the predicate. |
Success
Returns the count of removed entries (may be 0). Every entry for which the predicate returned true has been removed, its slot turned into a tombstone, and key_copy_deinit / value_copy_deinit (if configured) invoked. Map length shrinks by the returned count.
Failure
Function cannot fail. A NULL predicate_fn is a caller bug and aborts via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Map.c:1294:
if (!predicate) {
LOG_FATAL("MapRemoveIf requires a predicate");
}- In
Map.Deadend.c:60:
static bool test_map_remove_if_without_predicate_fails(void) {
WriteFmt("Testing MapRemoveIf without predicate\n");
typedef Map(int, int) IntIntMap;- In
Map.Deadend.c:66:
IntIntMap map = MapInit(i32_hash, i32_compare, &alloc);
MapRemoveIf(&map, NULL, NULL);
MapDeinit(&map);- In
Map.Remove.c:77:
MapInsertR(&map, 3, 31);
bool result = (MapRemoveIf(&map, remove_even_values, NULL) == 2);
result = result && !MapContainsKey(&map, 2);
result = result && (MapValueCountForKey(&map, 1) == 1);
Last updated on