NAME
corm_iteration - Corm iteration
- Iteration through map contents.
SYNOPSIS
Functions
Start iteration.
Fetch next key/value.
Fetch next key/value, copied into caller buffers.
End iteration early.
Start iteration over all values for a key.
Count entries matching a key.
Detailed Description
Iteration through map contents.
See also
Corm open, close and save
Corm get, put, del and drop
corm_assoc
Corm type customization
// Sorted range scan (requires CM_SORTED in corm_open).
uint32_t hd = corm_open(NULL, NULL, CM_U32, CM_U32,
0xFF, CM_SORTED);
uint32_t start = 100;
uint32_t cur = corm_iter(hd, &start, CM_RANGE);
const void *key, *value;
while (corm_next(&key, &value, cur)) {
// handle key/value
}
corm_fin(cur);
Function Documentation
uint32_t corm_count (uint32_t hd, const void * key)
Count entries matching a key.
Parameters
hd Map handle.
key Key to count. NULL counts total entries in map.
Returns
Number of matching entries.
Note
For CM_MULTIVALUE maps, returns count of all duplicate values
For normal maps, returns 0 or 1
void corm_fin (uint32_t cur_id)
End iteration early.
Parameters
cur_id Cursor handle.
uint32_t corm_get_multi (uint32_t hd, const void * key)
Start iteration over all values for a key. For maps with CM_MULTIVALUE flag, this returns a cursor that iterates over ALL values associated with the given key in insertion order (the order the duplicates were put). For maps without CM_MULTIVALUE, this behaves like a single-value iterator.
Parameters
hd Map handle.
key Key to look up.
Returns
Cursor handle for use with corm_next(), or CM_MISS if key not found.
Example:
uint32_t cur = corm_get_multi(hd, &key);
if (cur != CM_MISS) {
const void *k, *v;
while (corm_next(&k, &v, cur)) {
// Process each value for this key
}
corm_fin(cur);
}
Note
Internally, this walks the key's duplicate chain (O(k)) โ it does NOT trigger the sorted-index rebuild, so it is cheap even on a dirty map and on maps that are never queried via sorted iteration.
For single-value lookups, corm_get() is more efficient
See also
corm_del_all for deleting all duplicates at once
corm_count for counting entries without iteration
uint32_t corm_iter (uint32_t hd, const void *const key, uint32_t flags)
Start iteration. Creates a cursor for iterating over map entries. Ordered ranges require CM_SORTED flag on the map.
Parameters
hd Map handle.
key Starting key or NULL for all entries.
flags Iterator flags (CM_RANGE valid).
- CM_RANGE with CM_SORTED: ordered scan
- CM_RANGE without CM_SORTED: linear scan
- No flags: iterate single key (or all if key is NULL)
Returns
Cursor handle for use with corm_next.
int corm_next (const void ** key, const void ** value, uint32_t cur_id)
Fetch next key/value.
Parameters
key Pointer to key.
value Pointer to value.
cur_id Cursor handle.
Returns
1 if valid, 0 if done. See corm_common for pointer ownership rules.
int corm_next_copy (void * key, void * value, uint32_t cur_id)
Fetch next key/value, copied into caller buffers. As corm_next(), except the key and the value are memcpy'd out using the cursor's own map's type lengths, so a call site needs no casts and no const void * temporaries. Lengths come from corm_len(), so measured types (CM_STR) are copied in full; corm_type_len() would return 0 for those and copy nothing.
Each destination must be at least corm_len() bytes for the side it receives; the size is not returned and no truncation is performed. NULL skips that side.
As with corm_next(), the cursor is released by corm at end-of-iteration, and a corm_fin() after the loop that returned 0 is a no-op.
Parameters
key Destination for the key, or NULL to skip it.
value Destination for the value, or NULL to skip it.
cur_id Cursor handle from corm_iter() or corm_get_multi().
Returns
1 if valid, 0 if done.
See also
corm_next, corm_iter, corm_get_multi, corm_len
Author
Generated automatically by Doxygen for corm from the source code.