Skip to content

MapRemoveAll

Description

Remove all entries matching a key.

Parameters

Name Direction Description
m in,out Map.
lookup_key in Key to delete.

Success

Returns the count of removed entries (> 0). Every matching slot is now a tombstone; key_copy_deinit / value_copy_deinit (if configured) have been invoked on each removed entry. Map length shrinks by the returned count.

Failure

Returns 0 when no entry matches. The map is not modified.

Usage example (Cross-references)

Usage examples (Cross-references)
        for (int i = 0; i < 4000; ++i) {
            int key = 600 + (i & 0x3f); // small cycling window
            MapRemoveAll(&map, key);
            MapInsertR(&map, key, i);
        }
        for (int k = 0; k < 5; k++)
            MapInsertR(&map, k, k);
        MapRemoveAll(&map, 1);
        MapRemoveAll(&map, 3);
        bool result = (MapTombstones(&map) == 2);
            MapInsertR(&map, k, k);
        MapRemoveAll(&map, 1);
        MapRemoveAll(&map, 3);
        bool result = (MapTombstones(&map) == 2);
        MapInsertR(&map, 9, 90);
    
        bool result = (MapRemoveAll(&map, 5) == 3);
        result      = result && !MapContainsKey(&map, 5);
        result      = result && (MapValueCountForKey(&map, 5) == 0);
        u64 tombstones_before = MapTombstones(&map);
    
        bool result = (MapRemoveAll(&map, 77) == 0);
        result      = result && (MapPairCount(&map) == length_before);
        result      = result && (MapTombstones(&map) == tombstones_before);
        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");
        result = result && !MapContainsKey(&map, "beta");
Last updated on