libwebsockets
Lightweight C library for HTML5 websockets
lws-map.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lws_map_info
 

Macros

#define lws_map_item_create_ks(_map, _str, _v, _vl)
 
#define lws_map_item_lookup_ks(_map, _str)    lws_map_item_lookup(_map, (const lws_map_key_t)_str, strlen(_str))
 

Typedefs

typedef struct lws_map lws_map_t
 
typedef void * lws_map_key_t
 
typedef void * lws_map_value_t
 
typedef uint32_t lws_map_hash_t
 
typedef lws_map_hash_t(* lws_map_hash_from_key_t) (const lws_map_key_t key, size_t kl)
 
typedef int(* lws_map_compare_key_t) (const lws_map_key_t key1, size_t kl1, const lws_map_value_t key2, size_t kl2)
 
typedef void *(* lws_map_alloc_t) (struct lws_map *mo, size_t x)
 
typedef void(* lws_map_free_t) (void *)
 
typedef struct lws_map_info lws_map_info_t
 

Functions

LWS_VISIBLE LWS_EXTERN const void * lws_map_item_key (struct lws_map_item *_item)
 
LWS_VISIBLE LWS_EXTERN const void * lws_map_item_value (struct lws_map_item *_item)
 
LWS_VISIBLE LWS_EXTERN size_t lws_map_item_key_len (struct lws_map_item *_item)
 
LWS_VISIBLE LWS_EXTERN size_t lws_map_item_value_len (struct lws_map_item *_item)
 
LWS_VISIBLE LWS_EXTERN lws_map_tlws_map_create (const lws_map_info_t *info)
 
LWS_VISIBLE LWS_EXTERN void * lws_map_alloc_lwsac (struct lws_map *map, size_t x)
 
LWS_VISIBLE LWS_EXTERN void lws_map_free_lwsac (void *v)
 
LWS_VISIBLE LWS_EXTERN void lws_map_destroy (lws_map_t **pmap)
 
LWS_VISIBLE LWS_EXTERN struct lws_map_item * lws_map_item_create (lws_map_t *map, const lws_map_key_t key, size_t keylen, const lws_map_value_t value, size_t valuelen)
 
LWS_VISIBLE LWS_EXTERN void lws_map_item_destroy (struct lws_map_item *item)
 
LWS_VISIBLE LWS_EXTERN struct lws_map_item * lws_map_item_lookup (lws_map_t *map, const lws_map_key_t key, size_t keylen)
 

Data Structure Documentation

◆ lws_map_info

struct lws_map_info

Definition at line 63 of file lws-map.h.

+ Collaboration diagram for lws_map_info:
Data Fields
lws_map_hash_from_key_t _hash
lws_map_compare_key_t _compare
lws_map_alloc_t _alloc
lws_map_free_t _free
void * opaque

&lwsac if using lwsac allocator

void * aux

chunk size if using lwsac allocator this can be used by the alloc handler, eg for lws_ac

size_t modulo

number of hashed owner lists to create

Macro Definition Documentation

◆ lws_map_item_create_ks

#define lws_map_item_create_ks (   _map,
  _str,
  _v,
  _vl 
)
Value:
lws_map_item_create(_map, (const lws_map_key_t)_str, \
strlen(_str), (const lws_map_value_t)_v, \
_vl)
LWS_VISIBLE LWS_EXTERN struct lws_map_item * lws_map_item_create(lws_map_t *map, const lws_map_key_t key, size_t keylen, const lws_map_value_t value, size_t valuelen)
void * lws_map_key_t
Definition: lws-map.h:46
void * lws_map_value_t
Definition: lws-map.h:49

Definition at line 91 of file lws-map.h.

◆ lws_map_item_lookup_ks

#define lws_map_item_lookup_ks (   _map,
  _str 
)     lws_map_item_lookup(_map, (const lws_map_key_t)_str, strlen(_str))

Definition at line 95 of file lws-map.h.

Typedef Documentation

◆ lws_map_t

typedef struct lws_map lws_map_t

Definition at line 1 of file lws-map.h.

◆ lws_map_key_t

typedef void* lws_map_key_t

Definition at line 48 of file lws-map.h.

◆ lws_map_value_t

typedef void* lws_map_value_t

Definition at line 49 of file lws-map.h.

◆ lws_map_hash_t

