Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

epHash.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "epDefs.h"
#include "epUtils.h"
#include "epHash.h"

Include dependency graph for epHash.c:

Include dependency graph

Go to the source code of this file.

Functions

epHash_tepHash_create (const ulong numOfBuckets, boolean_t (*keyComparisonFunction)(const void *key1, const void *key2), uint (*hashFunction)(const void *key), int (*keyDeallocatorFunction)(void *key), int (*valueDeallocatorFunction)(void *value))
int epHash_destroy (epHash_t *hashTable)
uint epHash_size (epHash_t *hashTable)
boolean_t epHash_isEmpty (epHash_t *hashTable)
uint epHash_getNumOfBuckets (epHash_t *hashTable)
int epHash_put (epHash_t *hashTable, const void *key, const void *value)
void* epHash_get (const epHash_t *hashTable, const void *key)
int epHash_remove (epHash_t *hashTable, const void *key)
boolean_t epHash_containsKey (epHash_t *hashTable, const void *key)
int epHash_rehash (epHash_t *hashTable, uint numOfBuckets)
void epHash_setIdealRatio (epHash_t *hashTable, double idealRatio, double lowerRehashThreshold, double upperRehashThreshold)
uint calculateIdealNumOfBuckets (const epHash_t *hashTable)


Detailed Description

Author(s):
Guillaume Bour. U.B.O 2000/2001

Version:
0.0.0
Date:
19/02/2001

Generic hashtable. no size-limited, accept all type-defined data. User defined hash functions.

A IMPLEMENTER: 1)autoriser ou non 2 clé de même valeur de hashage. si interdit et autorehash -> alors rehash si interdit et pas autorehash -> alors erreur et pas d'insertion 2)pouvoir connaitre la valeur de hashage d'une clé 3)retourver une valeur(parcours) 4)savoir si l'autorehash est activé

Definition in file epHash.c.


Function Documentation

uint calculateIdealNumOfBuckets ( const epHash_t * hashTable )
 

Calculate the optimal number of buckets, based on the ideal ratio.

visibility :: private

Remarks:
1. the ideal number of buckets is between 1/5 and 1 the number of elements contained into the hashtable
Parameters:
hashTable   the considered hashtable
Returns:
the optimal bucket number

Definition at line 480 of file epHash.c.

boolean_t epHash_containsKey ( epHash_t * hashTable,
const void * key )
 

Return <true> if the key is present into the hastable, <false> else.

visibility :: public

Parameters:
hashTable   the considered hashtable
key   the search key
Return values:
<true>   if the key is present,
<false>   else

Definition at line 351 of file epHash.c.

epHash_t * epHash_create ( const ulong numOfBuckets,
boolean_t(* keyComparisonFunction)(const void *key1,const void *key2),
uint(* hashFunction)(const void *key),
int(* keyDeallocatorFunction)(void *key),
int(* valueDeallocatorFunction)(void *value) )
 

Create & initialize a new hashtable.

visibility :: public

Remarks:
1. the minimum numOfBuckets value is 5.
2. the keyComparisonFunction and hashFunction arguments are required (you can use the default functions defined in epUtils.h).
3. if the keyDeallocatorFunction and valueDeallocatorFunction are set to NULL, then the default pointer deallocator function is used.
Parameters:
numOfBuckets   the initiale number of buckets for the hashtable
keyComparisonFunction   the key comparison function
hashFunction   the hash function
keyDeallocatorFunction   the key deallocator function
valueDeallocatorFunction   the value deallocator function

Returns:
the created hashtable (a pointer) or NULL if an error occurs

Definition at line 50 of file epHash.c.

int epHash_destroy ( epHash_t * hashTable )
 

Destroy the hashtable and all the couples key/value contained into.

visibility :: public

Parameters:
hashTable   the considered hash table
Return values:
0   if OK,
-1   else

Definition at line 109 of file epHash.c.

