Previous: Array, Up: Data structures [Contents][Index]
A hashtable associates keys of arbitrary size and content with values. This data structure is also called associative array sometimes because you use keys in order to access values instead of numbers. You cannot store two values associated with the same key. The values can have any simple C types like integers or pointers.
Create a new hash table with an initial capacity size. Return a
non-zero pointer to the newly created hash. The size is calculated down
to a binary value. The destroy callback specifies an
element destruction callback for use by svz_hash_clear
and
svz_hash_destroy
for each value. If no such operation should be
performed the argument must be NULL
.
Set the internal keylen, code and and equals functions for hash table hash. Return hash.
keylen takes const char *data
and returns size_t
,
the number of bytes in data representing the key.
code takes const char *data
and returns unsigned long
.
equals takes const char *data1, const char *data2
and returns int
, which should be non-zero if equal.
As a special case, a NULL
value means don’t set that function,
leaving it to its default value.
Destroy the existing hash table hash, svz_free
ing
all keys within the hash, the hash table and the hash itself.
If a non-NULL
element destruction callback was specified to
svz_hash_create
, that function is called on each value.
Delete an existing entry accessed via a key from the
hash table hash. Return NULL
if there is no
such key, otherwise the previous value.
Add a new element consisting of key and value to hash. When key already exists, replace and return the old value. Note: This is sometimes the source of memory leaks.
Return the value associated with key in the hash table
hash, or NULL
if there is no such key.
Iterate func over each key/value pair in hash.
func is called with three void *
args: the key,
the value and the opaque (to svz_hash_foreach
) closure.
Return the number of keys in the hash table hash.
If hash is NULL
, return zero.
Return the key associated with value in the hash table
hash, or NULL
if there is no such value.
Return non-zero if key
is stored within
the hash table hash
, otherwise zero.
This function is useful when you cannot tell whether the return
value of svz_hash_get
(== NULL
) indicates a real
value in the hash or a non-existing hash key.
Previous: Array, Up: Data structures [Contents][Index]