Skip to content

MapPairCount

Description

Number of stored key/value pairs in the multimap.

Parameters

Name Direction Description
m in Map.

Usage example (Cross-references)

Usage examples (Cross-references)
        // bytes_in_use is non-zero; conversely zero live entries means
        // every byte has been returned.
        if (MapPairCount(&self->live) == 0 && self->bytes_in_use != 0) {
            LOG_FATAL("DebugAllocator: bytes_in_use {} with no live records", (u64)self->bytes_in_use);
        }
    
        // Report leaks for anything still in `live`.
        if (MapAllocator(&self->live) && MapPairCount(&self->live) > 0) {
            LOG_ERROR("DebugAllocator: {} live allocation(s) at deinit time:", (u64)MapPairCount(&self->live));
            MapForeachPairPtr(&self->live, key_ptr, val_ptr) {
        // Report leaks for anything still in `live`.
        if (MapAllocator(&self->live) && MapPairCount(&self->live) > 0) {
            LOG_ERROR("DebugAllocator: {} live allocation(s) at deinit time:", (u64)MapPairCount(&self->live));
            MapForeachPairPtr(&self->live, key_ptr, val_ptr) {
                LOG_ERROR("  leaked {x} ({} bytes)", (u64)*key_ptr, (u64)val_ptr->requested_size);
        if (!self)
            return 0;
        return (size)MapPairCount(&self->live);
    }
        if (!self || !out)
            return;
        if (MapPairCount(&self->live) == 0)
            return;
            return;
    
        StrAppendFmt(out, "DebugAllocator: {} live allocation(s):\n", (u64)MapPairCount(&self->live));
        MapForeachPairPtr(&self->live, key_ptr, val_ptr) {
            StrAppendFmt(out, "  leak: {x} ({} bytes)\n", (u64)*key_ptr, (u64)val_ptr->requested_size);
    
        result = result && (StrIterIndex(&si) == StrIterLength(&si));
        result = result && (MapPairCount(&cfg) == 3);
        result = result && KvConfigContains(&cfg, "host");
        result = result && host && StrCmp(host, "localhost") == 0;
    
        result = result && (StrIterIndex(&si) == StrIterLength(&si));
        result = result && (MapPairCount(&cfg) == 4);
        result = result && path && StrCmp(path, "/srv/my app") == 0;
        result = result && user && StrCmp(user, "root") == 0;
        MapSetOnlyR(&map, 3, 30);
    
        bool result = MapPairCount(&map) == 4;
        result      = result && (MapValueCountForKey(&map, 1) == 2);
        result      = result && (MapValueCountForKey(&map, 2) == 1);
        MapSetFirstR(&map, 1, 100);
    
        bool result = (MapPairCount(&map) == 3);
        result      = result && (MapValueCountForKey(&map, 1) == 3);
        result      = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 100);
            MapInsertR(&map, i, i * 10);
        }
        result = result && (MapPairCount(&map) == 600);
    
        // Phase 2: alternating remove+insert at the same churn point. Each
            MapInsertR(&map, key, i);
        }
        result = result && (MapPairCount(&map) >= 600);
    
        MapDeinit(&map);
        value_ptr = MapEnsurePtr(&map, 8, 80);
        result    = value_ptr && (*value_ptr == 80);
        result    = result && (MapPairCount(&map) == 1);
        result    = result && (MapValueCountForKey(&map, 8) == 1);
        value_ptr = MapEnsurePtr(&map, 8, 800);
        result    = result && value_ptr && (*value_ptr == 80);
        result    = result && (MapPairCount(&map) == 1);
        result    = result && (MapValueCountForKey(&map, 8) == 1);
        bool result = (got != NULL && *got == 1u);
        result      = result && (gone == NULL);
        result      = result && (MapPairCount(&counts) == 2);
    
        FloatDeinit(&k1);
        result      = result && (MapValueCountForKey(&map, 1) == 1);
        result      = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 11);
        result      = result && (MapPairCount(&map) == 2);
    
        MapDeinit(&map);
        result      = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 11);
        result      = result && MapContainsKey(&map, 3);
        result      = result && (MapPairCount(&map) == 2);
    
        MapDeinit(&map);
        result      = result && (MapValueCountForKey(&map, 5) == 0);
        result      = result && MapContainsKey(&map, 9);
        result      = result && (MapPairCount(&map) == 1);
    
        MapDeinit(&map);
        bool result = (got != NULL && *got == 1u);
        result      = result && (gone == NULL);
        result      = result && (MapPairCount(&counts) == 2);
    
        IntDeinit(&k1);
    
        bool result = (reserved_capacity >= 32) && (MapCapacity(&map) == reserved_capacity) && (MapTombstones(&map) == 0) &&
                      (MapPairCount(&map) == 0) && MapEmpty(&map) && !MapContainsKey(&map, 1) && !MapContainsKey(&map, 2);
    
        MapSetOnlyR(&map, 7, 70);
    
        MapSetOnlyR(&map, 7, 70);
        result = result && (MapPairCount(&map) == 1) && (MapValueCountForKey(&map, 7) == 1);
        result = result && MapGetFirstPtr(&map, 7) && (*MapGetFirstPtr(&map, 7) == 70);
        }
    
        MapRehashWithPolicy(&map, MapPairCount(&map), MapPolicyQuadratic);
    
        bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&
        bool result = (got != NULL && *got == 1u);
        result      = result && (gone == NULL);
        result      = result && (MapPairCount(&counts) == 2);
    
        BitVecDeinit(&k1);
        MapSetOnlyR(&map, "yellow", "banana");
        MapSetOnlyR(&map, "green", "pear");
        MapRehashWithPolicy(&map, MapPairCount(&map), MapPolicyQuadratic);
    
        bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&
        result = result && MapContainsPair(&first, 1, 11);
        result = result && MapContainsPair(&first, 2, 20);
        result = result && (MapPairCount(&first) == 2);
        result = result && (MapUniqueKeyCount(&first) == 2);
        result = result && MapContainsPair(&first, 9, 90);
        result = result && MapContainsPair(&first, 10, 100);
        result = result && (MapPairCount(&first) == 2);
        result = result && MapContainsPair(&second, 1, 11);
        result = result && MapContainsPair(&second, 2, 20);
        result = result && MapContainsPair(&second, 1, 11);
        result = result && MapContainsPair(&second, 2, 20);
        result = result && (MapPairCount(&second) == 2);
    
        MapDeinit(&first);
        result      = result && MapContainsKey(&map, 3);
        result      = result && MapContainsKey(&map, 4);
        result      = result && (MapPairCount(&map) == 2);
    
        MapDeinit(&map);
        IntIntMap        map   = MapInit(i32_hash, i32_compare, &alloc);
    
        bool result = MapPairCount(&map) == 0 && MapCapacity(&map) == 0 && MapTombstones(&map) == 0 &&
                      MapEntries(&map) == NULL && MapStates(&map) == NULL && MapKeyCompare(&map) == i32_compare &&
                      MapValueCompare(&map) == NULL && MapKeyHash(&map) == i32_hash &&
    /// TAGS: Map, Empty, Query, Ops
    ///
    #define MapEmpty(m) (MapPairCount(m) == 0)
    
    ///
Last updated on