Main Page | Data Structures | File List | Data Fields | Globals

hashtable.h File Reference

Hash table. More...


Typedefs

typedef _HashTable HashTable
 A hash table structure.
typedef unsigned long(* HashTableHashFunc )(void *data)
 Hash function used to generate hash values for keys used in a hash table.
typedef int(* HashTableEqualFunc )(void *data1, void *data2)
 Function used to compare two keys for equality.
typedef void(* HashTableFreeFunc )(void *data)
 Type of function used to free keys and values when entries are removed from a hash table.
typedef void(* HashTableIterator )(void *key, void *value, void *user_data)
 Type of function used as a callback when iterating over data.
typedef int(* HashTableRemoveIterator )(void *key, void *value, void *user_data)
 Type of function used as a callback when iterating over a hash table, selectively removing entries.

Functions

HashTablehash_table_new (HashTableHashFunc hash_func, HashTableEqualFunc equal_func)
 Create a new hash table.
void hash_table_free (HashTable *hashtable)
 Destroy a hash table.
void hash_table_register_free_functions (HashTable *hashtable, HashTableFreeFunc key_free_func, HashTableFreeFunc value_free_func)
 Register functions used to free the key and value when an entry is removed from a hash table.
void hash_table_insert (HashTable *hashtable, void *key, void *value)
 Insert a value into a hash table, overwriting any existing entry using the same key.
void * hash_table_lookup (HashTable *hashtable, void *key)
 Look up a value in a hash table by key.
int hash_table_remove (HashTable *hashtable, void *key)
 Remove a value from a hash table.
int hash_table_num_entries (HashTable *hashtable)
 Retrieve the number of entries in a hash table.
void hash_table_foreach (HashTable *hashtable, HashTableIterator iterator, void *user_data)
 Iterate over all key-value pairs in a hash table.
int hash_table_foreach_remove (HashTable *hashtable, HashTableRemoveIterator iterator, void *user_data)
 Iterate over all key-value pairs in a hash table, selectively removing entries.


Detailed Description

Hash table.

A hash table stores a set of values which can be addressed by a key. Given the key, the corresponding value can be looked up quickly.

To create a hash table, use hash_table_new. To destroy a hash table, use hash_table_free.

To insert a value into a hash table, use hash_table_insert.

To remove a value from a hash table, use hash_table_remove.

To look up a value by its key, use hash_table_lookup.


Typedef Documentation

typedef int(* HashTableEqualFunc)(void *data1, void *data2)
 

Function used to compare two keys for equality.

Returns:
Non-zero if the two keys are equal, zero if the keys are not equal.

typedef unsigned long(* HashTableHashFunc)(void *data)
 

Hash function used to generate hash values for keys used in a hash table.

Parameters:
data The value to generate a hash value for.
Returns:
The hash value.

typedef void(* HashTableIterator)(void *key, void *value, void *user_data)
 

Type of function used as a callback when iterating over data.

See hash_table_foreach.

Parameters:
key The key to the current element being iterated over.
value The value of the current element being iterated over.
user_data Extra data passed to the hash_table_foreach function.

typedef int(* HashTableRemoveIterator)(void *key, void *value, void *user_data)
 

Type of function used as a callback when iterating over a hash table, selectively removing entries.

See hash_table_foreach_remove.

Parameters:
key The key to the current element being iterated over.
value The value of the current element being iterated over.
user_data Extra data passed to the hash_table_foreach function.
Returns:
Non-zero (true) if the entry should be removed from the hash table. Zero (false) if the entry should not be removed from the hash table.


Function Documentation

void hash_table_foreach HashTable hashtable,
HashTableIterator  iterator,
void *  user_data
 

Iterate over all key-value pairs in a hash table.

Parameters:
hashtable The hash table.
iterator Callback function to invoke for each element.
user_data Extra data to pass to the iterator function as context.

int hash_table_foreach_remove HashTable hashtable,
HashTableRemoveIterator  iterator,
void *  user_data
 

Iterate over all key-value pairs in a hash table, selectively removing entries.

Parameters:
hashtable The hash table.
iterator Callback function to invoke for each element.
user_data Extra data to pass to the iterator function as context.
Returns:
The total number of entries removed from the hash table.

void hash_table_free HashTable hashtable  ) 
 

Destroy a hash table.

Parameters:
hashtable The hash table to destroy.

void hash_table_insert HashTable hashtable,
void *  key,
void *  value
 

Insert a value into a hash table, overwriting any existing entry using the same key.

Parameters:
hashtable The hash table.
key The key for the new value.
value The value to insert.

void* hash_table_lookup HashTable hashtable,
void *  key
 

Look up a value in a hash table by key.

Parameters:
hashtable The hash table.
key The key of the value to look up.
Returns:
The value, or NULL if there is no value with that key in the hash table.

HashTable* hash_table_new HashTableHashFunc  hash_func,
HashTableEqualFunc  equal_func
 

Create a new hash table.

Parameters:
hash_func Function used to generate hash keys for the keys used in the table.
equal_func Function used to test keys used in the table for equality.
Returns:
A new hash table structure.

int hash_table_num_entries HashTable hashtable  ) 
 

Retrieve the number of entries in a hash table.

Parameters:
hashtable The hash table.
Returns:
The number of entries in the hash table.

void hash_table_register_free_functions HashTable hashtable,
HashTableFreeFunc  key_free_func,
HashTableFreeFunc  value_free_func
 

Register functions used to free the key and value when an entry is removed from a hash table.

Parameters:
hashtable The hash table.
key_free_func Function used to free keys.
value_free_func Function used to free values.

int hash_table_remove HashTable hashtable,
void *  key
 

Remove a value from a hash table.

Parameters:
hashtable The hash table.
key The key of the value to remove.
Returns:
Non-zero if a key was removed, or zero if the specified key was not found in the hash table.


Generated on Mon Jan 30 18:56:23 2006 for C Algorithms by  doxygen 1.4.4