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

Hash tables


Detailed Description

Hash tables are a basic data structure used in building databases. Hash tables provide a means of storing data such that an arbitrary entry may be looked up efficiently. This library implements a hash table that may optionally grow and shrink to provide maximum efficiency. The implementation is with two kinds of caller-allocated structures--a hash_table_t structure that describes the table and a hash_entry_t structure for each entry in the table. The library allocates a bucket array which must be released with the ht_free() function when the hash table has been emptied. Additionally, the hash table may be manually resized with the ht_resize() function.

Entries may be added to and removed from the table using the ht_add() and ht_remove() functions. Additionally, the key on a given entry may be changed using the ht_move() function. Of course, any given entry may be looked up using the ht_find() function, and ht_iter() will execute a user-defined function for each entry in the hash table (in an unspecified order). The ht_flush() function will remove all entries from the hash table, optionally executing a user-specified clean-up function.


Data Structures

struct  _hash_table_s
 Hash table structure. More...
struct  _hash_entry_s
 Hash table entry structure. More...

Defines

#define MAX_PRIME
 Largest prime.
#define HASH_TABLE_MAGIC
 Hash table magic number.
#define HASH_FLAG_AUTOGROW
 Flag permitting a hash table to automatically grow.
#define HASH_FLAG_AUTOSHRINK
 Flag permitting a hash table to automatically shrink.
#define HASH_FLAG_MASK
 Hash table flags that may be set by the user.
#define HASH_TABLE_INIT(flags, func, comp, resize, extra)
 Hash table static initializer.
#define ht_verify(table)
 Hash table verification macro.
#define ht_flags(table)
 Hash table flags.
#define ht_frozen(table)
 Determine if a hash table is frozen.
#define ht_modulus(table)
 Hash table modulus.
#define ht_count(table)
 Hash table count.
#define ht_func(table)
 Hash table hash function.
#define ht_comp(table)
 Hash table comparison function.
#define ht_rsize(table)
 Hash table resize callback function.
#define ht_extra(table)
 Extra pointer data in a hash table.
#define ht_size(table)
 Hash table memory size.
#define HASH_ENTRY_MAGIC
 Hash table entry magic number.
#define HASH_ENTRY_INIT(value)
 Hash table entry static initializer.
#define he_verify(entry)
 Hash table entry verification macro.
#define he_link(entry)
 Hash table entry linked list element.
#define he_flags(entry)
 Hash table entry flags.
#define he_table(entry)
 Hash table entry table pointer.
#define he_hash(entry)
 Hash table entry hash value.
#define he_key(entry)
 Hash table entry key pointer.
#define he_value(entry)
 Hash table entry value pointer.
#define st_rsize(table)
 Sparse matrix table resize callback function.
#define _hash_rollover(mod)
 Select hash table roll over size.
#define _hash_rollunder(mod)
 Select hash table roll under size.
#define _hash_fuzz(mod)
 Fuzz the initial hash table size.
#define HASH_FNV_OFFSET
 FNV offset basis parameter.
#define HASH_FNV_PRIME
 FNV prime parameter.

Typedefs

typedef _hash_table_s hash_table_t
 Hash table.
typedef _hash_entry_s hash_entry_t
 Hash table entry.
typedef unsigned long(* hash_iter_t )(hash_table_t *table, hash_entry_t *ent, void *extra)
 Hash table iteration callback.
typedef unsigned long(* hash_func_t )(hash_table_t *table, db_key_t *key)
 Hash function callback.
typedef unsigned long(* hash_comp_t )(hash_table_t *table, db_key_t *key1, db_key_t *key2)
 Hash table comparison callback.
typedef unsigned long(* hash_resize_t )(hash_table_t *table, unsigned long new_mod)
 Hash table resize callback.

Functions

unsigned long hash_fnv1 (hash_table_t *table, db_key_t *key)
 FNV-1 hash function.
