Skip to content
MapInitWithPolicy

MapInitWithPolicy

Description

Initialize a map with key callbacks and an explicit probing policy.

Usage example (Cross-references)

Usage examples (Cross-references)
                   .max_probe_count = 32,
        };
        IntIntMap map    = MapInitWithPolicy(i32_hash, i32_compare, custom_policy, &alloc);
        bool      result = true;
        DefaultAllocator alloc  = DefaultAllocatorInit();
        MapPolicy        policy = make_small_probe_policy();
        IntIntMap        map    = MapInitWithPolicy(i32_identity_hash, i32_compare, policy, &alloc);
    
        const int keys[] = {0, 8, 16, 24, 32, 40};
        DefaultAllocator alloc  = DefaultAllocatorInit();
        MapPolicy        policy = fill_then_grow_policy();
        IntIntMap        map    = MapInitWithPolicy(i32_hash, i32_compare, policy, &alloc);
        bool             result = true;
                   .max_probe_count = 4,
        };
        IntIntMap map = MapInitWithPolicy(id_hash, i32_compare, policy, &alloc);
    
        const int keys[] = {0, 16, 32, 48, 64};
        DefaultAllocator alloc  = DefaultAllocatorInit();
        MapPolicy        policy = make_policy42();
        IntIntMap        map    = MapInitWithPolicy(i32_hash, i32_compare, policy, &alloc);
    
        MapInsertR(&map, 1, 10);
        DefaultAllocator alloc  = DefaultAllocatorInit();
        MapPolicy        policy = fill_then_grow_policy();
        IntIntMap        map    = MapInitWithPolicy(i32_hash, i32_compare, policy, &alloc);
    
        for (int k = 0; k < 8; k++)
                   .max_probe_count = 11,
        };
        IntIntMap map = MapInitWithPolicy(i32_hash, i32_compare, custom_policy, &alloc);
    
        custom_policy.name            = "changed";
    // would let an invalid-policy map be built silently.
    static bool test_map_init_with_invalid_policy_fails(void) {
        WriteFmt("Testing MapInitWithPolicy with an invalid policy\n");
    
        typedef Map(int, int) IntIntMap;
        policy.max_probe_count  = 0; // single broken field
    
        IntIntMap map = MapInitWithPolicy(i32_hash, i32_compare, policy, &alloc);
        (void)map;
        return false;
                   .max_probe_count = 8,
        };
        IntIntMap map    = MapInitWithPolicy(i32_hash, i32_compare, policy, &alloc);
        bool      result = MapInsertR(&map, 1, 10);
        result           = result && MapGetFirstPtr(&map, 1) && (*MapGetFirstPtr(&map, 1) == 10);
        DefaultAllocator alloc  = DefaultAllocatorInit();
        MapPolicy        policy = make_probe_policy(poly_next_index_stuck_at_cap8);
        IntIntMap        map    = MapInitWithPolicy(i32_hash, i32_compare, policy, &alloc); // must LOG_FATAL
        MapDeinit(&map);
        DefaultAllocatorDeinit(&alloc);
        DefaultAllocator alloc  = DefaultAllocatorInit();
        MapPolicy        policy = make_probe_policy(poly_next_index_stuck_at_golden);
        IntIntMap        map    = MapInitWithPolicy(i32_hash, i32_compare, policy, &alloc); // must LOG_FATAL
        MapDeinit(&map);
        DefaultAllocatorDeinit(&alloc);
        DefaultAllocator alloc  = DefaultAllocatorInit();
        MapPolicy        policy = make_probe_policy(poly_next_index_returns_first);
        IntIntMap        map    = MapInitWithPolicy(i32_hash, i32_compare, policy, &alloc); // must LOG_FATAL
        MapDeinit(&map);
        DefaultAllocatorDeinit(&alloc);
                   .max_probe_count = 100,
        };
        IntIntMap map = MapInitWithPolicy(const_hash, i32_compare, policy, &alloc);
    
        MapReserve(&map, 200);
                   .max_probe_count = 32,
        };
        IntIntMap map = MapInitWithPolicy(const_hash, i32_compare, policy, &alloc);
    
        MapReserve(&map, 6);
Last updated on