|
htils 1
A small set of utilities for C programming.
|
Go to the source code of this file.
Data Structures | |
| struct | stringmap_entry |
| A stringmap entry. More... | |
| struct | stringmap |
| A stringmap. More... | |
Macros | |
| #define | SM_VAL(val) |
| #define | sm_insert(map, key, value) |
Typedefs | |
| typedef enum stringmap_entry_state | stringmap_entry_state_t |
| typedef enum stringmap_result | stringmap_result_t |
| typedef struct stringmap_entry | stringmap_entry_t |
| A stringmap entry. | |
| typedef struct stringmap | stringmap_t |
| A stringmap. | |
Enumerations | |
| enum | stringmap_entry_state { EMPTY , OCCUPIED , DEAD } |
| enum | stringmap_result { CREATED , UPDATED , NOT_FOUND , KILLED } |
Functions | |
| stringmap_t * | sm_new (arena_t *arena, const u64 capacity) |
| Initializes a new stringmap. | |
| stringmap_result_t | __sm_insert (stringmap_t *map, const string *key, const void *value, u64 vsize) |
Insert key and value into the stringmap. | |
| stringmap_result_t | sm_kill (stringmap_t *map, const string *key) |
Remove the entry at key from the stringmap. | |
| void * | sm_get (stringmap_t *map, const string *key) |
| Get a value from the stringmap. | |
| #define sm_insert | ( | map, | |
| key, | |||
| value ) |
| #define SM_VAL | ( | val | ) |
| typedef enum stringmap_entry_state stringmap_entry_state_t |
| typedef struct stringmap_entry stringmap_entry_t |
A stringmap entry.
| key | The key of the entry. |
| value | The value of the entry. |
| vsize | The size of the value. |
| state | The state of the entry. |
| typedef enum stringmap_result stringmap_result_t |
| typedef struct stringmap stringmap_t |
| enum stringmap_result |
| stringmap_result_t __sm_insert | ( | stringmap_t * | map, |
| const string * | key, | ||
| const void * | value, | ||
| u64 | vsize ) |
Insert key and value into the stringmap.
Hashes and duplicates the key and sets the value, if the key already exists, it will be updated, if the capacity is too small, it will be automatically grown.
| map | The stringmap to insert into. |
| key | The key to insert. |
| value | The value to associate with the key. |
| vsize | The size of the value. |
| void * sm_get | ( | stringmap_t * | map, |
| const string * | key ) |
Get a value from the stringmap.
Returns the value stored at key, or null if the key is absent or the entry is dead.
| map | The stringmap to get from. |
| key | The key to get. |
map and key must be valid and cannot be null.| stringmap_result_t sm_kill | ( | stringmap_t * | map, |
| const string * | key ) |
Remove the entry at key from the stringmap.
Marks an entry as DEAD, if the key doesn't exist, it will return NOT_FOUND, otherwise it will return KILLED.
| map | The stringmap to remove from. |
| key | The key to remove. |
map and key must be valid and cannot be null.| stringmap_t * sm_new | ( | arena_t * | arena, |
| const u64 | capacity ) |
Initializes a new stringmap.
Optionally use a nullable type for stringmaps.
With the capacity, and arena, if the given capacity is 0, it will use the built in default capacity, which is 16.
arena must be valid and cannot be null.