|
PatchworkOS
966e257
A non-POSIX operating system.
|
Hash Map. More...
Hash Map.
Data Structures | |
| struct | map_key_t |
| Map key stucture. More... | |
| struct | map_entry_t |
| Map entry structure. More... | |
| struct | map_t |
| Hash map structure. More... | |
Macros | |
| #define | MAP_MIN_CAPACITY 16 |
| The minimum capacity of a map. | |
| #define | MAP_MAX_LOAD_PERCENTAGE 75 |
| The maximum load percentage of a map before it resizes. | |
| #define | MAP_MIN_LOAD_PERCENTAGE 25 |
| The minimum load percentage of a map before it resizes down. | |
| #define | MAP_TOMBSTONE ((map_entry_t*)1) |
| The value used to indicate a tombstone (removed entry). | |
| #define | MAP_KEY_MAX_LENGTH 118 |
| The maximum length of a key in the map. | |
| #define | MAP_ENTRY_PTR_IS_VALID(entryPtr) ((entryPtr) != NULL && (entryPtr) != MAP_TOMBSTONE) |
| Check if a map entry pointer is valid (not NULL or tombstone). | |
| #define | MAP_CREATE() {.entries = NULL, .capacity = 0, .length = 0, .tombstones = 0} |
| Create a map initializer. | |
Functions | |
| uint64_t | hash_object (const void *object, uint64_t length) |
| Hash a object. | |
| static map_key_t | map_key_buffer (const void *buffer, uint64_t length) |
| Create a map key from a buffer. | |
| static map_key_t | map_key_uint64 (uint64_t uint64) |
| Create a map key from a uint64_t. | |
| static map_key_t | map_key_string (const char *str) |
| Create a map key from a string. | |
| void | map_entry_init (map_entry_t *entry) |
| Initialize a map entry. | |
| void | map_init (map_t *map) |
| Initialize a map. | |
| void | map_deinit (map_t *map) |
| Deinitialize a map. | |
| uint64_t | map_insert (map_t *map, const map_key_t *key, map_entry_t *value) |
| Insert a key-value pair into the map. | |
| uint64_t | map_replace (map_t *map, const map_key_t *key, map_entry_t *entry) |
| Replace a key-value pair in the map. | |
| map_entry_t * | map_get (map_t *map, const map_key_t *key) |
| Get a value from the map by key. | |
| map_entry_t * | map_get_and_remove (map_t *map, const map_key_t *key) |
| Get and remove a key-value pair from the map. | |
| void | map_remove (map_t *map, map_entry_t *entry) |
| Remove a entry from the map. | |
| void | map_remove_key (map_t *map, const map_key_t *key) |
| Remove a key-value pair from the map by key. | |
| uint64_t | map_size (const map_t *map) |
| Get the number of entries in the map. | |
| uint64_t | map_capacity (const map_t *map) |
| Get the capacity of the map. | |
| bool | map_is_empty (const map_t *map) |
| Check if the map is empty. | |
| bool | map_contains (map_t *map, const map_key_t *key) |
| Check if the map contains a key. | |
| void | map_clear (map_t *map) |
| Clear all entries from the map. | |
| uint64_t | map_reserve (map_t *map, uint64_t minCapacity) |
Reserve space in the map for at least minCapacity entries. | |
| #define MAP_MAX_LOAD_PERCENTAGE 75 |
| #define MAP_MIN_LOAD_PERCENTAGE 25 |
| #define MAP_TOMBSTONE ((map_entry_t*)1) |
| #define MAP_KEY_MAX_LENGTH 118 |
| #define MAP_ENTRY_PTR_IS_VALID | ( | entryPtr | ) | ((entryPtr) != NULL && (entryPtr) != MAP_TOMBSTONE) |
|
inlinestatic |
| void map_entry_init | ( | map_entry_t * | entry | ) |
| void map_init | ( | map_t * | map | ) |
| void map_deinit | ( | map_t * | map | ) |
| uint64_t map_insert | ( | map_t * | map, |
| const map_key_t * | key, | ||
| map_entry_t * | value | ||
| ) |
Insert a key-value pair into the map.
If the key already exists, then an EEXIST error is returned.
| map | The map to insert into. |
| key | The key to insert. |
| value | The value to insert. |
0. On failure, ERR and errno is set. Definition at line 204 of file map.c.
| uint64_t map_replace | ( | map_t * | map, |
| const map_key_t * | key, | ||
| map_entry_t * | entry | ||
| ) |
Replace a key-value pair in the map.
If the key does not exist, it is inserted.
| map | The map to replace in. |
| key | The key to replace. |
| value | The value to replace. |
0. On failure, ERR and errno is set. Definition at line 247 of file map.c.
| map_entry_t * map_get | ( | map_t * | map, |
| const map_key_t * | key | ||
| ) |
| map_entry_t * map_get_and_remove | ( | map_t * | map, |
| const map_key_t * | key | ||
| ) |
Get and remove a key-value pair from the map.
| map | The map to get from. |
| key | The key to get and remove. |
NULL. Definition at line 335 of file map.c.
| void map_remove | ( | map_t * | map, |
| map_entry_t * | entry | ||
| ) |
| void map_clear | ( | map_t * | map | ) |