Handle-based map using either fixed-length arrays, or exponential arrays from "core:container/xar". Example: import hm "core:container/handle_map" Handle :: hm.Handle32 Entity :: struct { handle: Handle, pos: [2]f32, } { // static map entities: hm.Static_Handle_Map(1024, Entity, Handle) h1 := hm.add(&entities, Entity{pos = {1, 4}}) h2 := hm.add(&entities, Entity{pos = {9, 16}}) if e, ok := hm.get(&entities, h2); ok { e.pos.x += 32 } hm.remove(&entities, h1) h3 := hm.add(&entities, Entity{pos = {6, 7}}) assert(hm.is_valid(entities, h3)) it := hm.iterator_make(&entities) for e, h in hm.iterate(&it) { assert(hm.is_valid(entities, h)) e.pos += {1, 2} } } { // dynamic map entities: hm.Dynamic_Handle_Map(Entity, Handle) hm.dynamic_init(&entities, context.allocator) defer hm.dynamic_destroy(&entities) h1 := hm.add(&entities, Entity{pos = {1, 4}}) h2 := hm.add(&entities, Entity{pos = {9, 16}}) if e, ok := hm.get(&entities, h2); ok { e.pos.x += 32 } hm.remove(&entities, h1) h3 := hm.add(&entities, Entity{pos = {6, 7}}) assert(hm.is_valid(entities, h3)) it := hm.iterator_make(&entities) for e, h in hm.iterate(&it) { assert(hm.is_valid(entities, h)) e.pos += {1, 2} } }

Collection Info

View Source
Collection
core
Path
container/handle_map
Entries
36

Source Files

Types

7

Handle16 #

Source
Handle16 :: Handle16

Default 16-bit Handle type which can be used for handle maps which only need a maximum of 254 (1<<8 - 2) items

Handle32 #

Source
Handle32 :: Handle32

Default 32-bit Handle type which can be used for handle maps which only need a maximum of 65534 (1<<16 - 2) items

Handle64 #

Source
Handle64 :: Handle64

Default 64-bit Handle type which can be used for handle maps which only need a maximum of 4294967294 (1<<32 - 2) items

Procedures

20

dynamic_get #

Source
@(require_results)
dynamic_get :: proc "contextless" (m: ^$D/Dynamic_Handle_Map($T, $Handle_Type), h: $Handle_Type) -> ($$deferred_return, bool) #optional_ok {…}

dynamic_iterate #

Source
@(require_results)
dynamic_iterate :: proc "contextless" (it: ^$DHI/Dynamic_Handle_Map_Iterator($D)) -> (val: $$deferred_return, h: $$deferred_return, ok: bool) {…}

Iterate over a handle map. It will skip over unused item slots (e.g. handle.idx == 0). Usage: it := hm.dynamic_iterator_make(&the_dynamic_handle_map) for item, handle in hm.iterate(&it) { ... }

dynamic_iterator_make #

Source
@(require_results)
dynamic_iterator_make :: proc "contextless" (m: ^$D/Dynamic_Handle_Map($T, $Handle_Type)) -> $$deferred_return {…}

Makes an iterator from a handle map.

dynamic_len #

Source
@(require_results)
dynamic_len :: proc "contextless" (m: $D/Dynamic_Handle_Map($T, $Handle_Type)) -> uint {…}

Returns the number of possibly valid items in the handle map.

static_add #

Source
@(require_results)
static_add :: proc "contextless" (m: ^$H/Static_Handle_Map($N, $T, $Handle_Type), item: $T) -> (handle: $$deferred_return, ok: bool) #optional_ok {…}

`add` a value of type `T` to the handle map. This will return a pointer to the item and an optional boolean to check for validity.

static_cap #

Source
@(require_results)
static_cap :: proc "contextless" (m: $H/Static_Handle_Map($N, $T, $Handle_Type)) -> uint {…}

Returns the capacity of the items in a handle map. This is equivalent to `N-1` as the zero value is reserved for the zero-value sentinel.

static_clear #

Source
static_clear :: proc "contextless" (m: ^$H/Static_Handle_Map($N, $T, $Handle_Type)) {…}

`clear` the handle map by zeroing all of the memory. Internally this does not do `m^ = {}` but rather uses `intrinsics.mem_zero` explicitly improve performance.

static_get #

Source
@(require_results)
static_get :: proc "contextless" (m: ^$H/Static_Handle_Map($N, $T, $Handle_Type), h: $Handle_Type) -> ($$deferred_return, bool) #optional_ok {…}

`get` a stable pointer of type `^T` by resolving the handle `h`. If the handle is not valid, then `nil, false` is returned.

static_is_valid #

Source
@(require_results)
static_is_valid :: proc "contextless" (m: $H/Static_Handle_Map($N, $T, $Handle_Type), h: $Handle_Type) -> bool {…}

Returns true when the handle `h` is valid relating to the handle map.

static_iterate #

Source
@(require_results)
static_iterate :: proc "contextless" (it: ^$HI/Static_Handle_Map_Iterator($H)) -> (val: $$deferred_return, h: $$deferred_return, ok: bool) {…}

Iterate over a handle map. It will skip over unused item slots (e.g. handle.idx == 0). Usage: it := hm.iterator_make(&the_handle_map) for item, handle in hm.iterate(&it) { ... }

static_iterator_make #

Source
@(require_results)
static_iterator_make :: proc "contextless" (m: ^$H/Static_Handle_Map($N, $T, $Handle_Type)) -> $$deferred_return {…}

Makes an iterator from a handle map.

static_len #

Source
@(require_results)
static_len :: proc "contextless" (m: $H/Static_Handle_Map($N, $T, $Handle_Type)) -> uint {…}

Returns the number of possibly valid items in the handle map.

static_remove #

Source
static_remove :: proc "contextless" (m: ^$H/Static_Handle_Map($N, $T, $Handle_Type), h: $Handle_Type) -> bool {…}

`remove` an item from the handle map from the handle `h`.

Procedure Groups

9