unsigned long hash_fnv1a (hash_table_t *table, db_key_t *key)
 FNV-1a hash function.
unsigned long hash_comp (hash_table_t *table, db_key_t *key1, db_key_t *key2)
 Hash comparison function.
unsigned long ht_init (hash_table_t *table, unsigned long flags, hash_func_t func, hash_comp_t comp, hash_resize_t resize, void *extra, unsigned long init_mod)
 Dynamically initialize a hash table.
unsigned long ht_add (hash_table_t *table, hash_entry_t *entry, db_key_t *key)
 Add an entry to a hash table.
unsigned long ht_move (hash_table_t *table, hash_entry_t *entry, db_key_t *key)
 Move an entry in the hash table.
unsigned long ht_remove (hash_table_t *table, hash_entry_t *entry)
 Remove an element from a hash table.
unsigned long ht_find (hash_table_t *table, hash_entry_t **entry_p, db_key_t *key)
 Find an entry in a hash table.
unsigned long ht_iter (hash_table_t *table, hash_iter_t iter_func, void *extra)
 Iterate over each entry in a hash table.
unsigned long ht_flush (hash_table_t *table, hash_iter_t flush_func, void *extra)
 Flush a hash table.
unsigned long ht_resize (hash_table_t *table, unsigned long new_size)
 Resize a hash table.
unsigned long ht_free (hash_table_t *table)
 Free memory used by an empty hash table.
unsigned long he_init (hash_entry_t *entry, void *value)
 Dynamically initialize a hash table entry.
unsigned long _hash_prime (unsigned long start)
 Select a prime number.

Variables

static unsigned long primes []
 Table of primes.


Define Documentation

#define _hash_fuzz mod   ) 
 

For internal use only.

This macro is used to apply a fudge factor to a user-supplied size for the hash table, causing a slightly larger bucket to be allocated.

Parameters:
[in] mod The requested table modulus.
Returns:
The "fuzzed" size.

Definition at line 107 of file dbprim_int.h.

Referenced by ht_add(), and ht_resize().

#define _hash_rollover mod   ) 
 

For internal use only.

This macro is used to compute the "roll over" size--the size at which the hash table will be grown (assuming that the table has HASH_FLAG_AUTOGROW set).

Parameters:
[in] mod The table modulus.
Returns:
The "roll over" size.

Definition at line 79 of file dbprim_int.h.

Referenced by ht_init(), and ht_resize().

#define _hash_rollunder mod   ) 
 

For internal use only.

This macro is used to compute the "roll under" size--the size at which the hash table will be shrunk (assuming that the table has HASH_FLAG_AUTOSHRINK set).

Parameters:
[in] mod The table modulus.
Returns:
The "roll under" size.

Definition at line 93 of file dbprim_int.h.

Referenced by ht_init(), and ht_resize().

#define HASH_ENTRY_INIT value   ) 
 

This macro statically initializes a hash_entry_t.

Parameters:
[in] value A pointer to void representing the object associated with the entry.

Definition at line 1512 of file dbprim.h.

#define HASH_ENTRY_MAGIC
 

For internal use only.

This is the magic number used for the hash table entry structure.

Definition at line 1502 of file dbprim.h.

Referenced by he_init().

#define HASH_FLAG_AUTOGROW
 

If passed in to HASH_TABLE_INIT() or ht_init(), allows the hash table to grow automatically.

Definition at line 1100 of file dbprim.h.

Referenced by ht_add(), and ht_init().

#define HASH_FLAG_AUTOSHRINK
 

If passed in to HASH_TABLE_INIT() or ht_init(), allows the hash table to shrink automatically.

Definition at line 1108 of file dbprim.h.

Referenced by ht_flush(), ht_init(), and ht_remove().

#define HASH_FLAG_MASK
 

This flag mask may be used to obtain flags that the hash table user may set on a hash table.

Definition at line 1116 of file dbprim.h.

#define HASH_FNV_OFFSET
 

