htils 1
A small set of utilities for C programming.
Loading...
Searching...
No Matches
stringmap.h File Reference
#include <h2o/memory.h>
#include <htils/basictypes.h>
#include <h2otils/string.h>

Go to the source code of this file.

Data Structures

struct  h2o_stringmap_entry
 A h2o_stringmap entry. More...
 
struct  h2o_stringmap
 A h2o_stringmap_t. More...
 

Macros

#define __H2O_SM_VAL(val)   (val), sizeof(*val)
 
#define h2o_sm_insert(map, key, value)    __h2o_sm_insert(map, key, __H2O_SM_VAL(value))
 

Typedefs

typedef enum h2o_stringmap_entry_state h2o_stringmap_entry_state_t
 The state of a h2o_stringmap entry.
 
typedef enum h2o_stringmap_result h2o_stringmap_result_t
 The result of a stringmap operation.
 
typedef struct h2o_stringmap_entry h2o_stringmap_entry_t
 A h2o_stringmap entry.
 
typedef struct h2o_stringmap h2o_stringmap_t
 A h2o_stringmap_t.
 

Enumerations

enum  h2o_stringmap_entry_state { EMPTY , OCCUPIED , DEAD }
 The state of a h2o_stringmap entry. More...
 
enum  h2o_stringmap_result { CREATED , UPDATED , NOT_FOUND , KILLED }
 The result of a stringmap operation. More...
 

Functions

h2o_stringmap_th2o_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, 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.
 

Macro Definition Documentation

◆ __H2O_SM_VAL

#define __H2O_SM_VAL (   val)    (val), sizeof(*val)

◆ h2o_sm_insert

#define h2o_sm_insert (   map,
  key,
  value 
)     __h2o_sm_insert(map, key, __H2O_SM_VAL(value))

Typedef Documentation

◆ h2o_stringmap_entry_state_t

The state of a h2o_stringmap entry.

Parameters
EMPTYThe entry is empty.
OCCUPIEDThe entry is occupied.
DEADThe entry is dead.

◆ h2o_stringmap_entry_t

A h2o_stringmap entry.

Parameters
keyThe key of the entry.
valueThe value of the entry.
stateThe state of the entry.

◆ h2o_stringmap_result_t

The result of a stringmap operation.

Parameters
CREATEDThe entry was created.
UPDATEDThe entry was updated.
NOT_FOUNDThe entry was not found.
KILLEDThe entry was killed.

◆ h2o_stringmap_t

A h2o_stringmap_t.

Parameters
poolThe memory pool to allocate from.
entriesThe entries of the h2o_stringmap_t.
capacityThe capacity of the h2o_stringmap_t.
countThe amount of entries in the h2o_stringmap_t.
dead_entriesThe amount of dead entries of the h2o_stringmap_t.

Enumeration Type Documentation

◆ h2o_stringmap_entry_state

The state of a h2o_stringmap entry.

Parameters
EMPTYThe entry is empty.
OCCUPIEDThe entry is occupied.
DEADThe entry is dead.
Enumerator
EMPTY 
OCCUPIED 
DEAD 

◆ h2o_stringmap_result

The result of a stringmap operation.

Parameters
CREATEDThe entry was created.
UPDATEDThe entry was updated.
NOT_FOUNDThe entry was not found.
KILLEDThe entry was killed.
Enumerator
CREATED 
UPDATED 
NOT_FOUND 
KILLED 

Function Documentation

◆ __h2o_sm_insert()

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.

Note
This function is not meant to be run directly, and is called by the h2o_sm_insert() macro.
Parameters
mapThe h2o_stringmap_t to insert into.
keyThe key to insert.
valueThe value to associate with the key.
vsizeThe size of the value.
Precondition
  • map and key must be valid and cannot be null.
  • value can't be null, as it would lead to a null dereference.
Returns
The result of the insert (which will be either CREATED or UPDATED in this case).

◆ h2o_sm_get()

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.

Parameters
mapThe h2o_stringmap_t to get from.
keyThe key to get.
Precondition
map and key must be valid and cannot be null.
Returns
The value associated with the key, or null if it doesn't exist or is dead.

◆ h2o_sm_kill()

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.

Parameters
mapThe h2o_stringmap_t to remove from.
keyThe key to remove.
Precondition
stringmap and key must be valid and cannot be null.
Returns
The result of the remove (which will be either KILLED or NOT_FOUND in this case).

◆ h2o_sm_new()

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.

Parameters
poolThe memory pool to allocate from.
capacityThe capacity of the h2o_stringmap_t.
Precondition
pool must be valid and cannot be null.
Returns
A pointer to the new h2o_stringmap_t.