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_t * | fts_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. |
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).
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.
from | the hashtable | |
to | the copied hashtable |
FTS_API void fts_hashtable_destroy | ( | fts_hashtable_t * | h | ) |
Destroy (deinitialise) a hashtable.
h | the hashtable |
FTS_API int fts_hashtable_equals | ( | fts_hashtable_t * | a, | |
fts_hashtable_t * | b | |||
) |
Compare a hashtable content to another.
a | the hashtable | |
b | the hashtable to compare with |
FTS_API void fts_hashtable_free | ( | fts_hashtable_t * | h | ) |
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.
h | the hashtable | |
key | a pointer to the key to be inserted | |
value | a pointer for returning the retrieved value |
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.
h | the hashtable | |
i | the iterator |
int fts_hashtable_get_size | ( | fts_hashtable_t * | ht | ) |
Get size of a hashtable.
ht | 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.
h | the hashtable | |
i | the iterator |
FTS_API void fts_hashtable_init | ( | fts_hashtable_t * | h, | |
int | initial_capacity | |||
) |
Initialise a hashtable.
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.
initial_capacity | the initial capacity of the 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.
h | the hashtable | |
key | a pointer to the key to be inserted | |
value | a pointer to the value to be inserted |
FTS_API int fts_hashtable_remove | ( | fts_hashtable_t * | h, | |
const fts_atom_t * | key | |||
) |
Remove a given key from a hashtable.
h | the hashtable | |
key | a pointer to the key to be removed |