For internal use only.

This is the 32-bit offset basis for the FNV hash algorithm. See http://www.isthe.com/chongo/tech/comp/fnv/ for more information about the FNV hash algorithm.

Definition at line 117 of file dbprim_int.h.

Referenced by hash_fnv1(), and hash_fnv1a().

#define HASH_FNV_PRIME
 

For internal use only.

This is the 32-bit multiplication prime for the FNV hash algorithm. See http://www.isthe.com/chongo/tech/comp/fnv/ for more information about the FNV hash algorithm.

Definition at line 127 of file dbprim_int.h.

Referenced by hash_fnv1(), and hash_fnv1a().

#define HASH_TABLE_INIT flags,
func,
comp,
resize,
extra   ) 
 

This macro statically initializes a hash_table_t.

Parameters:
[in] flags A bit-wise OR of HASH_FLAG_AUTOGROW and HASH_FLAG_AUTOSHRINK. If neither behavior is desired, use 0.
[in] func A hash_func_t function pointer for a hash function.
[in] comp A hash_comp_t function pointer for a comparison function.
[in] resize A hash_resize_t function pointer for determining whether resizing is permitted and/or for notification of the resize.
[in] extra Extra pointer data that should be associated with the hash table.

Definition at line 1145 of file dbprim.h.

#define HASH_TABLE_MAGIC
 

For internal use only.

This is the magic number used for the hash table structure.

Definition at line 1092 of file dbprim.h.

Referenced by ht_init().

#define he_flags entry   ) 
 

This macro retrieves a set of user-defined flags associated with the entry. It may be used as an lvalue to set those flags.

Parameters:
[in] entry A pointer to a hash_entry_t.
Returns:
An unsigned long containing the flags associated with the entry.

Definition at line 1556 of file dbprim.h.

#define he_hash entry   ) 
 

This macro retrieves the hash value of the given hash entry. If the hash table has been resized, this value may not be the same as a previous value.

Parameters:
[in] entry A pointer to a hash_entry_t.
Returns:
An unsigned long containing the hash code for the entry.

Definition at line 1581 of file dbprim.h.

#define he_key entry   ) 
 

This macro retrieves the key associated with the hash table entry.

Parameters:
[in] entry A pointer to a hash_entry_t.
Returns:
A pointer to a db_key_t.

Definition at line 1592 of file dbprim.h.

Referenced by ht_find().

#define he_link entry   ) 
 

This macro provides access to the linked list element buried in the hash table entry. It should *not* be used on entries currently in a hash table. The purpose of this macro is to allow an object containing a hash table entry to be placed upon a free list.

Parameters:
[in] entry A pointer to a hash_entry_t.
Returns:
A pointer to a link_elem_t.

Definition at line 1543 of file dbprim.h.

#define he_table entry   ) 
 

This macro retrieves a pointer to the hash table the entry is in.

Parameters:
[in] entry A pointer to a hash_entry_t.
Returns:
A pointer to a hash_table_t.

Definition at line 1567 of file dbprim.h.

#define he_value entry   ) 
 

This macro retrieves the value associated with the hash table entry. It may be treated as an lvalue to change that value. Care should be taken when using this option.

Parameters:
[in] entry A pointer to a hash_entry_t.
Returns:
A pointer to void representing the value associated with this entry.

Definition at line 1606 of file dbprim.h.

Referenced by _st_flush_iter(), _st_iter_iter(), and st_find().

#define he_verify entry   ) 
 

This macro verifies that a given pointer actually does point to a hash table entry.

Warning:
This macro evaluates the entry argument twice.
Parameters:
[in] entry A pointer to a hash_entry_t.
Returns:
Boolean true if entry is a valid hash table entry or false otherwise.

Definition at line 1528 of file dbprim.h.

Referenced by ht_add(), ht_move(), and ht_remove().

#define ht_comp table   ) 
 

