libcstl
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
hash.h File Reference

Go to the source code of this file.

Data Structures

struct  cstl_hash_node
 Node to anchor an element within a hash. More...
 
struct  cstl_hash
 Hash object. More...
 

Macros

#define CSTL_HASH_INITIALIZER(TYPE, MEMB)
 Constant initialization of a hash object.
 
#define DECLARE_CSTL_HASH(NAME, TYPE, MEMB)    struct cstl_hash NAME = CSTL_HASH_INITIALIZER(TYPE, MEMB)
 (Statically) declare and initialize a hash
 

Typedefs

typedef size_t cstl_hash_func_t(size_t k, size_t m)
 Function type for hashing a key into a bucket.
 

Functions

static void cstl_hash_init (struct cstl_hash *const h, const size_t off)
 Initialize a hash object.
 
size_t cstl_hash_size (const struct cstl_hash *const h)
 Get the number of objects in the hash.
 
float cstl_hash_load (const struct cstl_hash *const h)
 Get the average number of nodes per bucket.
 
void cstl_hash_shrink_to_fit (struct cstl_hash *h)
 Free memory associated with excess buckets.
 
void cstl_hash_resize (struct cstl_hash *h, size_t n, cstl_hash_func_t *f)
 Resize the hash table.
 
void cstl_hash_rehash (struct cstl_hash *h)
 Rehash the hash table.
 
void cstl_hash_insert (struct cstl_hash *h, size_t k, void *e)
 Insert an item into the hash.
 
void * cstl_hash_find (struct cstl_hash *h, size_t k, cstl_const_visit_func_t *visit, void *priv)
 Lookup/find a previously inserted object in the hash.
 
void cstl_hash_erase (struct cstl_hash *h, void *e)
 Remove an object from the hash.
 
int cstl_hash_foreach (struct cstl_hash *h, cstl_visit_func_t *visit, void *priv)
 Visit each object within a hash table.
 
int cstl_hash_foreach_const (const struct cstl_hash *h, cstl_const_visit_func_t *visit, void *priv)
 Visit each object within a hash table.
 
void cstl_hash_clear (struct cstl_hash *h, cstl_xtor_func_t *clr)
 Remove all elements from the hash.
 
static void cstl_hash_swap (struct cstl_hash *const a, struct cstl_hash *const b)
 Swap the hash objects at the two given locations.
 
Built-in key hashing functions
size_t cstl_hash_div (size_t k, size_t m)
 Hash by division.
 
size_t cstl_hash_mul (size_t k, size_t m)
 Hash by multiplication.