.TH "corm_iteration" 3 "corm" \" -*- nroff -*- .ad l .nh .SH NAME corm_iteration \- Corm iteration .PP \- Iteration through map contents\&. .SH SYNOPSIS .br .PP .SS "Functions" .in +1c .ti -1c .RI "uint32_t \fBcorm_iter\fP (uint32_t hd, const void *const key, uint32_t flags)" .br .RI "Start iteration\&. " .ti -1c .RI "int \fBcorm_next\fP (const void **key, const void **value, uint32_t cur_id)" .br .RI "Fetch next key/value\&. " .ti -1c .RI "int \fBcorm_next_copy\fP (void *key, void *value, uint32_t cur_id)" .br .RI "Fetch next key/value, copied into caller buffers\&. " .ti -1c .RI "void \fBcorm_fin\fP (uint32_t cur_id)" .br .RI "End iteration early\&. " .ti -1c .RI "uint32_t \fBcorm_get_multi\fP (uint32_t hd, const void *key)" .br .RI "Start iteration over all values for a key\&. " .ti -1c .RI "uint32_t \fBcorm_count\fP (uint32_t hd, const void *key)" .br .RI "Count entries matching a key\&. " .in -1c .SH "Detailed Description" .PP Iteration through map contents\&. .PP \fBSee also\fP .RS 4 \fBCorm open, close and save\fP .PP \fBCorm get, put, del and drop\fP .PP \fBcorm_assoc\fP .PP \fBCorm type customization\fP .RE .PP .PP .nf // 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); .fi .PP .SH "Function Documentation" .PP .SS "uint32_t corm_count (uint32_t hd, const void * key)" .PP Count entries matching a key\&. .PP \fBParameters\fP .RS 4 \fIhd\fP Map handle\&. .br \fIkey\fP Key to count\&. NULL counts total entries in map\&. .RE .PP \fBReturns\fP .RS 4 Number of matching entries\&. .RE .PP \fBNote\fP .RS 4 For CM_MULTIVALUE maps, returns count of all duplicate values .PP For normal maps, returns 0 or 1 .RE .PP .SS "void corm_fin (uint32_t cur_id)" .PP End iteration early\&. .PP \fBParameters\fP .RS 4 \fIcur_id\fP Cursor handle\&. .RE .PP .SS "uint32_t corm_get_multi (uint32_t hd, const void * key)" .PP 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\&. .PP \fBParameters\fP .RS 4 \fIhd\fP Map handle\&. .br \fIkey\fP Key to look up\&. .RE .PP \fBReturns\fP .RS 4 Cursor handle for use with \fBcorm_next()\fP, or CM_MISS if key not found\&. .RE .PP Example: .PP .nf 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); } .fi .PP .PP \fBNote\fP .RS 4 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\&. .PP For single-value lookups, \fBcorm_get()\fP is more efficient .RE .PP \fBSee also\fP .RS 4 \fBcorm_del_all\fP for deleting all duplicates at once .PP \fBcorm_count\fP for counting entries without iteration .RE .PP .SS "uint32_t corm_iter (uint32_t hd, const void *const key, uint32_t flags)" .PP Start iteration\&. Creates a cursor for iterating over map entries\&. Ordered ranges require CM_SORTED flag on the map\&. .PP \fBParameters\fP .RS 4 \fIhd\fP Map handle\&. .br \fIkey\fP Starting key or NULL for all entries\&. .br \fIflags\fP Iterator flags (CM_RANGE valid)\&. .IP "\(bu" 2 CM_RANGE with CM_SORTED: ordered scan .IP "\(bu" 2 CM_RANGE without CM_SORTED: linear scan .IP "\(bu" 2 No flags: iterate single key (or all if key is NULL) .PP .RE .PP \fBReturns\fP .RS 4 Cursor handle for use with corm_next\&. .RE .PP .SS "int corm_next (const void ** key, const void ** value, uint32_t cur_id)" .PP Fetch next key/value\&. .PP \fBParameters\fP .RS 4 \fIkey\fP Pointer to key\&. .br \fIvalue\fP Pointer to value\&. .br \fIcur_id\fP Cursor handle\&. .RE .PP \fBReturns\fP .RS 4 1 if valid, 0 if done\&. See corm_common for pointer ownership rules\&. .RE .PP .SS "int corm_next_copy (void * key, void * value, uint32_t cur_id)" .PP Fetch next key/value, copied into caller buffers\&. As \fBcorm_next()\fP, 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 \fBcorm_len()\fP, so measured types (CM_STR) are copied in full; \fBcorm_type_len()\fP would return 0 for those and copy nothing\&. .PP Each destination must be at least \fBcorm_len()\fP bytes for the side it receives; the size is not returned and no truncation is performed\&. NULL skips that side\&. .PP As with \fBcorm_next()\fP, the cursor is released by corm at end-of-iteration, and a \fBcorm_fin()\fP after the loop that returned 0 is a no-op\&. .PP \fBParameters\fP .RS 4 \fIkey\fP Destination for the key, or NULL to skip it\&. .br \fIvalue\fP Destination for the value, or NULL to skip it\&. .br \fIcur_id\fP Cursor handle from \fBcorm_iter()\fP or \fBcorm_get_multi()\fP\&. .RE .PP \fBReturns\fP .RS 4 1 if valid, 0 if done\&. .RE .PP \fBSee also\fP .RS 4 \fBcorm_next\fP, \fBcorm_iter\fP, \fBcorm_get_multi\fP, \fBcorm_len\fP .RE .PP .SH "Author" .PP Generated automatically by Doxygen for corm from the source code\&.