This macro retrieves the comparison function pointer.

Parameters:
[in] table A pointer to a hash_table_t.
Returns:
A hash_comp_t.

Definition at line 1243 of file dbprim.h.

#define ht_count table   ) 
 

This macro retrieves the total number of items actually in the hash table.

Parameters:
[in] table A pointer to a hash_table_t.
Returns:
An unsigned long containing a count of the number of items in the hash table.

Definition at line 1221 of file dbprim.h.

#define ht_extra table   ) 
 

This macro retrieves the extra pointer data associated with a particular hash table.

Parameters:
[in] table A pointer to a hash_table_t.
Returns:
A pointer to void.

Definition at line 1266 of file dbprim.h.

Referenced by _smat_resize().

#define ht_flags table   ) 
 

This macro retrieves the flags associated with the hash table. Only HASH_FLAG_AUTOGROW and HASH_FLAG_AUTOSHRINK have any meaning to the application; all other bits are reserved for use in the library. This macro may be used as an lvalue, but care must be taken to avoid modifying the library-specific bits.

Parameters:
[in] table A pointer to a hash_table_t.
Returns:
An unsigned long containing the flags for the hash table.

Definition at line 1179 of file dbprim.h.

#define ht_frozen table   ) 
 

This macro returns a non-zero value if the table is currently frozen. The hash table may be frozen if there is an iteration in progress.

Parameters:
[in] table A pointer to a hash_table_t.
Returns:
A zero value if the table is not frozen or a non-zero value if the table is frozen.

Definition at line 1193 of file dbprim.h.

#define ht_func table   ) 
 

This macro retrieves the hash function pointer.

Parameters:
[in] table A pointer to a hash_table_t.
Returns:
A hash_func_t.

Definition at line 1232 of file dbprim.h.

#define ht_modulus table   ) 
 

This macro retrieves the number of buckets allocated for the hash table. An application may wish to save this value between invocations to avoid the overhead of growing the table while filling it with data.

Parameters:
[in] table A pointer to a hash_table_t.
Returns:
An unsigned long containing the number of buckets allocated for the hash table.

Definition at line 1208 of file dbprim.h.

Referenced by ht_flush(), ht_init(), ht_iter(), and ht_resize().

#define ht_rsize table   ) 
 

This macro retrieves the resize callback function pointer.

Parameters:
[in] table A pointer to a hash_table_t.
Returns:
A hash_resize_t.

Definition at line 1254 of file dbprim.h.

#define ht_size table   ) 
 

This macro returns the physical size of the bucket array allocated by the library for this hash table.

Parameters:
[in] table A pointer to a hash_table_t.
Returns:
A size_t.

Definition at line 1278 of file dbprim.h.

#define ht_verify table   ) 
 

This macro verifies that a given pointer actually does point to a hash table.

Warning:
This macro evaluates the table argument twice.
Parameters:
[in] table A pointer to a hash_table_t.
Returns:
Boolean true if table is a valid hash table or false otherwise.

Definition at line 1162 of file dbprim.h.

Referenced by ht_add(), ht_find(), ht_flush(), ht_free(), ht_iter(), ht_move(), ht_remove(), and ht_resize().

#define MAX_PRIME
 

For internal use only.

This is the largest prime number that can be handled by the _hash_prime() function.

Definition at line 41 of file _hash_prime.c.

Referenced by _hash_prime().

#define st_rsize table   ) 
 

This macro retrieves the resize callback function pointer.

Parameters:
[in] table A pointer to a smat_table_t.
Returns:
A smat_resize_t.

Definition at line 1763 of file dbprim.h.


Typedef Documentation

typedef unsigned long(* hash_comp_t)(hash_table_t *table, db_key_t *key1, db_key_t *key2)
 

This function pointer references a callback used to compare entries in a hash table. It should return 0 for identical entries and non-zero otherwise. No assumptions should be made about the order in which the two keys are passed to this function.

