Skip to content
MapGetFirstPtr

MapGetFirstPtr

Description

Get pointer to the first value stored for a key.

Parameters

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

Success

Returns a pointer of type MAP_VALUE_TYPE(m) * to the value slot of the first matching entry. The map is not modified. The pointer is valid until the next rehash.

Failure

Returns NULL when no entry exists for the key. The map is not modified.

Usage example (Cross-references)

Usage examples (Cross-references)
            return 0;
    
        DebugRecord *live_rec = MapGetFirstPtr(&self->live, ptr);
    
        if (!live_rec) {
        // the copy. If ptr is not in the live map, forward to deallocate
        // which emits the double-free / foreign-ptr diagnostic and aborts.
        DebugRecord *rec = MapGetFirstPtr(&self->live, ptr);
        if (!rec) {
            debug_allocator_deallocate(self, ptr); // aborts
            return NULL;
        }
        return MapGetFirstPtr(cfg, *key);
    }
        result      = result && (MapValueCountForKey(&map, 2) == 1);
        result      = result && (MapValueCountForKey(&map, 3) == 1);
        result      = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 10);
        result      = result && MapGetFirstPtr(&map, 2) && (*MapGetFirstPtr(&map, 2) == 200);
        result      = result && MapGetFirstPtr(&map, 3) && (*MapGetFirstPtr(&map, 3) == 30);
        result      = result && (MapValueCountForKey(&map, 3) == 1);
        result      = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 10);
        result      = result && MapGetFirstPtr(&map, 2) && (*MapGetFirstPtr(&map, 2) == 200);
        result      = result && MapGetFirstPtr(&map, 3) && (*MapGetFirstPtr(&map, 3) == 30);
        result      = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 10);
        result      = result && MapGetFirstPtr(&map, 2) && (*MapGetFirstPtr(&map, 2) == 200);
        result      = result && MapGetFirstPtr(&map, 3) && (*MapGetFirstPtr(&map, 3) == 30);
    
        MapDeinit(&map);
        bool result = (MapPairCount(&map) == 3);
        result      = result && (MapValueCountForKey(&map, 1) == 3);
        result      = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 100);
        result      = result && MapContainsPair(&map, 1, 11);
        result      = result && MapContainsPair(&map, 1, 12);
        bool result = (key == 0) && (value == 0);
        result      = result && (MapValueCountForKey(&map, 42) == 1);
        result      = result && MapGetFirstPtr(&map, 42) && (*MapGetFirstPtr(&map, 42) == 84);
    
        MapDeinit(&map);
    
        Float probe   = FloatFromStr("314e-2", &alloc.base); // same value as k1
        u64  *got     = MapGetFirstPtr(&counts, probe);
        Float missing = FloatFromStr("9.99", &alloc.base);
        u64  *gone    = MapGetFirstPtr(&counts, missing);
        u64  *got     = MapGetFirstPtr(&counts, probe);
        Float missing = FloatFromStr("9.99", &alloc.base);
        u64  *gone    = MapGetFirstPtr(&counts, missing);
    
        bool result = (got != NULL && *got == 1u);
        // to DebugAllocator with no public accessor; reach in to confirm the
        // alloc-trace was captured.
        DebugRecord *rec = MapGetFirstPtr(&dbg.live, p);
        ok               = ok && (rec != NULL) && (rec->alloc_trace_n > 0);
        result      = result && MapContainsKey(&map, 1);
        result      = result && (MapValueCountForKey(&map, 1) == 1);
        result      = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 11);
        result      = result && (MapPairCount(&map) == 2);
        result      = result && !MapContainsKey(&map, 2);
        result      = result && (MapValueCountForKey(&map, 1) == 1);
        result      = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 11);
        result      = result && MapContainsKey(&map, 3);
        result      = result && (MapPairCount(&map) == 2);
        bool result = !MapContainsKey(&map, 5);
        result      = result && MapContainsKey(&map, 105);
        result      = result && MapGetFirstPtr(&map, 105) && (*MapGetFirstPtr(&map, 105) == 205);
    
        MapDeinit(&map);
    
        Int  probe   = IntFrom(100u, &alloc.base);
        u64 *got     = MapGetFirstPtr(&counts, probe);
        Int  missing = IntFrom(999u, &alloc.base);
        u64 *gone    = MapGetFirstPtr(&counts, missing);
        u64 *got     = MapGetFirstPtr(&counts, probe);
        Int  missing = IntFrom(999u, &alloc.base);
        u64 *gone    = MapGetFirstPtr(&counts, missing);
    
        bool result = (got != NULL && *got == 1u);
        MapInsertR(&map, 11, 111);
    
        int *value  = MapGetFirstPtr(&map, 11);
        bool result = value && (*value == 110);
        result      = result && (MapGetFirstPtr(&map, 999) == NULL);
        int *value  = MapGetFirstPtr(&map, 11);
        bool result = value && (*value == 110);
        result      = result && (MapGetFirstPtr(&map, 999) == NULL);
    
        MapDeinit(&map);
        MapInsertR(&map, 11, 111);
    
        int *value  = MapGetFirstPtr(&map, 11);
        bool result = value && (*value == 110);
        result      = result && (MapGetFirstPtr(&map, 999) == NULL);
        int *value  = MapGetFirstPtr(&map, 11);
        bool result = value && (*value == 110);
        result      = result && (MapGetFirstPtr(&map, 999) == NULL);
    
        MapDeinit(&map);
        bool result = (MapValuePtrFromCursor(&map, cursor) == NULL);
        result      = result && (MapValueCountForKey(&map, 5) == 1);
        result      = result && MapGetFirstPtr(&map, 5) && (*MapGetFirstPtr(&map, 5) == 51);
    
        MapDeinit(&map);
        MapSetOnlyR(&map, 7, 70);
        result = result && (MapPairCount(&map) == 1) && (MapValueCountForKey(&map, 7) == 1);
        result = result && MapGetFirstPtr(&map, 7) && (*MapGetFirstPtr(&map, 7) == 70);
    
        MapDeinit(&map);
    
        for (int i = 0; i < 24; i++) {
            int *value = MapGetFirstPtr(&map, i);
            result     = result && value && (*value == i * 10);
        }
    
        for (int i = 0; i < 6; i++) {
            int *value = MapGetFirstPtr(&map, i);
            result     = result && value && (*value == (i + 100));
        }
    
    static bool city_reachable(CityGraph *graph, CityIndex *index, const Str *from, const Str *to) {
        GraphNodeId *from_id = MapGetFirstPtr(index, *from);
        GraphNodeId *to_id   = MapGetFirstPtr(index, *to);
    static bool city_reachable(CityGraph *graph, CityIndex *index, const Str *from, const Str *to) {
        GraphNodeId *from_id = MapGetFirstPtr(index, *from);
        GraphNodeId *to_id   = MapGetFirstPtr(index, *to);
    
        if (!from_id || !to_id) {
        }
    
        bool result = *MapGetFirstPtr(&counts, a) == 0;
        result      = result && *MapGetFirstPtr(&counts, b) == 1;
        result      = result && *MapGetFirstPtr(&counts, c) == 1;
    
        bool result = *MapGetFirstPtr(&counts, a) == 0;
        result      = result && *MapGetFirstPtr(&counts, b) == 1;
        result      = result && *MapGetFirstPtr(&counts, c) == 1;
        result      = result && *MapGetFirstPtr(&counts, d) == 2;
        bool result = *MapGetFirstPtr(&counts, a) == 0;
        result      = result && *MapGetFirstPtr(&counts, b) == 1;
        result      = result && *MapGetFirstPtr(&counts, c) == 1;
        result      = result && *MapGetFirstPtr(&counts, d) == 2;
        result      = result && *MapGetFirstPtr(&counts, b) == 1;
        result      = result && *MapGetFirstPtr(&counts, c) == 1;
        result      = result && *MapGetFirstPtr(&counts, d) == 2;
    
        MapDeinit(&counts);
        BitVecPush(&probe, true);
    
        u64 *got = MapGetFirstPtr(&counts, probe);
    
        BitVec missing = BitVecInit(base);
        BitVecPush(&missing, true);
        BitVecPush(&missing, true);
        u64 *gone = MapGetFirstPtr(&counts, missing);
    
        bool result = (got != NULL && *got == 1u);
        result       = result && !MapContainsKey(&map, key);
        result       = result && (MapValueCountForKey(&map, "alpha") == 2);
        stored_value = MapGetFirstPtr(&map, "alpha");
        result       = result && stored_value && (*stored_value != value) && (ZstrCompare(*stored_value, "first") == 0);
        MapForeachValueForKey(&map, "alpha", entry_value) {
                      (MapPolicy(&map).should_rehash == MapPolicyQuadratic.should_rehash);
        result = result && (MapValueCountForKey(&map, "red") == 2);
        result = result && MapGetFirstPtr(&map, "red") && (ZstrCompare(*MapGetFirstPtr(&map, "red"), "apple") == 0);
        result = result && MapGetFirstPtr(&map, "yellow") && (ZstrCompare(*MapGetFirstPtr(&map, "yellow"), "banana") == 0);
        result = result && MapGetFirstPtr(&map, "green") && (ZstrCompare(*MapGetFirstPtr(&map, "green"), "pear") == 0);
        result = result && (MapValueCountForKey(&map, "red") == 2);
        result = result && MapGetFirstPtr(&map, "red") && (ZstrCompare(*MapGetFirstPtr(&map, "red"), "apple") == 0);
        result = result && MapGetFirstPtr(&map, "yellow") && (ZstrCompare(*MapGetFirstPtr(&map, "yellow"), "banana") == 0);
        result = result && MapGetFirstPtr(&map, "green") && (ZstrCompare(*MapGetFirstPtr(&map, "green"), "pear") == 0);
        MapForeachValueForKey(&map, "red", red_value) {
        result = result && MapGetFirstPtr(&map, "red") && (ZstrCompare(*MapGetFirstPtr(&map, "red"), "apple") == 0);
        result = result && MapGetFirstPtr(&map, "yellow") && (ZstrCompare(*MapGetFirstPtr(&map, "yellow"), "banana") == 0);
        result = result && MapGetFirstPtr(&map, "green") && (ZstrCompare(*MapGetFirstPtr(&map, "green"), "pear") == 0);
        MapForeachValueForKey(&map, "red", red_value) {
            if ((ZstrCompare(red_value, "apple") == 0) || (ZstrCompare(red_value, "cherry") == 0)) {
Last updated on