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)
- In
Ops.h:22:
/// TAGS: Map, Empty, Query, Ops
///
#define MapEmpty(m) (MapPairCount(m) == 0)
///
- In
Debug.c:158:
// 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);
}- In
Debug.c:469:
// 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) {- In
Debug.c:470:
// 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);- In
Debug.c:508:
if (!self)
return 0;
return (size)MapPairCount(&self->live);
}- In
Debug.c:532:
if (!self || !out)
return;
if (MapPairCount(&self->live) == 0)
return;- In
Debug.c:535:
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);- In
Compare.c:235:
bool result = (got != NULL && *got == 1u);
result = result && (gone == NULL);
result = result && (MapPairCount(&counts) == 2);
FloatDeinit(&k1);- In
Compare.c:1065:
bool result = (got != NULL && *got == 1u);
result = result && (gone == NULL);
result = result && (MapPairCount(&counts) == 2);
BitVecDeinit(&k1);- In
Compare.c:177:
bool result = (got != NULL && *got == 1u);
result = result && (gone == NULL);
result = result && (MapPairCount(&counts) == 2);
IntDeinit(&k1);- In
Ops.c:96:
MapSetOnlyR(&map, "yellow", "banana");
MapSetOnlyR(&map, "green", "pear");
MapRehashWithPolicy(&map, MapPairCount(&map), MapPolicyQuadratic);
bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&- In
Ops.c:138:
result = result && MapContainsPair(&first, 1, 11);
result = result && MapContainsPair(&first, 2, 20);
result = result && (MapPairCount(&first) == 2);
result = result && (MapUniqueKeyCount(&first) == 2);- In
Ops.c:145:
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);- In
Ops.c:148:
result = result && MapContainsPair(&second, 1, 11);
result = result && MapContainsPair(&second, 2, 20);
result = result && (MapPairCount(&second) == 2);
MapDeinit(&first);- In
Ops.c:186:
MapRemoveFirst(&map, 2);
result = result && MapEmpty(&map);
result = result && (MapPairCount(&map) == 0);
// Refill then clear -> empty.
- In
Ops.c:194:
MapClear(&map);
result = result && MapEmpty(&map);
result = result && (MapPairCount(&map) == 0);
MapDeinit(&map);- In
Ops.c:222:
result = result && MapContainsPair(&map, 3, 30);
result = result && !MapContainsKey(&map, 2);
result = result && (MapPairCount(&map) == 2);
result = result && (MapUniqueKeyCount(&map) == 2);- In
Ops.c:245:
bool result = (MapTombstones(&map) == 1);
MapMustRehashWithPolicy(&map, MapPairCount(&map), MapPolicyQuadratic);
// Policy is now quadratic (copied in by value).
- In
Ops.c:259:
result = result && MapContainsPair(&map, 3, 30);
result = result && (MapValueCountForKey(&map, 2) == 2);
result = result && (MapPairCount(&map) == 3);
result = result && (MapUniqueKeyCount(&map) == 2);- In
Ops.c:283:
result = result && MapContainsKey(&map, 3);
result = result && MapContainsKey(&map, 4);
result = result && (MapPairCount(&map) == 2);
MapDeinit(&map);- In
Init.c:71:
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);- In
Init.c:74:
MapSetOnlyR(&map, 7, 70);
result = result && (MapPairCount(&map) == 1) && (MapValueCountForKey(&map, 7) == 1);
result = result && MapGetFirstPtr(&map, 7) && (*MapGetFirstPtr(&map, 7) == 70);- In
Init.c:91:
}
MapRehashWithPolicy(&map, MapPairCount(&map), MapPolicyQuadratic);
bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&- In
Init.c:150:
(MapPolicy(&map).first_index == MapPolicyLinear.first_index) &&
(MapPolicy(&map).next_index == MapPolicyLinear.next_index) &&
(MapPolicy(&map).max_probe_count == MapPolicyLinear.max_probe_count) && (MapPairCount(&map) == 0) &&
(MapCapacity(&map) == 0) && (MapTombstones(&map) == 0) && MapEmpty(&map);- In
Init.c:172:
result = MapReserve(&map, 64);
result = result && (MapCapacity(&map) >= 64);
result = result && (MapPairCount(&map) == 8);
for (i = 0; i < 8; i++) {- In
Init.c:193:
MapMustReserve(&map, 48);
bool result = (MapCapacity(&map) >= 48) && (MapPairCount(&map) == 2);
result = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 10);
result = result && MapGetFirstPtr(&map, 2) && (*MapGetFirstPtr(&map, 2) == 20);- In
Init.c:210:
MapInsertR(&map, 6, 60);
bool result = (MapKeyHash(&map) == i32_hash) && (MapKeyCompare(&map) == i32_compare) && (MapPairCount(&map) == 2);
result = result && MapGetFirstPtr(&map, 5) && (*MapGetFirstPtr(&map, 5) == 50);
result = result && MapGetFirstPtr(&map, 6) && (*MapGetFirstPtr(&map, 6) == 60);- In
Init.c:237:
MapInsertR(&map, "alpha", "first");
result = result && (MapPairCount(&map) == 1);
result = result && MapGetFirstPtr(&map, "alpha") && (ZstrCompare(*MapGetFirstPtr(&map, "alpha"), "first") == 0);- In
Init.c:261:
MapMustInsertR(&map, i, i * 7 + 1);
bool result = (MapPairCount(&map) == N);
for (int i = 0; i < N; i++) {
int *value = MapGetFirstPtr(&map, i);- In
Insert.c:350:
MapSetOnlyR(&map, 3, 30);
bool result = MapPairCount(&map) == 4;
result = result && (MapValueCountForKey(&map, 1) == 2);
result = result && (MapValueCountForKey(&map, 2) == 1);- In
Insert.c:373:
MapSetFirstR(&map, 1, 100);
bool result = (MapPairCount(&map) == 3);
result = result && (MapValueCountForKey(&map, 1) == 3);
result = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 100);- In
Insert.c:397:
// Miss on an empty (capacity 0) map: returns false, nothing inserted.
bool result = !MapSetFirstR(&map, 7, 70);
result = result && (MapPairCount(&map) == 0) && !MapContainsKey(&map, 7);
MapInsertR(&map, 1, 10);- In
Insert.c:405:
result = result && !MapContainsKey(&map, 7);
result = result && (MapValueCountForKey(&map, 7) == 0);
result = result && (MapPairCount(&map) == 1);
// Pre-existing entry is untouched.
result = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 10);- In
Insert.c:436:
result = result && !MapContainsPair(&map, 5, 51);
result = result && !MapContainsPair(&map, 5, 52);
result = result && (MapPairCount(&map) == 1);
MapDeinit(&map);- In
Insert.c:529:
result = result && (miss == 220);
result = result && !MapContainsKey(&map, 99);
result = result && (MapPairCount(&map) == 1);
MapDeinit(&map);- In
Insert.c:551:
MapInsertR(&map, i, i * 10);
}
result = result && (MapPairCount(&map) == 600);
// Phase 2: alternating remove+insert at the same churn point. Each
- In
Insert.c:563:
// Deterministic count: 600 base keys (0..599) survive untouched, plus
// the 64 churned keys (600..663) each ending with exactly one value.
result = result && (MapPairCount(&map) == 664);
MapDeinit(&map);- In
Insert.c:579:
value_ptr = MapEnsurePtr(&map, 8, 80);
result = value_ptr && (*value_ptr == 80);
result = result && (MapPairCount(&map) == 1);
result = result && (MapValueCountForKey(&map, 8) == 1);- In
Insert.c:584:
value_ptr = MapEnsurePtr(&map, 8, 800);
result = result && value_ptr && (*value_ptr == 80);
result = result && (MapPairCount(&map) == 1);
result = result && (MapValueCountForKey(&map, 8) == 1);- In
Insert.c:609:
// Mutation must not have spawned a second entry.
result = result && (MapValueCountForKey(&map, 3) == 1);
result = result && (MapPairCount(&map) == 1);
MapDeinit(&map);- In
Insert.c:737:
bool result = MapCompact(&map); // empty map: must succeed via fast path
result = result && (MapPairCount(&map) == 0);
MapInsertR(&map, 5, 50);
result = result && MapGetFirstPtr(&map, 5) && (*MapGetFirstPtr(&map, 5) == 50);- In
Insert.c:807:
bool result = MapRehashWithPolicy(&map, 0, tight);
result = result && (MapPairCount(&map) == 3);
result = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 10);
result = result && MapGetFirstPtr(&map, 2) && (*MapGetFirstPtr(&map, 2) == 20);- In
Insert.c:853:
fa.fail_now = false;
bool result = failed && (MapPairCount(&map) == 6);
for (int k = 0; k < 6; k++)
result = result && MapGetFirstPtr(&map, k) && (*MapGetFirstPtr(&map, k) == k * 10);- In
Insert.c:876:
MapInsertR(&map, keys[i], keys[i] + 1);
bool result = (MapPairCount(&map) == 6);
result = result && MapCompact(&map);- In
Insert.c:881:
result = result && (MapCapacity(&map) == 16);
result = result && (MapPairCount(&map) == 6);
for (int i = 0; i < 6; i++)
result = result && MapGetFirstPtr(&map, keys[i]) && (*MapGetFirstPtr(&map, keys[i]) == keys[i] + 1);- In
Insert.c:934:
result = result && MapInsertR(&map, k, k * 100 + 1);
result = result && (MapPairCount(&map) == 6);
for (int k = 0; k < 6; k++) {
int *v = MapGetFirstPtr(&map, k);- In
Insert.c:960:
result = result && MapInsertR(&map, 8, 8 * 100 + 3);
result = result && (MapPairCount(&map) == 9);
for (int k = 0; k < 9; k++) {
int *v = MapGetFirstPtr(&map, k);- In
Insert.c:1041:
MapRehashWithPolicy(&map, 8, policy);
bool result = (MapPairCount(&map) == 5);
for (int i = 0; i < 5; i++) {
int *v = MapGetFirstPtr(&map, keys[i]);- In
Insert.c:1162:
result = result && (MapTombstones(&map) == 0);
result = result && (MapPairCount(&map) == 1);
result = result && (MapValueCountForKey(&map, 7) == 1);
result = result && MapGetFirstPtr(&map, 7) && (*MapGetFirstPtr(&map, 7) == 700);- In
Insert.c:1186:
for (int k = 0; k < 8; k++)
MapInsertR(&map, k, k * 100 + 3);
bool result = (MapCapacity(&map) == 8) && (MapPairCount(&map) == 8);
MapInsertR(&map, 8, 803); // probe budget exhausted -> recover with n = cap+1 = 9
- In
Insert.c:1191:
result = result && (MapCapacity(&map) == 16);
result = result && (MapPairCount(&map) == 9);
for (int k = 0; k < 9; k++)
result = result && MapGetFirstPtr(&map, k) && (*MapGetFirstPtr(&map, k) == k * 100 + 3);- In
Type.c:61:
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 &&- In
Remove.c:43:
MapSetOnlyR(&map, 2, 20);
u64 length_before = MapPairCount(&map);
bool result = MapRemoveFirst(&map, 1);- In
Remove.c:49:
result = result && (MapValueCountForKey(&map, 1) == 1);
result = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 11);
result = result && (MapPairCount(&map) == 2);
// Length shrinks by exactly one.
result = result && (MapPairCount(&map) == length_before - 1);- In
Remove.c:51:
result = result && (MapPairCount(&map) == 2);
// Length shrinks by exactly one.
result = result && (MapPairCount(&map) == length_before - 1);
// Unrelated key untouched.
result = result && MapGetFirstPtr(&map, 2) && (*MapGetFirstPtr(&map, 2) == 20);- In
Remove.c:70:
MapInsertR(&map, 2, 20);
u64 length_before = MapPairCount(&map);
u64 tombstones_before = MapTombstones(&map);- In
Remove.c:74:
bool result = !MapRemoveFirst(&map, 99);
result = result && (MapPairCount(&map) == length_before);
result = result && (MapTombstones(&map) == tombstones_before);
result = result && MapContainsKey(&map, 1);- In
Remove.c:115:
MapInsertR(&map, 5, 51);
u64 length_before = MapPairCount(&map);
u64 tombstones_before = MapTombstones(&map);- In
Remove.c:123:
result = result && !MapRemovePair(&map, 6, 50);
result = result && (MapPairCount(&map) == length_before);
result = result && (MapTombstones(&map) == tombstones_before);
result = result && MapContainsPair(&map, 5, 50);- In
Remove.c:170:
MapInsertR(&map, 5, 51);
result = result && (MapTombstones(&map) == 0);
result = result && (MapPairCount(&map) == 1);
int *value = MapGetFirstPtr(&map, 5);
result = result && value && (*value == 51);- In
Remove.c:188:
bool result = (MapRetainIf(&map, always_retain, NULL) == 0);
result = result && (MapPairCount(&map) == 0);
MapDeinit(&map);- In
Remove.c:204:
size removed = MapRemoveIf(&map, always_true_predicate, NULL);
bool result = (removed == 0) && (MapPairCount(&map) == 0);
MapDeinit(&map);- In
Remove.c:226:
result = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 11);
result = result && MapContainsKey(&map, 3);
result = result && (MapPairCount(&map) == 2);
MapDeinit(&map);- In
Remove.c:247:
result = result && (MapValueCountForKey(&map, 5) == 0);
result = result && MapContainsKey(&map, 9);
result = result && (MapPairCount(&map) == 1);
MapDeinit(&map);- In
Remove.c:264:
MapInsertR(&map, 9, 90);
u64 length_before = MapPairCount(&map);
u64 tombstones_before = MapTombstones(&map);- In
Remove.c:268:
bool result = (MapRemoveAll(&map, 77) == 0);
result = result && (MapPairCount(&map) == length_before);
result = result && (MapTombstones(&map) == tombstones_before);
result = result && MapContainsKey(&map, 5);- In
Remove.c:298:
MapSetOnlyR(&map, i, i + 100);
u64 length_before = MapPairCount(&map);
MapRemoveFirst(&map, 5);- In
Remove.c:302:
MapRemoveFirst(&map, 5);
bool result = !MapContainsKey(&map, 5);
result = result && (MapPairCount(&map) == length_before - 1);
MapSetOnlyR(&map, 5, 205);- In
Remove.c:307:
result = result && MapContainsKey(&map, 5);
result = result && MapGetFirstPtr(&map, 5) && (*MapGetFirstPtr(&map, 5) == 205);
result = result && (MapPairCount(&map) == length_before);
// Unrelated keys remain intact.
result = result && MapGetFirstPtr(&map, 4) && (*MapGetFirstPtr(&map, 4) == 104);- In
Remove.c:386:
// Remove two interior keys; the ones before and after must stay reachable.
bool result = MapRemoveFirst(&map, 1) && MapRemoveFirst(&map, 2);
result = result && (MapPairCount(&map) == 2);
result = result && !MapContainsKey(&map, 1) && !MapContainsKey(&map, 2);
result = result && MapGetFirstPtr(&map, 0) && (*MapGetFirstPtr(&map, 0) == 0);- In
Remove.c:393:
// The chain still accepts new keys, and every live key stays retrievable.
result = result && MapInsertR(&map, 5, 55) && MapInsertR(&map, 6, 66);
result = result && (MapPairCount(&map) == 4);
int *v5 = MapGetFirstPtr(&map, 5);
int *v6 = MapGetFirstPtr(&map, 6);- In
Access.c:227:
result = result && (MapValueCountForKey(&map, 7) == 0); // map_value_count early-out
result = result && (MapUniqueKeyCount(&map) == 0);
result = result && (MapPairCount(&map) == 0);
// Cursor APIs on an empty map are invalid / NULL.
- In
Access.c:237:
int got = MapGetOrDefault(&map, 7, 1234);
result = result && (got == 1234);
result = result && (MapPairCount(&map) == 0);
result = result && !MapContainsKey(&map, 7);- In
Access.c:352:
MapInsertR(&map, k, k * 100 + 7);
bool result = (MapPairCount(&map) == 8) && (MapUniqueKeyCount(&map) == 8);
for (int k = 0; k < 8; k++) {
int *v = MapGetFirstPtr(&map, k);- In
Access.c:399:
MapInsertR(&map, k, k * 100 + 7);
bool result = (MapPairCount(&map) == KEY_COUNT) && (MapUniqueKeyCount(&map) == KEY_COUNT);
// Lookup: every inserted key must return ITS OWN value, not a neighbour's.
- In
Access.c:415:
// Count dropped by exactly one; the removed key is gone.
result = result && (MapPairCount(&map) == (KEY_COUNT - 1));
result = result && (MapUniqueKeyCount(&map) == (KEY_COUNT - 1));
result = result && !MapContainsKey(&map, removed) && (MapGetFirstPtr(&map, removed) == NULL);- In
Parse.c:115:
result = result && (StrIterIndex(&si) == StrIterLength(&si));
result = result && (MapPairCount(&cfg) == 2);
result = result && KvConfigGetI64(&cfg, "a", &a) && (a == 1);
result = result && KvConfigGetI64(&cfg, "b", &b) && (b == 2);- In
Parse.c:206:
result = result && (StrIterIndex(&si) == StrIterLength(&si));
result = result && (MapPairCount(&cfg) == 2);
result = result && KvConfigGetI64(&cfg, "a", &a) && (a == 1);
result = result && KvConfigGetI64(&cfg, "b", &b) && (b == 2);- In
Parse.c:253:
result = result && (StrIterIndex(&si) == StrIterLength(&si));
result = result && (MapPairCount(&cfg) == 1);
v = KvConfigGetPtr(&cfg, "k");
result = result && v && (StrCmp(v, "v") == 0);- In
Parse.c:278:
result = result && (StrIterIndex(&si) == StrIterLength(&si));
result = result && (MapPairCount(&cfg) == 1);
v = KvConfigGetPtr(&cfg, "k");
result = result && v && (StrCmp(v, "v") == 0);- In
Parse.c:300:
result = result && (StrIterIndex(&si) == StrIterLength(&si));
result = result && (MapPairCount(&cfg) == 1);
result = result && KvConfigContains(&cfg, "k");- In
Parse.c:326:
result = result && (StrIterIndex(&si) == StrIterLength(&si));
result = result && (MapPairCount(&cfg) == 3);
result = result && KvConfigContains(&cfg, "host");
result = result && host && StrCmp(host, "localhost") == 0;- In
Parse.c:360:
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;- In
Parse.c:613:
result = result && (StrIterIndex(&si) == StrIterLength(&si));
result = result && (MapPairCount(&cfg) == 3);
// The CR must not survive in the parsed value.
result = result && host && (StrCmp(host, "localhost") == 0);
Last updated on