hmap: Advanced Interface
[HMap]

Functions

int u_hmap_new (u_hmap_opts_t *opts, u_hmap_t **phmap)
 Create a new hmap.
void u_hmap_clear (u_hmap_t *hmap)
 Clear hmap.
void u_hmap_free (u_hmap_t *hmap)
 Deallocate hmap.
int u_hmap_put (u_hmap_t *hmap, u_hmap_o_t *obj, u_hmap_o_t **old)
 Insert an object into the hmap.
int u_hmap_get (u_hmap_t *hmap, const void *key, u_hmap_o_t **obj)
 Retrieve an object from the hmap.
int u_hmap_del (u_hmap_t *hmap, const void *key, u_hmap_o_t **obj)
 Delete an object from the hmap.
u_hmap_o_t * u_hmap_o_new (u_hmap_t *hmap, const void *key, const void *val)
 Create a data object (unused for hmap_easy interface).
void u_hmap_o_free (u_hmap_o_t *obj)
 Free a data object (unused for hmap_easy interface).
void * u_hmap_o_get_key (u_hmap_o_t *obj)
 Access the key of the hmap element pointed to by obj.
void * u_hmap_o_get_val (u_hmap_o_t *obj)
 Access the value of the hmap element pointed to by obj.
ssize_t u_hmap_count (u_hmap_t *hmap)
 Count the number of elements currently stored in hmap.

Function Documentation

void u_hmap_clear ( u_hmap_t *  hmap  ) 

Clears all hmap elements. Objects are freed via free() by default or using the custom deallocation function passed in the hmap options.

Parameters:
hmap hmap object

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

Referenced by u_hmap_easy_clear(), and u_hmap_free().

ssize_t u_hmap_count ( u_hmap_t *  hmap  ) 

Count the number of elements currently stored in the supplied hmap object

Parameters:
hmap hmap object
Returns:
The number of elements currently stored in hmap, or -1 on error

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

int u_hmap_del ( u_hmap_t *  hmap,
const void *  key,
u_hmap_o_t **  obj 
)

Delete object with given key from hmap and return it (if the object is owned by user).

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

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

References U_HMAP_OPTS_OWNSDATA.

Referenced by u_hmap_easy_del().

void u_hmap_free ( u_hmap_t *  hmap  ) 

Deallocate hmap along with all hmapd objects (unless U_HMAP_OPTS_OWNSDATA is set). Objects are freed via free() by default or using the custom deallocation function passed in the hmap options.

Parameters:
hmap hmap object

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

References u_free(), u_hmap_clear(), and u_hmap_opts_free().

Referenced by u_hmap_easy_free().

int u_hmap_get ( u_hmap_t *  hmap,
const void *  key,
u_hmap_o_t **  obj 
)

Retrieve object with given key from hmap. On success the requested object is returned in obj. The object is not removed from the hmap, so ownership of the object is not returned to the user.

Parameters:
hmap hmap object
key key to be retrieved
obj returned object
Return values:
U_HMAP_ERR_NONE on success
U_HMAP_ERR_FAIL on failure

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

Referenced by u_hmap_easy_get().

int u_hmap_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 (may be NULL)
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 551 of file srcs/toolbox/hmap.c.

References u_free(), u_hmap_opts_copy(), U_HMAP_OPTS_DATATYPE_STRING, u_hmap_opts_dbg(), u_hmap_opts_new(), and u_zalloc().

Referenced by u_hmap_easy_new().

void u_hmap_o_free ( u_hmap_o_t *  obj  ) 

Frees a data object (without freeing its content). This function should only be used if U_HMAP_OPTS_OWNSDATA is not set to free objects allocated with u_hmap_o_new(). If U_HMAP_OPTS_OWNSDATA is set, the data is freed automatically by the hashmap by using the default free function or the overridden f_free().

Parameters:
obj hmap object

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

References u_free().

Referenced by u_hmap_o_new().

u_hmap_o_t* u_hmap_o_new ( u_hmap_t *  hmap,
const void *  key,
const void *  val 
)

Creates a new (key, value) tuple to be inserted into a hmap. By default, the user is responsible for allocation and deallocation of these objects and their content. If the option U_HMAP_OPTS_OWNSDATA is set

Parameters:
hmap reference to parent hmap
key pointer to the key
val pointer to the oject
Returns:
pointer to a new u_hmap_o_t

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

References u_hmap_o_free(), U_HMAP_OPTS_DATATYPE_OPAQUE, U_HMAP_OPTS_DATATYPE_POINTER, U_HMAP_OPTS_DATATYPE_STRING, U_HMAP_OPTS_OWNSDATA, u_strdup(), and u_zalloc().

Referenced by u_hmap_easy_put().

int u_hmap_put ( u_hmap_t *  hmap,
u_hmap_o_t *  obj,
u_hmap_o_t **  old 
)

Insert a (key, val) pair obj into hmap. Such object should be created with u_hmap_o_new(). The user is responsible for allocation of keys and values unless U_HMAP_OPTS_OWNSDATA is set. If a value is overwritten (U_HMAP_OPTS_NO_OVERWRITE must be unset via u_hmap_opts_unset_option()) and data is owned by the user, the old value is returned.

Parameters:
hmap hmap object
obj key to be inserted
old returned old value
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 673 of file srcs/toolbox/hmap.c.

References U_HMAP_OPTS_HASH_STRONG, U_HMAP_PCY_NONE, U_HMAP_TYPE_CHAIN, U_HMAP_TYPE_LINEAR, and u_snprintf().

Referenced by u_hmap_copy(), and u_hmap_easy_put().


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