|
htils 1
A small set of utilities for C programming.
|
#include <string.h>#include <h2o/memory.h>#include <htils/assert.h>#include <htils/basictypes.h>#include <h2otils/string.h>#include <h2otils/stringmap.h>Macros | |
| #define | DEFAULT_CAPACITY 16 |
Functions | |
| static u64 | hash_key (const h2o_string *key) |
| Hash a key into an index. | |
| static void | sm_insert_direct (h2o_stringmap_t *map, const h2o_string *key, void *value, u64 vsize) |
| Inserts a key-value pair into the stringmap directly. | |
| static void | h2o_sm_grow (h2o_stringmap_t *map) |
| Grow a stringmap if it's too small. | |
| h2o_stringmap_t * | h2o_sm_new (h2o_mem_pool_t *pool, const u64 capacity) |
| Initializes a new h2o_stringmap_t. | |
| h2o_stringmap_result_t | __h2o_sm_insert (h2o_stringmap_t *map, const h2o_string *key, const void *value, const u64 vsize) |
Insert key and value into the h2o_stringmap_t. | |
| h2o_stringmap_result_t | h2o_sm_kill (h2o_stringmap_t *map, const h2o_string *key) |
Remove / Kill entry at key from the h2o_stringmap_t. | |
| void * | h2o_sm_get (h2o_stringmap_t *map, const h2o_string *key) |
| Get a V from the h2o_stringmap_t. | |
| #define DEFAULT_CAPACITY 16 |
| h2o_stringmap_result_t __h2o_sm_insert | ( | h2o_stringmap_t * | map, |
| const h2o_string * | key, | ||
| const void * | value, | ||
| u64 | vsize | ||
| ) |
Insert key and value into the h2o_stringmap_t.
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 h2o_stringmap_t to insert into. |
| key | The key to insert. |
| value | The value to associate with the key. |
| vsize | The size of the value. |
map and key must be valid and cannot be null.value can't be null, as it would lead to a null dereference.| void * h2o_sm_get | ( | h2o_stringmap_t * | map, |
| const h2o_string * | key | ||
| ) |
Get a V from the h2o_stringmap_t.
Gets an entry from the h2o_stringmap_t, if the entry doesn't exist, it will be null.
| map | The h2o_stringmap_t to get from. |
| key | The key to get. |
map and key must be valid and cannot be null.
|
static |
Grow a stringmap if it's too small.
By doubling the capacity, allocating a new block using h2o_mem_alloc_pool(), and copying over all occupied entries.
| map | The stringmap to grow. |
map must be valid and cannot be null. | h2o_stringmap_result_t h2o_sm_kill | ( | h2o_stringmap_t * | map, |
| const h2o_string * | key | ||
| ) |
Remove / Kill entry at key from the h2o_stringmap_t.
Marks an entry as DEAD, if the key doesn't exist, it will return NOT_FOUND, otherwise it will return KILLED.
| map | The h2o_stringmap_t to remove from. |
| key | The key to remove. |
stringmap and key must be valid and cannot be null.| h2o_stringmap_t * h2o_sm_new | ( | h2o_mem_pool_t * | pool, |
| const u64 | capacity | ||
| ) |
Initializes a new h2o_stringmap_t.
Optionally use a nullable type for h2o_stringmaps.
With the capacity, and pool, if the given capacity is 0, it will use the built in default capacity, which is 16.
| pool | The memory pool to allocate from. |
| capacity | The capacity of the h2o_stringmap_t. |
pool must be valid and cannot be null.
|
static |
Hash a key into an index.
Hashes a key into an index, using the FNV-1a algorithm.
| key | The key to hash. |
key must be valid and cannot be null.
|
static |
Inserts a key-value pair into the stringmap directly.
By first hashing the key, then iterating through the entries.
| map | The h2o_stringmap_t to insert into. |
| key | The key to insert. |
| value | The value to insert. |
| vsize | The size of the value. |
map, key, and value must be valid and cannot be null.vsize must be greater than 0 and the explicit size of the value, since @value is a void * it has to be provided.