Parameters:
[in] table A pointer to a hash_table_t.
[in] key1 The first key being compared.
[in] key2 The second key being compared.
Returns:
Zero if the keys match, non-zero otherwise.

Definition at line 408 of file dbprim.h.

typedef struct _hash_entry_s hash_entry_t
 

This structure represents a single entry of a hash table.

Definition at line 284 of file dbprim.h.

typedef unsigned long(* hash_func_t)(hash_table_t *table, db_key_t *key)
 

This function is associated with a hash table, and is responsible for generating a hash value. The full 32-bit range of an unsigned long should be used--do *not* reduce the hash value by the modulus of the hash table.

Parameters:
[in] table A pointer to a hash_table_t.
[in] key The database key to hash.
Returns:
A 32-bit hash value for key.

Definition at line 392 of file dbprim.h.

typedef unsigned long(* hash_iter_t)(hash_table_t *table, hash_entry_t *ent, void *extra)
 

This function pointer references a callback used by ht_iter() and ht_flush(). It should return 0 for success. A non-zero return value will terminate the operation and will become the return value of the ht_iter() or ht_flush() call.

Parameters:
[in] table A pointer to a hash_table_t.
[in] ent A pointer to the hash_entry_t being considered.
[in] extra A void pointer passed to ht_iter() or ht_flush().
Returns:
Zero for success, or non-zero to terminate the iteration.

Definition at line 376 of file dbprim.h.

typedef unsigned long(* hash_resize_t)(hash_table_t *table, unsigned long new_mod)
 

This function pointer references a callback that will be called with both the old and new hash table sizes whenever a hash table is resized. It should return non-zero only when the resize should be inhibited.

Parameters:
[in] table A pointer to a hash_table_t.
[in] new_mod The new table modulus.
Returns:
Zero to permit the table resize, non-zero otherwise.

Definition at line 424 of file dbprim.h.

typedef struct _hash_table_s hash_table_t
 

This structure is the basis of all hash tables maintained by this library.

Definition at line 277 of file dbprim.h.


Function Documentation

unsigned long _hash_prime unsigned long  start  ) 
 

For internal use only.

This function is used by the hash table system to find the first prime number larger than start. This prime number will be used as the hash table modulus.

Parameters:
[in] start The number from which to start looking for the next largest prime.
Returns:
The first prime number larger than start.

Definition at line 781 of file _hash_prime.c.

References MAX_PRIME, and primes.

Referenced by ht_init(), and ht_resize().

unsigned long hash_comp hash_table_t table,
db_key_t key1,
db_key_t key2
 

This is a hash comparison function, compatible with hash_comp_t, based around memcmp().

Parameters:
[in] table A pointer to a hash_table_t.
[in] key1 The first key being compared.
[in] key2 The second key being compared.
Returns:
Zero if the keys match, non-zero otherwise.

Definition at line 36 of file hash_comp.c.

References dk_key, and dk_len.

Referenced by st_init().

unsigned long hash_fnv1 hash_table_t table,
db_key_t key
 

This is a hash function, compatible with hash_func_t, based around the FNV-1 hash algorithm. See http://www.isthe.com/chongo/tech/comp/fnv/ for more information about FNV-1.

Parameters:
[in] table A pointer to a hash_table_t.
[in] key The database key to hash.
Returns:
A 32-bit hash value for key.

Definition at line 35 of file hash_fnv1.c.

References dk_key, dk_len, HASH_FNV_OFFSET, and HASH_FNV_PRIME.

unsigned long hash_fnv1a hash_table_t table,
db_key_t key
 

This is a hash function, compatible with hash_func_t, based around the FNV-1a hash algorithm. See http://www.isthe.com/chongo/tech/comp/fnv/ for more information about FNV-1a.

Parameters:
[in] table A pointer to a hash_table_t.
[in] key The database key to hash.
Returns:
A 32-bit hash value for key.

