cgi/hash.h File Reference

hash functions. More...


Defines

#define HASH_TABLE_SIZE   65535
 Hash table size.

Typedefs

typedef unsigned int(* t_hash_fn )(void *)
 Hash function type.
typedef int(* t_hash_key_compare_fn )(void *, void *)
 Keys comparison function type.
typedef void *(* t_hash_key_copy_fn )(void *)
 Key copy function type.
typedef void(* t_hash_key_free_fn )(void *)
 Free key function type.
typedef struct s_hash t_hash
 Hash type.

Functions

void * hash_find (t_hash *, void *)
 Find hash value with given key.
void hash_add (t_hash *, void *, void *)
 Adds new value with given key.
void hash_del (t_hash *, void *)
 Deletes element with given key.
t_hashhash_create (t_hash_key_compare_fn, t_hash_key_copy_fn, t_hash_key_free_fn, t_hash_fn)
 Create hash using given functions for keys manipulations.
t_hashhash_create_strkey ()
 Create hash with char* keys.
void hash_free (t_hash *)
 Frees hash and releases occupied memory.


Detailed Description

hash functions.

Author:
Vladimir Pavluk, 2006-2007
Hash is a data structure to speed up data searching based on keys. This file contains functions to create and handle hash structures.

Define Documentation

#define HASH_TABLE_SIZE   65535

Hash table size.

Size of a virtual hash table. The bigger is it, the more memory it consumes, but works faster.


Typedef Documentation

typedef struct s_hash t_hash

Hash type.

Contains hash structure.

typedef unsigned int(* t_hash_fn)(void *)

Hash function type.

Function converting key to integer in range 0 to HASH_TABLE_SIZE.

typedef int(* t_hash_key_compare_fn)(void *, void *)

Keys comparison function type.

Function returning -1 0 or 1 depending on keys comparison.

typedef void*(* t_hash_key_copy_fn)(void *)

Key copy function type.

Function returning a copy of key.

typedef void(* t_hash_key_free_fn)(void *)

Free key function type.

Function freeing passed key.


Function Documentation

void hash_add ( t_hash hash,
void *  key,
void *  data 
)

Adds new value with given key.

Adds hash element with given key and value.

Attention:
WARNING: its your responsibility to ensure the hash is valid.
Parameters:
hash hash to add to.
key key to add.
data element data.
See also:
hash_create(t_hash_key_compare_fn, t_hash_key_copy_fn, t_hash_key_free_fn, t_hash_fn)

hash_find(t_hash *, void *)

hash_del(t_hash *, void *)

t_hash* hash_create ( t_hash_key_compare_fn  cmp,
t_hash_key_copy_fn  cpy,
t_hash_key_free_fn  kfree,
t_hash_fn  hash_fn 
)

Create hash using given functions for keys manipulations.

Creates hash using given functions for keys manipulations.

Parameters:
cmp comparison function.
cpy function for copying keys.
kfree function for releasing memory occupied by key.
hash_fn hash function.
Returns:
pointer to created hash (t_hash*).
See also:
hash_create_strkey()

hash_free(t_hash *)

t_hash* hash_create_strkey (  ) 

Create hash with char* keys.

Automatically creates hash using existing functions for char* keys manipulations.

Returns:
pointer to created hash (t_hash*).
See also:
hash_create(t_hash_key_compare_fn, t_hash_key_copy_fn, t_hash_key_free_fn, t_hash_fn)

hash_free(t_hash *)

void hash_del ( t_hash hash,
void *  key 
)

Deletes element with given key.

Deletes hash element with given key.

Attention:
WARNING: its your responsibility to ensure the hash is valid.
Parameters:
hash hash to delete from.
key key to delete.
See also:
hash_create(t_hash_key_compare_fn, t_hash_key_copy_fn, t_hash_key_free_fn, t_hash_fn)

hash_add(t_hash *, void *, void *)

hash_find(t_hash *, void *)

void* hash_find ( t_hash hash,
void *  key 
)

Find hash value with given key.

Finds hash element with given key and returns its value.

Attention:
WARNING: its your responsibility to ensure the hash is valid.
Parameters:
hash hash to search in.
key key for which to search.
Returns:
pointer to found element, or null if not found.
See also:
hash_create(t_hash_key_compare_fn, t_hash_key_copy_fn, t_hash_key_free_fn, t_hash_fn)

hash_add(t_hash *, void *, void *)

hash_del(t_hash *, void *)

void hash_free ( t_hash hash  ) 

Frees hash and releases occupied memory.

Releases memory occupied by the hash. Deletes all hash elements.

Attention:
WARNING: its your responsibility to ensure the hash is valid.

WARNING: if you don't keep your data pointers anywhere else, you will lose all the data,

along with memory it occupies.
Parameters:
hash hash to add to.
See also:
hash_create(t_hash_key_compare_fn, t_hash_key_copy_fn, t_hash_key_free_fn, t_hash_fn)

hash_create_strkey()


Generated on Tue Jun 17 17:31:12 2008 for Data Processing Library by  doxygen 1.5.5