Simple data structures / objects in plain C Snapshot
Classes | Defines | Typedefs | Functions
bhash.h File Reference
#include <cutils/sring.h>
#include <cutils/hashfunction.h>

Go to the source code of this file.

Classes

struct  HASH_Entry
struct  HASH

Defines

#define HASH_BUCKET_FOREACH(cur, bucket)
#define HASH_FOREACH_KEY(cur, hash, key, key_size)
 Macro: iterate over all elements that match a given key (multimap)
#define HASH_DELETEALL_KEY(cur, hash, key, key_size)
 Macro: unlink al entries that match a given key (for multimap); the user has to free the memory in loop code.
#define HASH_DELETEALL_KEY_END
#define HASH_FOREACH(cur, hash)
 Macro: iterate over all elements in hash table.
#define HASH_FOREACH_END
 Macro: close block opened by HASH_FOREACH.
#define HASH_DELETEALL(cur, hash)
 Macro: iterate over all elements in hash table and delete them from the table; allow the user to free the memory of each element.
#define HASH_DELETEALL_END
 Macro: close block opened by HASH_DELETEALL.

Typedefs

typedef HASH_VALUE(* HASH_FUNCTION )(void *data, ssize_t length)
typedef int(* HASH_COMPARE_KEY )(HASH_Entry *, void *key, ssize_t key_size)
typedef int(* HASH_VISITOR )(HASH_Entry *, void *context)

Functions

int HASH_init (HASH *hash, size_t buckets, int ismultimap, HASH_COMPARE_KEY compare_key, HASH_FUNCTION hash_func)
 Object constructor; initialise the hash that allows one entry for a given key.
int HASH_resize (HASH *hash, size_t buckets)
 resize the hash table
M_INLINE void HASH_free (HASH *hash)
 Object destructor; frees a hash table.
M_INLINE size_t HASH_size (HASH *hash)
 returns number of elements in hash table
HASH_EntryHASH_find (HASH *phash, void *key, ssize_t key_size)
 find entry with given key in hash table; for multimaps this will return the first occurence of the key.
HASH_EntryHASH_find_next (HASH *phash, HASH_Entry *prev, void *key, ssize_t key_size)
 for multimaps - find next occurence of key
int HASH_insert (HASH *phash, HASH_Entry *entry, void *key, ssize_t key_size)
 insert new entry in hash table
HASH_EntryHASH_unlink (HASH *hash, void *key, ssize_t key_size)
 find first hash table entry and unlink it from its bucket. The caller of this function has to free memory held by hash table entry.
M_INLINE void HASH_foreach_key (HASH *hash, void *key, ssize_t key_size, HASH_VISITOR eval_func, void *context)
 iterate over all entries of the hash table that match a given key and invoke callback with those elements.
M_INLINE void HASH_foreach (HASH *hash, HASH_VISITOR eval_func, void *context)
 iterate over all entries of the hash table and invoke callback with each element. Equivalent of Lisp foldl,mapcar and friends.
M_INLINE HASH_EntryHASH_findif (HASH *hash, HASH_VISITOR eval_func, void *context, int *retval)
 find an element within the hash. callback is invoked for each element of the list, when the callback returns non zero value the iteration stops as we have found what we searched for.
M_INLINE void HASH_deleteall (HASH *hash, int offset_of_link, HASH_VISITOR on_delete, void *context)
 iterate over all entries of the hash table and delete them.
M_INLINE int HASH_check (HASH *hash)
 check consistency of bucket hash structure.