corm_assoc(3)corm

NAME

corm_assoc - Corm associations

- Linking of primary and secondary maps.

SYNOPSIS

Typedefs

typedef void corm_assoc_t(const void **skey, const void *const pkey, const void *const value, void *userdata)

Association callback type.

typedef size_t corm_assoc_multi_t(const void **skeys, size_t max_skeys, const void *pkey, const void *value, void *userdata)

Multi-key association callback type.

Functions

void corm_assoc (uint32_t hd, uint32_t link, corm_assoc_t cb, void *userdata)

Make an association between tables.

void corm_assoc_multi (uint32_t hd, uint32_t link, corm_assoc_multi_t cb, void *userdata)

Make a multi-key association between tables.

Detailed Description

Linking of primary and secondary maps.

See also

Corm open, close and save

Corm get, put, del and drop

Corm iteration

Corm type customization

Typedef Documentation

typedef size_t corm_assoc_multi_t(const void **skeys, size_t max_skeys, const void *pkey, const void *value, void *userdata)

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).

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.

Parameters

skeys Array to fill with secondary key pointers.
max_skeys Capacity of skeys array.
pkey Primary key.
value Primary value.
userdata User context pointer (from corm_assoc_multi call).

Returns

Number of keys written to skeys.

typedef void corm_assoc_t(const void **skey, const void *const pkey, const void *const value, void *userdata)

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.

Parameters

skey Pointer to set secondary key.
pkey Primary key.
value Primary value.
userdata User context pointer (from corm_assoc call).

Function Documentation

void corm_assoc (uint32_t hd, uint32_t link, corm_assoc_t cb, void * userdata)

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.

Parameters

hd Secondary (index) map handle.
link Primary (source) map handle.
cb Callback to produce secondary keys. NULL → use primary value.
userdata User context pointer passed to callback.

Note

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.

// 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

void corm_assoc_multi (uint32_t hd, uint32_t link, corm_assoc_multi_t cb, void * userdata)

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).

Puts to the primary automatically insert entries into the secondary. Deletes from the primary automatically remove matching secondary entries.

Parameters

hd Secondary (index) map handle (root map, CM_STR/CM_STR).
link Primary (source) map handle.
cb Multi-key callback.
userdata User context pointer passed to callback.

Author

Generated automatically by Doxygen for corm from the source code.