chashmap · Section 3
chmap_init_mp
NAME
chmap_init_mp - create a hash map with a custom allocator into an already declared handle
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/chashmap.h> chmap_init_mp(hm_name, mmgmt_procs);
DESCRIPTION
Creates a hash map that takes all of its memory from mmgmt_procs, and assigns it to hm_name. The handle has to be declared first, with chmap_declare(3) or chmap_declare_scoped(3). The key and value types are not arguments, because the macro reads them from the companion type variables that the declare macro created. It is chmap_init(3) with an allocator added, and the map uses its own hashing for the declared key type. chmap_init_ch(3) swaps the hashing instead, and chmap_init_full(3) takes both. The one-step equivalents are chmap_construct_mp(3) and chmap_construct_mp_scoped(3).
PARAMETERS
hm_name The already declared map handle to create the map into
mmgmt_procs Pointer to a ccol_memmgmt_procs, or NULL for the default
allocator
RETURN VALUE
None. The macro expands to a statement and is not an expression.
NOTES
Stops the program through ccol__fatal_err() if the creation fails All four members of ccol_memmgmt_procs must be non-NULL The macro copies the procedures into the map, so your own ccol_memmgmt_procs doesn't need to outlive the call, but the procedures themselves must stay callable for the whole life of the map Everything the map allocates later, its bucket array included, comes from these procedures, and everything it frees goes back to them Uses CHMAP_DEFAULT_INITIAL_BUCKET_ARRAY_SIZE (16) buckets
EXAMPLES
ccol_memmgmt_procs procs = {
.malloc = my_malloc, .calloc = my_calloc,
.realloc = my_realloc, .free = my_free,
};
chmap_declare(scores, char *, int);
chmap_init_mp(scores, &procs);
int score = 42;
chmap_insert(scores, "alice", score);
chmap_destroy(scores);
SEE ALSO
chmap_init(3), chmap_init_ch(3), chmap_init_full(3), chmap_declare(3), chmap_construct_mp(3), chashmap_create_full(3), chmap_destroy(3)