Definition at line 50 of file lws-map.h.

◆ lws_map_hash_from_key_t

typedef lws_map_hash_t(* lws_map_hash_from_key_t) (const lws_map_key_t key, size_t kl)

Definition at line 52 of file lws-map.h.

◆ lws_map_compare_key_t

typedef int(* lws_map_compare_key_t) (const lws_map_key_t key1, size_t kl1, const lws_map_value_t key2, size_t kl2)

Definition at line 54 of file lws-map.h.

◆ lws_map_alloc_t

typedef void*(* lws_map_alloc_t) (struct lws_map *mo, size_t x)

Definition at line 56 of file lws-map.h.

◆ lws_map_free_t

typedef void(* lws_map_free_t) (void *)

Definition at line 57 of file lws-map.h.

◆ lws_map_info_t

typedef struct lws_map_info lws_map_info_t

Function Documentation

◆ lws_map_item_key()

LWS_VISIBLE LWS_EXTERN const void* lws_map_item_key ( struct lws_map_item *  _item)

◆ lws_map_item_value()

LWS_VISIBLE LWS_EXTERN const void* lws_map_item_value ( struct lws_map_item *  _item)

◆ lws_map_item_key_len()

LWS_VISIBLE LWS_EXTERN size_t lws_map_item_key_len ( struct lws_map_item *  _item)

◆ lws_map_item_value_len()

LWS_VISIBLE LWS_EXTERN size_t lws_map_item_value_len ( struct lws_map_item *  _item)

◆ lws_map_create()

LWS_VISIBLE LWS_EXTERN lws_map_t* lws_map_create ( const lws_map_info_t info)

lws_map_create() - create a map object and hashtables on heap

Parameters
infodescription of map to create

Creates a map object on heap, using lws_malloc().

info may be all zeros inside, if so, modulo defaults to 8, and the operation callbacks default to using lws_malloc() / _free() for item alloc, a default xor / shift based hash and simple linear memory key compare.

For less typical use-cases, the provided info members can be tuned to control how the allocation of mapped items is done, lws provides two exports lws_map_alloc_lwsac() and lws_map_free_lwsac() that can be used for _alloc and _free to have items allocated inside an lwsac.

The map itself is created on the heap directly, the info._alloc() op is only used when creating items.

keys have individual memory sizes and do not need to all be the same length.

◆ lws_map_alloc_lwsac()

LWS_VISIBLE LWS_EXTERN void* lws_map_alloc_lwsac ( struct lws_map *  map,
size_t  x 
)

◆ lws_map_free_lwsac()

LWS_VISIBLE LWS_EXTERN void lws_map_free_lwsac ( void *  v)

◆ lws_map_destroy()

LWS_VISIBLE LWS_EXTERN void lws_map_destroy ( lws_map_t **  pmap)

lws_map_destroy() - deallocate all items and free map

Parameters
pmappointer to pointer map object to deallocate

Frees all items in the map, using info._free(), and then frees the map from heap directly. *pmap is set to NULL.

◆ lws_map_item_create()

LWS_VISIBLE LWS_EXTERN struct lws_map_item* lws_map_item_create ( lws_map_t map,
const lws_map_key_t  key,
size_t  keylen,
const lws_map_value_t  value,
size_t  valuelen 
)

lws_map_item_create() - allocate and map an item into an existing map

Parameters
mapthe map to add items into
keythe key, may be any kind of object
keylenthe length of the key in bytes
valuethe value, may be any kind of object
valuelenthe length of value

Allocates space for the item, key and value using the map allocator, and if non-NULL, copies the key and value into the item.

If an item with the same key exists, it is removed and destroyed before creating and adding the new one.

◆ lws_map_item_destroy()

LWS_VISIBLE LWS_EXTERN void lws_map_item_destroy ( struct lws_map_item *  item)

lws_map_item_destroy() - remove item from map and free

Parameters
itemthe item in the map to remove and free

◆ lws_map_item_lookup()

LWS_VISIBLE LWS_EXTERN struct lws_map_item* lws_map_item_lookup ( lws_map_t map,
const lws_map_key_t  key,
size_t  keylen 
)

lws_map_item_lookup() - look for a item with the given key in the map

Parameters
mapthe map
keythe key to look for
keylenthe length of the key to look for

Searches for the key in the map, using the map's key hash and key compare functions.