.TH "corm_assoc" 3 "corm" \" -*- nroff -*- .ad l .nh .SH NAME corm_assoc \- Corm associations .PP \- Linking of primary and secondary maps\&. .SH SYNOPSIS .br .PP .SS "Typedefs" .in +1c .ti -1c .RI "typedef void \fBcorm_assoc_t\fP(const void **skey, const void *const pkey, const void *const value, void *userdata)" .br .RI "Association callback type\&. " .ti -1c .RI "typedef size_t \fBcorm_assoc_multi_t\fP(const void **skeys, size_t max_skeys, const void *pkey, const void *value, void *userdata)" .br .RI "Multi-key association callback type\&. " .in -1c .SS "Functions" .in +1c .ti -1c .RI "void \fBcorm_assoc\fP (uint32_t hd, uint32_t link, \fBcorm_assoc_t\fP cb, void *userdata)" .br .RI "Make an association between tables\&. " .ti -1c .RI "void \fBcorm_assoc_multi\fP (uint32_t hd, uint32_t link, \fBcorm_assoc_multi_t\fP cb, void *userdata)" .br .RI "Make a multi-key association between tables\&. " .in -1c .SH "Detailed Description" .PP Linking of primary and secondary maps\&. .PP \fBSee also\fP .RS 4 \fBCorm open, close and save\fP .PP \fBCorm get, put, del and drop\fP .PP \fBCorm iteration\fP .PP \fBCorm type customization\fP .RE .PP .SH "Typedef Documentation" .PP .SS "typedef size_t corm_assoc_multi_t(const void **skeys, size_t max_skeys, const void *pkey, const void *value, void *userdata)" .PP Multi-key association callback type\&. Produces multiple secondary keys from a single primary entry\&. Used by corm_assoc_multi for fields that reference multiple values (e\&.g\&., multi-reference dataset fields)\&. .PP Callback fills skeys[0\&.\&.returned_count-1] with key pointers\&. Each key is copied by corm internally; callback-owned temporary copies must remain valid until the callback returns\&. .PP \fBParameters\fP .RS 4 \fIskeys\fP Array to fill with secondary key pointers\&. .br \fImax_skeys\fP Capacity of skeys array\&. .br \fIpkey\fP Primary key\&. .br \fIvalue\fP Primary value\&. .br \fIuserdata\fP User context pointer (from corm_assoc_multi call)\&. .RE .PP \fBReturns\fP .RS 4 Number of keys written to skeys\&. .RE .PP .SS "typedef void corm_assoc_t(const void **skey, const void *const pkey, const void *const value, void *userdata)" .PP Association callback type\&. After association, future puts/dels on the primary will update the secondary\&. Deletes on the primary remove corresponding entries from the secondary\&. .PP \fBParameters\fP .RS 4 \fIskey\fP Pointer to set secondary key\&. .br \fIpkey\fP Primary key\&. .br \fIvalue\fP Primary value\&. .br \fIuserdata\fP User context pointer (from corm_assoc call)\&. .RE .PP .SH "Function Documentation" .PP .SS "void corm_assoc (uint32_t hd, uint32_t link, \fBcorm_assoc_t\fP cb, void * userdata)" .PP Make an association between tables\&. Links a secondary (index) map to a primary map so that put/delete operations on the primary automatically update the secondary\&. The callback determines the secondary key\&. .PP \fBParameters\fP .RS 4 \fIhd\fP Secondary (index) map handle\&. .br \fIlink\fP Primary (source) map handle\&. .br \fIcb\fP Callback to produce secondary keys\&. NULL → use primary value\&. .br \fIuserdata\fP User context pointer passed to callback\&. .RE .PP \fBNote\fP .RS 4 The secondary map stores (secondary_key, primary_value)\&. To retrieve the primary KEY instead of the primary VALUE, the secondary map must be created with the CM_PGET flag\&. This is essential for creating value→key indexes\&. .RE .PP .PP .nf // Example: Create a secondary index from username \-> user_id // Primary: user_id \-> username uint32_t users = corm_open(NULL, NULL, CM_U32, CM_STR, 0xFF, 0); // Secondary: username \-> user_id // CM_PGET makes corm_get return the primary key instead of value uint32_t by_name = corm_open(NULL, NULL, CM_STR, CM_U32, 0xFF, CM_PGET); // Callback: use primary value (username) as secondary key static void value_to_key(const void **skey, const void *pkey, const void *value) { (void) pkey; *skey = value; // Use username as key } corm_assoc(by_name, users, value_to_key); // Now puts to 'users' automatically update 'by_name' corm_put(users, &(uint32_t){100}, "alice"); // by_name now contains: "alice" \-> 100 .fi .PP .SS "void corm_assoc_multi (uint32_t hd, uint32_t link, \fBcorm_assoc_multi_t\fP cb, void * userdata)" .PP Make a multi-key association between tables\&. Like corm_assoc, but the callback produces multiple secondary keys from a single primary entry\&. The secondary is a root map (independent position space) with KEY=vtype=CM_STR, VALUE=ktype=CM_STR, and CM_MULTIVALUE|CM_SORTED flags\&. Each entry stores (ref_value, primary_key)\&. .PP Puts to the primary automatically insert entries into the secondary\&. Deletes from the primary automatically remove matching secondary entries\&. .PP \fBParameters\fP .RS 4 \fIhd\fP Secondary (index) map handle (root map, CM_STR/CM_STR)\&. .br \fIlink\fP Primary (source) map handle\&. .br \fIcb\fP Multi-key callback\&. .br \fIuserdata\fP User context pointer passed to callback\&. .RE .PP .SH "Author" .PP Generated automatically by Doxygen for corm from the source code\&.