MapInit
MapInit
Description
Initialize map with required key hash and compare callbacks. Uses linear probing by default.
Parameters
| Name | Direction | Description |
|---|---|---|
hash_fn |
in | Hash callback for keys. |
compare_fn |
in | Key comparator. Equality is compare_fn(a, b) == 0. |
Usage example (from documentation)
typedef Map(int, Str) IntStrMap;
IntStrMap map = MapInit(IntHash, IntCompare);Usage example (Cross-references)
Usage examples (Cross-references)
- In
Map.Type.c:55:
static bool test_map_type_defaults(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
return map.length == 0 && map.capacity == 0 && map.tombstones == 0 && map.entries == NULL && map.states == NULL &&- In
Map.Remove.c:22:
static bool test_map_remove_value(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
MapSetOnlyR(&map, 1, 10);- In
Map.Remove.c:64:
static bool test_map_remove_if(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
MapInsertR(&map, 1, 10);- In
Map.Remove.c:84:
static bool test_map_remove_all(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
MapInsertR(&map, 5, 50);- In
Map.Remove.c:103:
static bool test_map_tombstone_reuse(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
for (int i = 0; i < 12; i++) {- In
Map.Foreach.c:22:
static bool test_map_foreach_ptr(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
int key_sum = 0;
int value_sum = 0;- In
Map.Foreach.c:44:
static bool test_map_foreach_multimap_iterators(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
int unique_key_sum = 0;
int all_value_sum = 0;- In
Map.Insert.c:22:
static bool test_map_insert_and_set(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
MapInsertR(&map, 1, 10);- In
Map.Insert.c:64:
static bool test_map_lvalue_zeroing(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
int key = 42;
int value = 84;- In
Map.Insert.c:80:
static bool test_map_ensure_ptr(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
int *value_ptr;
bool result;- In
Map.Ops.c:156:
static bool test_map_retain_if(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
int threshold = 30;- In
Map.Init.c:54:
static bool test_map_reserve_and_clear(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
MapReserve(&map, 32);- In
Map.Init.c:69:
static bool test_map_rehash_policy_switch(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
for (int i = 0; i < 24; i++) {- In
Map.Access.c:45:
static bool test_map_get_ptr(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
MapSetOnlyR(&map, 11, 110);- In
Map.Access.c:60:
static bool test_map_value_cursor_query(void) {
typedef Map(int, int) IntIntMap;
IntIntMap map = MapInit(int_hash, int_compare);
MapValueCursor cursor = MapValueCursorInvalid();
int value_sum = 0;- In
Init.h:211:
#ifdef __cplusplus
# define MapInitT(m, hash_fn, compare_fn) (TYPE_OF(m) MapInit((hash_fn), (compare_fn)))
# define MapInitWithValueCompareT(m, hash_fn, compare_fn, value_compare_fn) \
(TYPE_OF(m) MapInitWithValueCompare((hash_fn), (compare_fn), (value_compare_fn)))- In
Init.h:271:
))
#else
# define MapInitT(m, hash_fn, compare_fn) ((TYPE_OF(m))MapInit((hash_fn), (compare_fn)))
# define MapInitWithValueCompareT(m, hash_fn, compare_fn, value_compare_fn) \
((TYPE_OF(m))MapInitWithValueCompare((hash_fn), (compare_fn), (value_compare_fn)))
Last updated on