cbstmap · Section 3
cbmap_construct
NAME
cbmap_construct - type-inferred BST map construction
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cbstmap.h> cbmap_construct(hm_name, key_type, val_type);
DESCRIPTION
Creates a BST map with the default settings. You don't name the kind of key: The macro works out whether key_type is a signed integer, an unsigned integer, a floating-point type, a string or some other type. It also creates the type marker variables, which carry the declared key type and value type to the other type-dispatching macros wherever you call them.
PARAMETERS
hm_name Name of the BST map variable to create key_type Type of the keys val_type Type of the values
NOTES
The macro stops the program when an allocation fails. The map gets the default memory management and the default comparison. A struct key_type is ordered by a raw memcmp of its bytes; see cbstmap_create_full(3) for the rules of the default comparison and for how to pass a custom_comparison_proc instead. For a struct key_type the type-inferred macro to use is cbmap_construct_cc. An array key type or value type, such as int[2] or char[16], does not compile, and the error message tells you to wrap the array in a struct. The macros copy keys and values by assignment, which C doesn't allow for an array, so the map would end up storing the address of the caller's array instead of its elements. A struct that holds the array works.
EXAMPLES
cbmap_construct(map, int, char*); int key = 42; cbmap_insert(map, key, "hello"); cbmap_destroy(map);