Definition at line 35 of file hash_fnv1a.c.

References dk_key, dk_len, HASH_FNV_OFFSET, and HASH_FNV_PRIME.

Referenced by st_init().

unsigned long he_init hash_entry_t entry,
void *  value
 

This function dynamically initializes a hash table entry.

Parameters:
[in] entry A pointer to a hash_entry_t to be initialized.
[in] value A pointer to void which will be the value of the hash table entry.
Return values:
DB_ERR_BADARGS A NULL pointer was passed for entry.

Definition at line 34 of file he_init.c.

References _db_key_s::dk_key, _db_key_s::dk_len, HASH_ENTRY_MAGIC, _hash_entry_s::he_elem, _hash_entry_s::he_hash, _hash_entry_s::he_key, _hash_entry_s::he_magic, _hash_entry_s::he_table, _hash_entry_s::he_value, and le_init().

Referenced by _smat_alloc().

Here is the call graph for this function:

unsigned long ht_add hash_table_t table,
hash_entry_t entry,
db_key_t key
 

This function adds an entry to a hash table.

Parameters:
[in] table A pointer to a hash_table_t.
[in] entry A pointer to a hash_entry_t to be added to the table.
[in] key A pointer to a db_key_t containing the key for the entry.
Return values:
DB_ERR_BADARGS An invalid argument was given.
DB_ERR_BUSY The entry is already in a table.
DB_ERR_FROZEN The table is currently frozen.
DB_ERR_NOTABLE The bucket table has not been allocated and automatic growth is not enabled.
DB_ERR_DUPLICATE The entry is a duplicate of an existing entry.
DB_ERR_UNRECOVERABLE An unrecoverable error occurred while resizing the table.

Definition at line 34 of file ht_add.c.

References _hash_fuzz, HASH_FLAG_AUTOGROW, HASH_FLAG_FREEZE, _hash_entry_s::he_elem, _hash_entry_s::he_hash, _hash_entry_s::he_key, _hash_entry_s::he_table, he_verify, _hash_table_s::ht_count, ht_find(), _hash_table_s::ht_flags, _hash_table_s::ht_func, _hash_table_s::ht_modulus, ht_resize(), _hash_table_s::ht_rollover, _hash_table_s::ht_table, ht_verify, le_object, LINK_LOC_HEAD, and ll_add().

Referenced by st_add().

Here is the call graph for this function:

unsigned long ht_find hash_table_t table,
hash_entry_t **  entry_p,
db_key_t key
 

This function looks up an entry matching the given key.

Parameters:
[in] table A pointer to a hash_table_t.
[out] entry_p A pointer to a pointer to a hash_entry_t. If NULL is passed, the lookup will be performed and an appropriate error code returned.
[in] key A pointer to a db_key_t describing the item to find.
Return values:
DB_ERR_BADARGS An argument was invalid.
DB_ERR_NOENTRY No matching entry was found.

Definition at line 34 of file ht_find.c.

References he_key, _hash_table_s::ht_comp, _hash_table_s::ht_count, _hash_table_s::ht_func, _hash_table_s::ht_modulus, _hash_table_s::ht_table, ht_verify, le_next, le_object, and ll_first.

Referenced by ht_add(), ht_move(), and st_find().

unsigned long ht_flush hash_table_t table,
hash_iter_t  flush_func,
void *  extra
 

This function flushes a hash table--that is, it removes each entry from the table. If a flush_func is specified, it will be called on the entry after it has been removed from the table, and may safely call free().

Parameters:
[in] table A pointer to a hash_table_t.
[in] flush_func A pointer to a callback function used to perform user-specified actions on an entry after removing it from the table. May be NULL. See the documentation for hash_iter_t for more information.
[in] extra A void pointer that will be passed to flush_func.
Return values:
DB_ERR_BADARGS An argument was invalid.
DB_ERR_FROZEN The hash table is frozen.

Definition at line 36 of file ht_flush.c.

