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

Go to the source code of this file.

Defines

#define ADJUST_HASH(hash, buckets)   ((hash) & ((buckets) - 1))

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
HASH_EntryHASH_find_in_bucket (SRING *abucket, HASH_VALUE hash, HASH_COMPARE_KEY compare_key, void *key, ssize_t key_size)
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 *phash, 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.

Define Documentation

#define ADJUST_HASH (   hash,
  buckets 
)    ((hash) & ((buckets) - 1))

Definition at line 9 of file bhash.c.


Function Documentation

HASH_Entry* HASH_find_in_bucket ( SRING abucket,
HASH_VALUE  hash,
HASH_COMPARE_KEY  compare_key,
void *  key,
ssize_t  key_size 
)

Definition at line 97 of file bhash.c.

{
        SRING   *pos;

        SRING_FOREACH(pos, abucket) {
                HASH_Entry *entry = (HASH_Entry *) pos;
                if (entry->hash == hash) 
                {
                        if (compare_key( entry, key, key_size ) == 0) {
                                return entry;
                        }
                }
        }
        return 0;
}