Subastra
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Data Fields
map_t Struct Reference

#include <map.h>

Collaboration diagram for map_t:
Collaboration graph
[legend]

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.
 

Member Function Documentation

◆ map_cleanup()

static void map_cleanup ( map_t *  map)
static

Cleanup the memory used by the map itself. Importantly, does not clean the internal types stored inside the map. O(N)

◆ map_get()

static void * map_get ( map_t *  map,
map_key_t  key 
)
static

Retrieves the element of the map at key map_key. Returns NULL if no element found. O(1*)

◆ map_grow()

static void map_grow ( map_t *  map)
static

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)

◆ map_init()

static void map_init ( map_t *  map,
allocator_t  allocator,
sz  entry_size 
)
static

Initializes the map with a fixed size and some initial capacity. O(1)

Parameters
entry_sizeThe size of the type stored inside the map

◆ map_init_with_capacity()

static void map_init_with_capacity ( map_t *  map,
allocator_t  allocator,
sz  entry_size,
sz  capacity 
)
static

Initialize the map with a specific capacity and entry size. O(1)

◆ map_insert()

static void map_insert ( map_t *  map,
map_key_t  key,
void *  data,
sz  size 
)
static

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*)

Field Documentation

◆ allocator

allocator_t allocator

The allocator used for all memory management, used for allocating both the main and the secondary storages.

◆ buckets

void* buckets

The raw byte storage used for the buckets.

◆ capacity

sz capacity

The amount of buckets available.

◆ entry_size

sz entry_size

The size of a single entry in bytes. Serves as a guardrail for runtime checking.

◆ size

sz size

The amount of elements currently in the map.