FTS hashtable
[FTS Utilitiy Data Structures]


Detailed Description

The FTS hashtable.

An FTS hashtable maps keys to values, where both keys and values are FTS atoms.

FTS hashtable performs automatic rehashing when the ration between number of inserted keys and the capacity is greater than a "load factor" (typically 0.75).

The initial capacity of the hashtable can be given by an argument at the initialisation (FTS_HASHTABLE_SMALL, FTS_HASHTABLE_MEDIUM or FTS_HASHTABLE_BIG). To work with a big hashtable, it is more efficient to create the hashtable with a big capacity to avoid intermediate automatic rehashing.


Defines

#define FTS_HASHTABLE_SMALL   1
 Initialisation argument constant for small hashtables.
#define FTS_HASHTABLE_MEDIUM   2
 Initialisation argument constant for medium hashtables.
#define FTS_HASHTABLE_BIG   3
 Initialisation argument constant for big hashtables.

Typedefs

typedef struct fts_hashtable fts_hashtable_t
 FTS hashtable data type.

Functions

int fts_hashtable_get_size (fts_hashtable_t *ht)
 Get size of a hashtable.
FTS_API void fts_hashtable_init (fts_hashtable_t *h, int initial_capacity)
 Initialise a hashtable.
FTS_API void fts_hashtable_destroy (fts_hashtable_t *h)
 Destroy (deinitialise) a hashtable.
FTS_API fts_hashtable_tfts_hashtable_new (int initial_capacity)
 Allocate and initialise a hashtable.
FTS_API void fts_hashtable_free (fts_hashtable_t *h)
 Free a hashtable that was obtained by fts_hashtable_new().
FTS_API void fts_hashtable_clear (fts_hashtable_t *h)
 Clear the content of a hashtable.
FTS_API void fts_hashtable_copy (fts_hashtable_t *from, fts_hashtable_t *to)
 Copy the content of a hashtable to another.
FTS_API int fts_hashtable_equals (fts_hashtable_t *a, fts_hashtable_t *b)
 Compare a hashtable content to another.
FTS_API int fts_hashtable_get (const fts_hashtable_t *h, const fts_atom_t *key, fts_atom_t *value)
 Retrieve the value associated to a given key from a hashtable.
FTS_API int fts_hashtable_put (fts_hashtable_t *h, const fts_atom_t *key, const fts_atom_t *value)
 Insert or set a value associated to teh given key to a hashtable.
FTS_API int fts_hashtable_remove (fts_hashtable_t *h, const fts_atom_t *key)
 Remove a given key from a hashtable.
FTS_API void fts_hashtable_get_keys (const fts_hashtable_t *h, fts_iterator_t *i)
 Get an iterator to enumerate the keys contained in the hashtable.
FTS_API void fts_hashtable_get_values (const fts_hashtable_t *h, fts_iterator_t *i)
 Get an iterator to enumerate the values contained in the hashtable.


Function Documentation

FTS_API void fts_hashtable_clear ( fts_hashtable_t h  ) 

Clear the content of a hashtable.

After calling fts_hashtable_clear(), the hashtable will contain no keys, but will keep its allocation state (i.e. its capacity will be its capacity before call).

Parameters:
h the hashtable

FTS_API void fts_hashtable_copy ( fts_hashtable_t from,
fts_hashtable_t to 
)

Copy the content of a hashtable to another.

Parameters:
from the hashtable
to the copied hashtable

FTS_API void fts_hashtable_destroy ( fts_hashtable_t h  ) 

Destroy (deinitialise) a hashtable.

Parameters:
h the hashtable

FTS_API int fts_hashtable_equals ( fts_hashtable_t a,
fts_hashtable_t b 
)

Compare a hashtable content to another.

Parameters:
a the hashtable
b the hashtable to compare with
Returns:
1 if hashtables have equal content, else 0

FTS_API void fts_hashtable_free ( fts_hashtable_t h  ) 

Free a hashtable that was obtained by fts_hashtable_new().

Parameters:
h the hashtable

FTS_API int fts_hashtable_get ( const fts_hashtable_t h,
const fts_atom_t *  key,
fts_atom_t *  value 
)

Retrieve the value associated to a given key from a hashtable.

Parameters:
h the hashtable
key a pointer to the key to be inserted
value a pointer for returning the retrieved value
Returns:
1 if key is mapped, 0 if not

FTS_API void fts_hashtable_get_keys ( const fts_hashtable_t h,
fts_iterator_t i 
)

Get an iterator to enumerate the keys contained in the hashtable.

Parameters:
h the hashtable
i the iterator

int fts_hashtable_get_size ( fts_hashtable_t ht  ) 

Get size of a hashtable.

Parameters:
ht hashtable
Returns:
hashtable size

FTS_API void fts_hashtable_get_values ( const fts_hashtable_t h,
fts_iterator_t i 
)

Get an iterator to enumerate the values contained in the hashtable.

Parameters:
h the hashtable
i the iterator

FTS_API void fts_hashtable_init ( fts_hashtable_t h,
int  initial_capacity 
)

Initialise a hashtable.

Parameters:
h the hashtable
initial_capacity the initial capacity of the hashtable.

FTS_API fts_hashtable_t* fts_hashtable_new ( int  initial_capacity  ) 

Allocate and initialise a hashtable.

Parameters:
initial_capacity the initial capacity of the hashtable.
Returns:
the allocated hashtable

FTS_API int fts_hashtable_put ( fts_hashtable_t h,
const fts_atom_t *  key,
const fts_atom_t *  value 
)

Insert or set a value associated to teh given key to a hashtable.

Parameters:
h the hashtable
key a pointer to the key to be inserted
value a pointer to the value to be inserted
Returns:
1 if entry was already mapped, 0 if not

FTS_API int fts_hashtable_remove ( fts_hashtable_t h,
const fts_atom_t *  key 
)

Remove a given key from a hashtable.

Parameters:
h the hashtable
key a pointer to the key to be removed
Returns:
1 if entry was mapped, 0 if not


Generated on Wed Aug 24 18:28:43 2011 for FTM API by  doxygen 1.5.6