References HASH_FLAG_AUTOSHRINK, HASH_FLAG_FREEZE, _hash_table_s::ht_count, _hash_table_s::ht_flags, ht_free(), ht_modulus, ht_remove(), _hash_table_s::ht_table, ht_verify, le_object, and ll_first.

Referenced by st_flush().

Here is the call graph for this function:

unsigned long ht_free hash_table_t table  ) 
 

This function releases the memory used by the bucket table in an empty hash table.

Parameters:
[in] table A pointer to a hash_table_t.
Return values:
DB_ERR_BADARGS An invalid argument was given.
DB_ERR_FROZEN The table is frozen.
DB_ERR_NOTEMPTY The table is not empty.

Definition at line 36 of file ht_free.c.

References HASH_FLAG_FREEZE, _hash_table_s::ht_count, _hash_table_s::ht_flags, _hash_table_s::ht_modulus, _hash_table_s::ht_rollover, _hash_table_s::ht_rollunder, _hash_table_s::ht_table, and ht_verify.

Referenced by ht_flush(), and st_free().

unsigned long ht_init hash_table_t table,
unsigned long  flags,
hash_func_t  func,
hash_comp_t  comp,
hash_resize_t  resize,
void *  extra,
unsigned long  init_mod
 

This function dynamically initializes a hash table.

Parameters:
[in] table A pointer to a hash_table_t to be initialized.
[in] flags A bit-wise OR of HASH_FLAG_AUTOGROW and HASH_FLAG_AUTOSHRINK. If neither behavior is desired, use 0.
[in] func A hash_func_t function pointer for a hash function.
[in] comp A hash_comp_t function pointer for a comparison function.
[in] resize A hash_resize_t function pointer for determining whether resizing is permitted and/or for notification of the resize.
[in] extra Extra pointer data that should be associated with the hash table.
[in] init_mod An initial modulus for the table. This will presumably be extracted by ht_modulus() in a previous invocation of the application. A 0 value is valid.
Return values:
DB_ERR_BADARGS An invalid argument was given.
ENOMEM Unable to allocate memory.

Definition at line 37 of file ht_init.c.

References _hash_prime(), _hash_rollover, _hash_rollunder, HASH_FLAG_AUTOGROW, HASH_FLAG_AUTOSHRINK, HASH_TABLE_MAGIC, _hash_table_s::ht_comp, _hash_table_s::ht_count, _hash_table_s::ht_extra, _hash_table_s::ht_flags, _hash_table_s::ht_func, _hash_table_s::ht_magic, _hash_table_s::ht_modulus, ht_modulus, _hash_table_s::ht_resize, _hash_table_s::ht_rollover, _hash_table_s::ht_rollunder, _hash_table_s::ht_table, and ll_init().

Referenced by st_init().

Here is the call graph for this function:

unsigned long ht_iter hash_table_t table,
hash_iter_t  iter_func,
void *  extra
 

This function iterates over every entry in a hash table (in an unspecified order), executing the given iter_func on each entry.

Parameters:
[in] table A pointer to a hash_table_t.
[in] iter_func A pointer to a callback function used to perform user-specified actions on an entry in a hash table. NULL is an invalid value. See the documentation for hash_iter_t for more information.
[in] extra A void pointer that will be passed to iter_func.
Return values:
DB_ERR_BADARGS An argument was invalid.
DB_ERR_FROZEN The hash table is frozen.

Definition at line 34 of file ht_iter.c.

References HASH_FLAG_FREEZE, _hash_table_s::ht_flags, ht_modulus, _hash_table_s::ht_table, ht_verify, le_next, le_object, and ll_first.

Referenced by st_iter().

unsigned long ht_move hash_table_t table,
hash_entry_t entry,
db_key_t key
 

This function moves an existing entry in the hash table to correspond to the new key.

