cbstmap · Section 3
cbstmap_create_full
NAME
cbstmap_create_full - create a BST map with full customization
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cbstmap.h>
cbmap cbstmap_create_full(ccol_data_type key_type,
ccol_memmgmt_procs *mmgmt_procs,
ccol_comparison_proc custom_comparison_proc,
char **err);
DESCRIPTION
Creates a self-balancing BST map and gives the caller full control over the key type, the memory management and the comparison function.
PARAMETERS
key_type Type of the keys that the map stores mmgmt_procs Custom memory management, or NULL custom_comparison_proc Custom comparison function, or NULL err Optional pointer that receives an error string
RETURN VALUE
A pointer to the new BST map on success, NULL on failure.
NOTES
The default comparison for each key type is: ccol_char: The platform's native char comparison, signed or unsigned to match how char behaves on this platform. ccol_signed_char and short/int/long/long_long: A signed comparison, which doesn't depend on whether char is signed on this platform. ccol_signed_char is a scalar signed char or its typedef int8_t; a signed char * string key is ccol_string instead. The unsigned integer types and ccol_pointer: An unsigned comparison. ccol_float/double/long_double: A numeric floating-point comparison, in which a NaN key sorts above every non-NaN key and equal to every other NaN key. ccol_string: A lexicographic order equivalent to strcmp. ccol_other_types (a struct key type, for example): A raw memcmp of the representation. That compares indeterminate padding bytes and compares each pointer member by its address, not by the object it points at, so pass a custom_comparison_proc for a struct key. All of these compare two keys of the same stored size. Only a key type of variable width, ccol_string or ccol_other_types, can have two keys of different sizes, and for those the map compares the common prefix first; when the prefix is equal it compares the sizes and the shorter key comes first. Every key of a fixed-width key type is exactly ccol_fixed_width_data_type_size(3) bytes wide, and every entry point that takes a key_pair needs that exact width. The same holds with a custom_comparison_proc, since that function gets two bare key pointers and no sizes and so reads a width that the key type fixes. A custom comparison gets void* pointers to the key data, and a key that comes in through the raw layer can be at any address. Read a key wider than one byte with memcpy, not through a pointer cast to the key type.
SEE ALSO
cbstmap_create(3), cbstmap_create_mp(3), cbstmap_create_ch(3), cbmap_destroy(3), ccol_determine_ccol_data_type(3)