chashmap · Section 3
chmap_init
NAME
chmap_init - create a hash map into an already declared handle
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/chashmap.h> chmap_init(hm_name);
DESCRIPTION
Creates a hash map with the default allocator and the map's own hashing, 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 the create half of a declare-then-create pair, for a handle that is declared in one place and created in another. When both happen together, chmap_construct(3) creates the same map in one step. The map picks its implementation from the declared key and value types, as chashmap_create_full(3) describes.
PARAMETERS
hm_name The already declared map handle to create the map into
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; call chashmap_create(3) directly when a failure has to be handled instead of being fatal Uses CHMAP_DEFAULT_INITIAL_BUCKET_ARRAY_SIZE (16) buckets Assigning over a handle that already holds a map leaks that map, so destroy the old one with chmap_destroy(3) first chmap_destroy(3) destroys the handle, which a handle declared with chmap_declare_scoped(3) doesn't need
EXAMPLES
chmap_declare(scores, char *, int); chmap_init(scores); int score = 42; chmap_insert(scores, "alice", score); chmap_destroy(scores);
SEE ALSO
chmap_declare(3), chmap_declare_scoped(3), chmap_init_mp(3), chmap_init_ch(3), chmap_init_full(3), chmap_construct(3), chashmap_create(3), chmap_destroy(3)