Skip to content

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)
    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 &&
    static bool test_map_remove_value(void) {
        typedef Map(int, int) IntIntMap;
        IntIntMap map = MapInit(int_hash, int_compare);
    
        MapSetOnlyR(&map, 1, 10);
    static bool test_map_remove_if(void) {
        typedef Map(int, int) IntIntMap;
        IntIntMap map = MapInit(int_hash, int_compare);
    
        MapInsertR(&map, 1, 10);
    static bool test_map_remove_all(void) {
        typedef Map(int, int) IntIntMap;
        IntIntMap map = MapInit(int_hash, int_compare);
    
        MapInsertR(&map, 5, 50);
    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++) {
    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;
    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;
    static bool test_map_insert_and_set(void) {
        typedef Map(int, int) IntIntMap;
        IntIntMap map = MapInit(int_hash, int_compare);
    
        MapInsertR(&map, 1, 10);
    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;
    static bool test_map_ensure_ptr(void) {
        typedef Map(int, int) IntIntMap;
        IntIntMap map = MapInit(int_hash, int_compare);
        int      *value_ptr;
        bool      result;
    static bool test_map_retain_if(void) {
        typedef Map(int, int) IntIntMap;
        IntIntMap map       = MapInit(int_hash, int_compare);
        int       threshold = 30;
    static bool test_map_reserve_and_clear(void) {
        typedef Map(int, int) IntIntMap;
        IntIntMap map = MapInit(int_hash, int_compare);
    
        MapReserve(&map, 32);
    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++) {
    static bool test_map_get_ptr(void) {
        typedef Map(int, int) IntIntMap;
        IntIntMap map = MapInit(int_hash, int_compare);
    
        MapSetOnlyR(&map, 11, 110);
    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;
    
    #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)))
            ))
    #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