cucon/hmap.h: General-Purpose Hash Map
[Associative Containers (trees, maps, sets)]

Data Structures

struct  cucon_hmap_node
struct  cucon_hmap

Typedefs

typedef struct cucon_hmap_nodecucon_hmap_node_t

Functions

void cucon_hmap_init (cucon_hmap_t map, cu_clop(eq, cu_bool_t, void const *, void const *), cu_clop(hash, cu_hash_t, void const *))
cucon_hmap_t cucon_hmap_new (cu_clop(eq, cu_bool_t, void const *, void const *), cu_clop(hash, cu_hash_t, void const *))
void cucon_hmap_clear (cucon_hmap_t)
size_t cucon_hmap_card (cucon_hmap_t map)
cu_bool_t cucon_hmap_is_empty (cucon_hmap_t map)
void * cucon_hmap_find_mem (cucon_hmap_t map, void const *key)
void * cucon_hmap_find_ptr (cucon_hmap_t map, void const *key)
cu_bool_t cucon_hmap_insert_mem (cucon_hmap_t map, void const *key, size_t slot_size, cu_ptr_ptr_t slot)
void * cucon_hmap_pop_mem (cucon_hmap_t map, void const *key)
void * cucon_hmap_pop_ptr (cucon_hmap_t map, void const *key)
cu_bool_t cucon_hmap_erase (cucon_hmap_t map, void const *key)
void * cucon_hmap_isocap_pop_mem (cucon_hmap_t map, void const *key)
void * cucon_hmap_isocap_pop_ptr (cucon_hmap_t map, void const *key)
cu_bool_t cucon_hmap_isocap_erase (cucon_hmap_t map, void const *key)
void cucon_hmap_set_capacity (cucon_hmap_t map, size_t cap)
cu_bool_t cucon_hmap_conj_keys (cucon_hmap_t map, cu_clop(f, cu_bool_t, void const *))
cu_bool_t cucon_hmap_conj_mem (cucon_hmap_t map, cu_clop(f, cu_bool_t, void const *, void *))

Detailed Description

Defined here is a hash map where the keys are pointers with associated client-provided equality and hash functions. The values are arbitrary sized slots, but shortcuts for pointer-valued maps are provided.

See also:
cucon/hset.h: General-Purpose Hash Set
cucon/pmap.h: Pointer-Keyed Hash Map

Function Documentation

size_t cucon_hmap_card ( cucon_hmap_t  map  ) 

The number of elements of map.

void cucon_hmap_clear ( cucon_hmap_t   ) 

Erase all entries in hash.

cu_bool_t cucon_hmap_erase ( cucon_hmap_t  map,
void const *  key 
)

Delete the mapping of key from map if it exists and return true, otherwise return false.

void* cucon_hmap_find_mem ( cucon_hmap_t  map,
void const *  key 
)

If an object equal to key is in map, return its value slot, else return NULL.

void* cucon_hmap_find_ptr ( cucon_hmap_t  map,
void const *  key 
)

If an object equal to key is in map, assume it maps to a slot containing a pointer, and return the pointer, otherwise return NULL.

void cucon_hmap_init ( cucon_hmap_t  map,
cu_clop(eq, cu_bool_t, void const *, void const *)  ,
cu_clop(hash, cu_hash_t, void const *)   
)

Initialise map as a hash set over objects with equality eq and hash function hash.

cu_bool_t cucon_hmap_insert_mem ( cucon_hmap_t  map,
void const *  key,
size_t  slot_size,
cu_ptr_ptr_t  slot 
)

If key is in map, return false and set *slot to its value slot, else return true and associate key with slot_size bytes of value slot assigned to *slot.

cu_bool_t cucon_hmap_is_empty ( cucon_hmap_t  map  ) 

True iff map is empty.

cu_bool_t cucon_hmap_isocap_erase ( cucon_hmap_t  map,
void const *  key 
)

Same as cucon_hmap_erase, except that the capacity is kept constant. Use in conjunction with cucon_hmap_set_capacity as an optimisation.

void* cucon_hmap_isocap_pop_mem ( cucon_hmap_t  map,
void const *  key 
)

Same as cucon_hmap_pop_mem, except that the capacity is kept constant. Use in conjunction with cucon_hmap_set_capacity as an optimisation.

void* cucon_hmap_isocap_pop_ptr ( cucon_hmap_t  map,
void const *  key 
)

Same as cucon_hmap_pop_ptr, except that the capacity is kept constant. Use in conjunction with cucon_hmap_set_capacity as an optimisation.

cucon_hmap_t cucon_hmap_new ( cu_clop(eq, cu_bool_t, void const *, void const *)  ,
cu_clop(hash, cu_hash_t, void const *)   
)

Return a hash set over objects with equality defined by eq and hash function hash.

void* cucon_hmap_pop_mem ( cucon_hmap_t  map,
void const *  key 
)

If key has a mapping in map, return the slot and erase it, otherwise return NULL.

void* cucon_hmap_pop_ptr ( cucon_hmap_t  map,
void const *  key 
)

If key has a mapping in map, return the single pointer which is assumed to be stored in the slot and delete the mapping, otherwise return NULL.

void cucon_hmap_set_capacity ( cucon_hmap_t  map,
size_t  cap 
)

Set the capacity of map to cap, which must be a power of 2. This is used either as a preparation for subsequent insertions or as a final step after a series of calls to the "isocap" functions. It is merely an optimisation to avoid unnecessary intermediate adjustments of the capacity when the final cardinality is known.

Generated 2009-11-23 for culibs-0.25 using Doxygen. Maintained by Petter Urkedal.