void * epHash_get ( const epHash_t * hashTable,
const void * key )
 

Return the key-associated value of the hashtable.

visibility :: public

Parameters:
hashTable   the considered hashtable
key   the search key
Returns:
the associated value if found, NULL else

Definition at line 258 of file epHash.c.

uint epHash_getNumOfBuckets ( epHash_t * hashTable )
 

Return the bucket number of the hashtable.

visibility :: public

Parameters:
hashTable   the considered hashtable
Returns:
the number of its buckets

Definition at line 178 of file epHash.c.

boolean_t epHash_isEmpty ( epHash_t * hashTable )
 

Return <true> is the hashtable is empty, <false> else.

visibility :: public

Parameters:
hashTable   the considered hashtable
Return values:
<true>   if the hashtable is empty,
<false>   if not

Definition at line 164 of file epHash.c.

int epHash_put ( epHash_t * hashTable,
const void * key,
const void * value )
 

Insert a new key/value couple into the hashtable.

visibility :: public

Remarks:
1. if the key is already present into the hashtable, then an error is release.
2. if the auto rehash is activated and necessary, then the hashtable is rehash (increase in fact).
Parameters:
hashTable   the considered hashtable
key   the key and
value   its associated value
Return values:
0   if OK,
-1   else

Definition at line 201 of file epHash.c.

int epHash_rehash ( epHash_t * hashTable,
uint numOfBuckets )
 

Rehash the hastable. It is used to optimized the access time and the memory space using.

visibility :: public

Remarks:
1. if numOfBuckets = 0, then the new numOfBuckets is automaticaly compute from the ideal ratio for optimization.
2. the minimum numOfBuckets is 5.
Parameters:
hashTable   the considered hashtable
numOfBuckets   the desired new number of buckets
Return values:
0   if OK,
-1   else

Definition at line 374 of file epHash.c.

int epHash_remove ( epHash_t * hashTable,
const void * key )
 

Remove the key/value couple from the hashtable.

visibility :: public

Remarks:
1. if the key is no present into the hashtable, then an error is release.
2. if the auto rehash is activated and necessary, then the hashtable is rehash (decrease in fact).
Parameters:
hashTable   the considered hashtable
key   the to-remove key
Return values:
0   if OK,
-1   else

Definition at line 300 of file epHash.c.

void epHash_setIdealRatio ( epHash_t * hashTable,
double idealRatio,
double lowerRehashThreshold,
double upperRehashThreshold )
 

fixe les ratio de rehashage. les différentes valeurs sont: + ratio idéal. c'est le nombre idéal d'éléments par bucket (celui que cherche à atteindre lors d'un rehashage)

+ ratio moyen minimal avant rehash décrémentiel. (nombre total d'éléments/nombre de buckets). En dessous de cette valeur, un rehashage négatif sera effectué (on diminue le nombre de buckets)

Pour désactiver le rehashage négatif automatique, on mettra la valeur 0.0

+ ratio moyen maximal avant rehash incrémentiel (nombre total d'éléments/nombre de buckets) Au dessus de cette valeur, on rehash la table en augmentant son nombre de buckets

! Doit être supérieur au ratio minimal moyen Pour désactiver le rehashage automatique incrémentiel, on lui affectera la valeur 0.0

valeurs par défaut: resp. 3.0, 0.0 et 15.0

visibility :: public

Parameters:
hashTable   the considered hashtable
idealRatio   the ideal ratio
lowerRehashThreshold   the min. threshold before rehash
upperRehashThreshold   the max. threshold before rehash

Definition at line 454 of file epHash.c.

uint epHash_size ( epHash_t * hashTable )
 

Return the size of the hashtable (the number of elements contained into).

visibility :: public

Parameters:
hashTable   the considered hashtable
Returns:
its size

Definition at line 149 of file epHash.c.


Generated at Sun Nov 25 14:05:10 2001 for ExtendedPersonnalLibrary by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000