Subastra
|
#include <map.h>
Public Member Functions | |
#define | MAP_LOAD_FACTOR 75 |
The load factor (in %) to be used when deciding if its time to resize the map. | |
#define | MAP_MAX_CAPACITY (1 << 30) |
The maximum capactiy of the map. Will not resize further independent of the MAP_LOAD_FACTOR. | |
#define | map_init_ty(ty, map, allocator) map_init(map, allocator, sizeof(ty)) |
Initialize a typed map. O(1) | |
Static Public Member Functions | |
static void | map_init_with_capacity (map_t *map, allocator_t allocator, sz entry_size, sz capacity) |
Initialize the map with a specific capacity and entry size. O(1) | |
static void | map_init (map_t *map, allocator_t allocator, sz entry_size) |
Initializes the map with a fixed size and some initial capacity. O(1) | |
static void | map_cleanup (map_t *map) |
Cleanup the memory used by the map itself. Importantly, does not clean the internal types stored inside the map. O(N) | |
static void | map_grow (map_t *map) |
Tries to grow the map. Doubles the size and reallocates all buckets. Will not grow if the MAP_LOAD_FACTOR is not reached. O(N) | |
static void | map_insert (map_t *map, map_key_t key, void *data, sz size) |
Insert an element of the size size into the map. Does an additional check to verify that the size of the insertion matches the size set at initialization. O(1*) | |
static void * | map_get (map_t *map, map_key_t key) |
Retrieves the element of the map at key map_key . Returns NULL if no element found. O(1*) | |
Data Fields | |
allocator_t | allocator |
The allocator used for all memory management, used for allocating both the main and the secondary storages. | |
sz | entry_size |
The size of a single entry in bytes. Serves as a guardrail for runtime checking. | |
sz | size |
The amount of elements currently in the map. | |
sz | capacity |
The amount of buckets available. | |
void * | buckets |
The raw byte storage used for the buckets. | |
Cleanup the memory used by the map itself. Importantly, does not clean the internal types stored inside the map. O(N)
Tries to grow the map. Doubles the size and reallocates all buckets. Will not grow if the MAP_LOAD_FACTOR is not reached. O(N)
|
static |
Initializes the map with a fixed size and some initial capacity. O(1)
entry_size | The size of the type stored inside the map |
|
static |
Initialize the map with a specific capacity and entry size. O(1)
Insert an element of the size size
into the map. Does an additional check to verify that the size of the insertion matches the size set at initialization. O(1*)
allocator_t allocator |
The allocator used for all memory management, used for allocating both the main and the secondary storages.
void* buckets |
The raw byte storage used for the buckets.
sz capacity |
The amount of buckets available.
sz entry_size |
The size of a single entry in bytes. Serves as a guardrail for runtime checking.
sz size |
The amount of elements currently in the map.