hmap_easy: Simplified Interface (recommended)
[HMap]

Functions

int u_hmap_easy_new (u_hmap_opts_t *opts, u_hmap_t **phmap)
 Create a new hmap.
void u_hmap_easy_clear (u_hmap_t *hmap)
 Clear hmap.
void u_hmap_easy_free (u_hmap_t *hmap)
 Deallocate hmap.
int u_hmap_easy_put (u_hmap_t *hmap, const char *key, const void *val)
 Insert an object into the hmap.
void * u_hmap_easy_get (u_hmap_t *hmap, const char *key)
 Retrieve a value from the hmap.
int u_hmap_easy_del (u_hmap_t *hmap, const char *key)
 Delete an object from the hmap.

Function Documentation

void u_hmap_easy_clear ( u_hmap_t *  hmap  ) 

See u_hmap_clear().

Parameters:
hmap hmap object

Definition at line 302 of file srcs/toolbox/hmap.c.

References u_hmap_clear().

int u_hmap_easy_del ( u_hmap_t *  hmap,
const char *  key 
)

Delete object with given key from hmap.

Parameters:
hmap hmap object
key key of object to be deleted
Return values:
U_HMAP_ERR_NONE on success
U_HMAP_ERR_FAIL on failure

Definition at line 398 of file srcs/toolbox/hmap.c.

References u_hmap_del().

void u_hmap_easy_free ( u_hmap_t *  hmap  ) 

Deallocate hmap along with all hmapd objects. Objects are freed by using the function pointer specified with u_hmap_opts_set_val_freefunc() if it is not NULL.

Parameters:
hmap hmap object

Definition at line 318 of file srcs/toolbox/hmap.c.

References u_hmap_free().

Referenced by u_json_free(), u_json_index(), and u_json_unindex().

void* u_hmap_easy_get ( u_hmap_t *  hmap,
const char *  key 
)

Retrieve the value with given key from hmap.

Parameters:
hmap hmap object
key key to be retrieved
Returns:
a pointer to the retrieved value on success, NULL on failure or no match

Definition at line 378 of file srcs/toolbox/hmap.c.

References u_hmap_get().

Referenced by u_json_cache_get().

int u_hmap_easy_new ( u_hmap_opts_t *  opts,
u_hmap_t **  phmap 
)

Create a new hmap object and save its pointer to *hmap. The call may fail on memory allocation problems or if the options are manipulated incorrectly.

Parameters:
opts options to be passed to the hmap
phmap on success contains the hmap options object
Return values:
U_HMAP_ERR_NONE on success
U_HMAP_ERR_FAIL on failure

Definition at line 274 of file srcs/toolbox/hmap.c.

References u_hmap_new(), u_hmap_opts_copy(), and u_hmap_opts_init().

Referenced by u_json_index().

int u_hmap_easy_put ( u_hmap_t *  hmap,
const char *  key,
const void *  val 
)

Insert a key, val pair into hmap.

The size of val copied into the hmap is based on its type set using u_hmap_opts_set_val_type():

  • U_HMAP_OPTS_DATATYPE_POINTER (default): the pointer value will be simply copied
  • U_HMAP_OPTS_DATATYPE_STRING: the null-terminated string value will copied entirely
  • U_HMAP_OPTS_DATATYPE_OPAQUE: the value will be duplicated to the size set with u_hmap_opts_set_val_sz()

Values are not overwritten if a value already exists in the hmap for a given key, unless U_HMAP_OPTS_NO_OVERWRITE is explicitly unset using u_hmap_opts_unset_option().

Parameters:
hmap hmap object
key key to be inserted
val value to be inserted
Return values:
U_HMAP_ERR_NONE on success
U_HMAP_ERR_EXISTS if key already exists
U_HMAP_ERR_FAIL on other failures

Definition at line 353 of file srcs/toolbox/hmap.c.

References u_hmap_o_new(), and u_hmap_put().


←Products
© 2005-2012 - KoanLogic S.r.l. - All rights reserved