core | glapi | vbo | math | shader | swrast | swrast_setup | tnl | tnl_dd

hash_table.h File Reference


Detailed Description

Implementation of a generic, opaque hash table data type.

Author:
Ian Romanick <ian.d.romanick@intel.com>

#include <string.h>

Defines

#define hash_table_string_compare   ((hash_compare_func_t) strcmp)
 Compare two strings used as keys.

Typedefs

typedef unsigned(* hash_func_t )(const void *key)
typedef int(* hash_compare_func_t )(const void *key1, const void *key2)

Functions

struct hash_tablehash_table_ctor (unsigned num_buckets, hash_func_t hash, hash_compare_func_t compare)
 Hash table constructor.
void hash_table_dtor (struct hash_table *ht)
 Release all memory associated with a hash table.
void hash_table_clear (struct hash_table *ht)
 Flush all entries from a hash table.
void * hash_table_find (struct hash_table *ht, const void *key)
 Search a hash table for a specific element.
void hash_table_insert (struct hash_table *ht, void *data, const void *key)
 Add an element to a hash table.
unsigned hash_table_string_hash (const void *key)
 Compute hash value of a string.


Define Documentation

#define hash_table_string_compare   ((hash_compare_func_t) strcmp)

Compare two strings used as keys.

This is just a macro wrapper around strcmp.

See also:
hash_table_string_hash


Typedef Documentation

typedef int(* hash_compare_func_t)(const void *key1, const void *key2)

typedef unsigned(* hash_func_t)(const void *key)


Function Documentation

void hash_table_clear ( struct hash_table ht  ) 

Flush all entries from a hash table.

Parameters:
ht Table to be cleared of its entries.

struct hash_table* hash_table_ctor ( unsigned  num_buckets,
hash_func_t  hash,
hash_compare_func_t  compare 
) [read]

Hash table constructor.

Creates a hash table with the specified number of buckets. The supplied hash and compare routines are used when adding elements to the table and when searching for elements in the table.

Parameters:
num_buckets Number of buckets (bins) in the hash table.
hash Function used to compute hash value of input keys.
compare Function used to compare keys.

void hash_table_dtor ( struct hash_table ht  ) 

Release all memory associated with a hash table.

Warning:
This function cannot release memory occupied either by keys or data.

void* hash_table_find ( struct hash_table ht,
const void *  key 
)

Search a hash table for a specific element.

Parameters:
ht Table to be searched
key Key of the desired element
Returns:
The data value supplied to hash_table_insert when the element with the matching key was added. If no matching key exists in the table, NULL is returned.

void hash_table_insert ( struct hash_table ht,
void *  data,
const void *  key 
)

Add an element to a hash table.

unsigned hash_table_string_hash ( const void *  key  ) 

Compute hash value of a string.

Computes the hash value of a string using the DJB2 algorithm developed by Professor Daniel J. Bernstein. It was published on comp.lang.c once upon a time. I was unable to find the original posting in the archives.

Parameters:
key Pointer to a NUL terminated string to be hashed.
See also:
hash_table_string_compare


Generated on Sun Sep 27 06:48:02 2009 for Mesa Vertex and Fragment Program code by  doxygen 1.5.4