Parameters:
[in] table A pointer to a hash_table_t.
[in] entry A pointer to a hash_entry_t to be moved. It must already be in the hash table.
[in] key A pointer to a db_key_t describing the new key for the entry.
Return values:
DB_ERR_BADARGS An invalid argument was given.
DB_ERR_UNUSED Entry is not in a hash table.
DB_ERR_WRONGTABLE Entry is not in this hash table.
DB_ERR_FROZEN Hash table is frozen.
DB_ERR_DUPLICATE New key is a duplicate of an existing key.
DB_ERR_READDFAILED Unable to re-add entry to table.

Definition at line 34 of file ht_move.c.

References HASH_FLAG_FREEZE, _hash_entry_s::he_elem, _hash_entry_s::he_hash, _hash_entry_s::he_key, _hash_entry_s::he_table, he_verify, _hash_table_s::ht_count, ht_find(), _hash_table_s::ht_flags, _hash_table_s::ht_func, _hash_table_s::ht_modulus, _hash_table_s::ht_table, ht_verify, LINK_LOC_HEAD, ll_add(), and ll_remove().

Here is the call graph for this function:

unsigned long ht_remove hash_table_t table,
hash_entry_t entry
 

This function removes the given element from the specified hash table.

Parameters:
[in] table A pointer to a hash_table_t.
[in] entry A pointer to a hash_entry_t to be removed from the table.
Return values:
DB_ERR_BADARGS An invalid argument was given.
DB_ERR_UNUSED Entry is not in a hash table.
DB_ERR_WRONGTABLE Entry is not in this hash table.
DB_ERR_FROZEN Hash table is frozen.
DB_ERR_UNRECOVERABLE An unrecoverable error occurred while resizing the table.

Definition at line 34 of file ht_remove.c.

References HASH_FLAG_AUTOSHRINK, HASH_FLAG_FREEZE, _hash_entry_s::he_elem, _hash_entry_s::he_hash, _hash_entry_s::he_table, he_verify, _hash_table_s::ht_count, _hash_table_s::ht_flags, ht_resize(), _hash_table_s::ht_rollunder, _hash_table_s::ht_table, ht_verify, and ll_remove().

Referenced by _st_remove(), ht_flush(), and st_add().

Here is the call graph for this function:

unsigned long ht_resize hash_table_t table,
unsigned long  new_size
 

This function resizes a hash table to the given new_size. If new_size is 0, then an appropriate new size based on the current number of items in the hash table will be selected.

Parameters:
[in] table A pointer to a hash_table_t.
[in] new_size A new size value for the table.
Return values:
DB_ERR_BADARGS An argument was invalid.
DB_ERR_FROZEN The table is currently frozen.
DB_ERR_UNRECOVERABLE A catastrophic error was encountered. The table is now unusable.
ENOMEM No memory could be allocated for the new bucket table.

Definition at line 38 of file ht_resize.c.

References _hash_fuzz, _hash_prime(), _hash_rollover, _hash_rollunder, HASH_FLAG_FREEZE, _hash_entry_s::he_hash, _hash_entry_s::he_key, _hash_table_s::ht_count, _hash_table_s::ht_flags, _hash_table_s::ht_func, ht_modulus, _hash_table_s::ht_modulus, _hash_table_s::ht_resize, _hash_table_s::ht_rollover, _hash_table_s::ht_rollunder, _hash_table_s::ht_table, ht_verify, le_object, LINK_LOC_HEAD, ll_add(), ll_first, ll_init(), and ll_remove().

Referenced by ht_add(), ht_remove(), and st_resize().

Here is the call graph for this function:


Variable Documentation

unsigned long primes[] [static]
 

For internal use only.

This variable contains a table of 16-bit prime numbers, used by _hash_prime() to test the primality of potential primes.

Definition at line 50 of file _hash_prime.c.

Referenced by _hash_prime().


Generated on Sat Jul 15 14:10:58 2006 for DatabasePrimitivesLibrary by  doxygen 1.4.4