Main Page | Modules | Data Structures | Directories | File List | Data Fields

Map


Defines

#define U_HMAP_MAX_SIZE   512
#define U_HMAP_MAX_ELEMS   U_HMAP_MAX_SIZE
#define U_HMAP_RATE_FULL   0.75
#define U_HMAP_RATE_RESIZE   3

Typedefs

typedef u_hmap_q_h_s u_hmap_q_h_t
typedef u_hmap_e_s u_hmap_e_t

Functions

const char * u_hmap_strerror (u_hmap_ret_t rc)
 Get a string representation of an error code.
int u_hmap_new (u_hmap_opts_t *opts, u_hmap_t **hmap)
 Create a new hmap.
int u_hmap_copy (u_hmap_t *to, u_hmap_t *from)
 Copy hmap.
void u_hmap_dbg (u_hmap_t *hmap)
 Debug Hmap.
int u_hmap_del (u_hmap_t *hmap, void *key, u_hmap_o_t **obj)
void u_hmap_pcy_dbg (u_hmap_t *hmap)
 Debug policy.
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, void *key, u_hmap_o_t **obj)
 Retrieve an object from the hmap.
int u_hmap_foreach (u_hmap_t *hmap, int f(void *val))
 Perform an operation on all objects.
int u_hmap_foreach_keyval (u_hmap_t *hmap, int f(void *key, void *val))
 Perform an operation on all objects.
void u_hmap_free (u_hmap_t *hmap)
 Deallocate hmap.
int u_hmap_opts_new (u_hmap_opts_t **opts)
 Create new hmap options.
int u_hmap_opts_copy (u_hmap_opts_t *to, u_hmap_opts_t *from)
 Copy options.
void u_hmap_opts_init (u_hmap_opts_t *opts)
 Initialise hmap options.
void u_hmap_opts_free (u_hmap_opts_t *opts)
 Deallocate hmap options.
void u_hmap_opts_dbg (u_hmap_opts_t *opts)
 Debug options.
u_hmap_o_tu_hmap_o_new (void *key, void *val)
 Create a data object.
void u_hmap_o_free (u_hmap_o_t *obj)
 Free a data object.

Function Documentation

int u_hmap_copy u_hmap_t *  to,
u_hmap_t *  from
 

Perform a copy of an hmap from to to by rehashing all elements and copying the object pointers to the new locations.

Parameters:
to destination hmap
from source hmap
Returns:
U_HMAP_ERR_NONE on success, U_HMAP_ERR_FAIL on failure

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

References u_hmap_put().

void u_hmap_dbg u_hmap_t *  hmap  ) 
 

Print out information on an hmap.

Parameters:
hmap hmap object

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

References u_string_append(), u_string_c(), u_string_clear(), u_string_create(), u_string_free(), and u_string_len().

int u_hmap_foreach u_hmap_t *  hmap,
int   f(void *val)
 

Execute function f on all objects within hmap. These functions should return U_HMAP_ERR_NONE on success, and take an object as a parameter.

Parameters:
hmap hmap object
f function
Returns:
U_HMAP_ERR_NONE on success, U_HMAP_ERR_FAIL on failure

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

int u_hmap_foreach_keyval u_hmap_t *  hmap,
int   f(void *key, void *val)
 

Execute function f on all objects within hmap. These functions should return U_HMAP_ERR_NONE on success, and take an object as a parameter.

Parameters:
hmap hmap object
f function, must accept key and val params
Returns:
U_HMAP_ERR_NONE on success, U_HMAP_ERR_FAIL on failure

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

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 904 of file srcs/toolbox/hmap.c.

References u_free().

int u_hmap_get u_hmap_t *  hmap,
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
Returns:
U_HMAP_ERR_NONE on success, U_HMAP_ERR_FAIL on failure

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

References u_hmap_o_s::pqe.

int u_hmap_new u_hmap_opts_t opts,
u_hmap_t **  hmap
 

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
hmap on success contains the hmap options object
Returns:
U_HMAP_ERR_NONE on success, U_HMAP_ERR_FAIL on failure

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

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

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 1093 of file srcs/toolbox/hmap.c.

References u_free().

u_hmap_o_t* u_hmap_o_new void *  key,
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:
key pointer to the key
val pointer to the oject
Returns:
pointer to a new u_hmap_o_t

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

References u_hmap_o_s::key, u_hmap_o_s::pqe, u_free(), u_zalloc(), and u_hmap_o_s::val.

int u_hmap_opts_copy u_hmap_opts_t to,
u_hmap_opts_t from
 

Perform a deep copy of options object from to to.

Parameters:
to destination options
from source options
Returns:
U_HMAP_ERR_NONE on success, U_HMAP_ERR_FAIL on failure

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

Referenced by u_hmap_new().

void u_hmap_opts_dbg u_hmap_opts_t opts  ) 
 

Print out information on option settings.

Parameters:
opts options object

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

References u_hmap_opts_s::f_free, u_hmap_opts_s::max, u_hmap_opts_s::options, u_hmap_opts_s::policy, and u_hmap_opts_s::size.

Referenced by u_hmap_new().

void u_hmap_opts_free u_hmap_opts_t opts  ) 
 

Deallocate hmap options object opts.

Parameters:
opts hmap options

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

References u_free().

void u_hmap_opts_init u_hmap_opts_t opts  ) 
 

Set allocated hmap options to default values

Parameters:
opts hmap options object

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

References u_hmap_opts_s::f_comp, u_hmap_opts_s::f_free, u_hmap_opts_s::f_hash, u_hmap_opts_s::f_str, u_hmap_opts_s::max, u_hmap_opts_s::options, u_hmap_opts_s::policy, u_hmap_opts_s::size, u_hmap_opts_s::type, U_HMAP_MAX_ELEMS, and U_HMAP_MAX_SIZE.

Referenced by u_hmap_opts_new().

int u_hmap_opts_new u_hmap_opts_t **  opts  ) 
 

Create a new hmap options object and save its pointer to *opts. The fields within the object can be manipulated publicly according to the description in the header file.

Parameters:
opts on success contains the hmap options object
Returns:
U_HMAP_ERR_NONE on success, U_HMAP_ERR_FAIL on failure

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

References u_hmap_opts_init(), and u_zalloc().

Referenced by u_hmap_new().

void u_hmap_pcy_dbg u_hmap_t *  hmap  ) 
 

Print out policy information.

Parameters:
hmap hmap object

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

References u_string_append(), u_string_c(), u_string_clear(), u_string_create(), and u_string_free().

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, the old value is returned (only if data is owned by user).

Parameters:
hmap hmap object
obj key to be inserted
old returned old value
Returns:
U_HMAP_ERR_NONE on success, U_HMAP_ERR_FAIL on failure

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

References u_hmap_o_s::key, u_hmap_o_s::pqe, and u_snprintf().

Referenced by u_hmap_copy().

const char* u_hmap_strerror u_hmap_ret_t  rc  ) 
 

Get a string representation of an error code

Parameters:
rc return code

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


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