Skip to content
MapFindFirstForKey

MapFindFirstForKey

Description

Find the first value stored for a key as a cursor.

Parameters

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

Success

Returns a MapValueCursor positioned at the first entry that matches the key. MapValuePtrFromCursor resolves it to a value pointer. The map is not modified.

Failure

Returns MapValueCursorInvalid() when no entry exists for the key. The map is not modified.

Usage example (Cross-references)

Usage examples (Cross-references)
            MapInsertR(&map, k, k);
    
        MapValueCursor cursor = MapFindFirstForKey(&map, 15);
        bool           ok     = MapValueCursorIsValid(cursor);
    
        // Cursor APIs on an empty map are invalid / NULL.
        MapValueCursor cursor = MapFindFirstForKey(&map, 7);
        result                = result && !MapValueCursorIsValid(cursor);
        result                = result && (MapValuePtrFromCursor(&map, cursor) == NULL);
        MapInsertR(&map, 9, 90);
    
        cursor = MapFindFirstForKey(&map, 4);
        while (MapValueCursorIsValid(cursor)) {
            int *value_ptr = MapValuePtrFromCursor(&map, cursor);
    
        bool result = (seen == 3) && (value_sum == (40 + 41 + 42));
        result      = result && !MapValueCursorIsValid(MapFindFirstForKey(&map, 99));
        result      = result && (MapValuePtrFromCursor(&map, MapValueCursorInvalid()) == NULL);
        // Single-valued key: first is valid, next past the end stays invalid,
        // and advancing an already-invalid cursor remains invalid.
        MapValueCursor single = MapFindFirstForKey(&map, 9);
        result                = result && MapValueCursorIsValid(single);
        MapValueCursor past   = MapFindNextForKey(&map, 9, single);
        MapInsertR(&map, 5, 51);
    
        cursor = MapFindFirstForKey(&map, 5);
        if (!MapValueCursorIsValid(cursor)) {
            MapDeinit(&map);
Last updated on