| libdatatypes 0.3.2
    Abstract datatypes for C. | 
Generic hashtable. More...
#include <stdlib.h>#include <stdio.h>#include <string.h>#include <assert.h>#include "hashtable.h"Go to the source code of this file.
Generic hashtable.
Definition in file hashtable.c.
| void hashtable_clear | ( | HashTable * | table | ) | 
| table | a HashTable | 
Removes all elements from the HashTable.
Definition at line 218 of file hashtable.c.
| size_t hashtable_count | ( | const HashTable * | table | ) | 
| table | a HashTable | 
Gets the number of stored elements.
Definition at line 481 of file hashtable.c.
| void hashtable_destroy | ( | HashTable * | table | ) | 
| table | a HashTable | 
Frees all keys, values and the table pointer.
Definition at line 167 of file hashtable.c.
| void hashtable_free | ( | HashTable * | table | ) | 
| table | a HashTable | 
Frees all keys and values without freeing the table pointer.
Definition at line 208 of file hashtable.c.
| void hashtable_init | ( | HashTable * | table, | 
| size_t | size, | ||
| HashFunc | hash_func, | ||
| EqualFunc | compare_keys, | ||
| FreeFunc | free_key, | ||
| FreeFunc | free_value | ||
| ) | 
| table | a HashTable | 
| size | size of the hash table (number of buckets), HASHTABLE_AUTO_RESIZE to grow automatically | 
| hash_func | function to create hash from a key | 
| compare_keys | function to check equality of two keys | 
| free_key | function to free keys or NULL | 
| free_value | function to free values or NULL | 
Initializes a HashTable.
Definition at line 120 of file hashtable.c.
| void * hashtable_iter_get_key | ( | const HashTableIter * | iter | ) | 
| iter | a HashTableIter | 
Retrieves the key of the current element.
Definition at line 537 of file hashtable.c.
| void * hashtable_iter_get_value | ( | const HashTableIter * | iter | ) | 
| iter | a HashTableIter | 
Retrieves the value of the current element.
Definition at line 545 of file hashtable.c.
| void hashtable_iter_init | ( | const HashTable * | table, | 
| HashTableIter * | iter | ||
| ) | 
| table | a HashTable | 
| iter | an uninitialized HashTableIter | 
Initializes a key/value pair iterator and associates it with the table. Modifying the table while using the iterator might lead to undefined behaviour.
Definition at line 489 of file hashtable.c.
| bool hashtable_iter_next | ( | HashTableIter * | iter | ) | 
| iter | a HashTableIter | 
Goes to next element of the HashTable.
Definition at line 513 of file hashtable.c.
| bool hashtable_key_exists | ( | const HashTable * | table, | 
| const void * | key | ||
| ) | 
| table | a HashTable | 
| key | key to test | 
Checks if a key does exist.
Definition at line 470 of file hashtable.c.
| HashTablePair * hashtable_lookup | ( | HashTable * | table, | 
| const void * | key | ||
| ) | 
| table | a HashTable | 
| key | key to lookup | 
Looks up a key-value pair in the HashTable.
Definition at line 416 of file hashtable.c.
| HashTable * hashtable_new | ( | size_t | size, | 
| HashFunc | hash_func, | ||
| EqualFunc | compare_keys, | ||
| FreeFunc | free_key, | ||
| FreeFunc | free_value | ||
| ) | 
| size | size of the hash table (number of buckets), HASHTABLE_AUTO_RESIZE to grow automatically | 
| hash_func | function to create hash from a key | 
| compare_keys | function to check equality of two keys | 
| free_key | function to free keys or NULL | 
| free_value | function to free values or NULL | 
Creates a new HashTable.
Definition at line 100 of file hashtable.c.
| void * hashtable_pair_get_key | ( | const HashTablePair * | pair | ) | 
| pair | a key-value pair | 
Retrieves the key of a key-value pair.
Definition at line 435 of file hashtable.c.
| void * hashtable_pair_get_value | ( | const HashTablePair * | pair | ) | 
| pair | a key-value pair | 
Retrieves the value of a key-value pair.
Definition at line 445 of file hashtable.c.
| void hashtable_pair_set_value | ( | HashTablePair * | pair, | 
| void * | value | ||
| ) | 
| pair | a HashTablePair | 
| value | new value to set | 
Overwrites the value of a key-value pair.
Definition at line 455 of file hashtable.c.
| void hashtable_remove | ( | HashTable * | table, | 
| const void * | key | ||
| ) | 
| table | a HashTable | 
| key | key of the element to remove | 
Removes an element from the HashTable.
Definition at line 367 of file hashtable.c.
| HashTableInsertResult hashtable_set | ( | HashTable * | table, | 
| void * | key, | ||
| void * | value, | ||
| bool | overwrite_key | ||
| ) | 
| table | a HashTable | 
| key | key to insert | 
| value | the value to associate with the key | 
| overwrite_key | true to overwrite already existing keys | 
Inserts a new key and value in the HashTable. If overwrite_key is set an existing key is freed using the specified free_key function before it gets replaced.
Definition at line 308 of file hashtable.c.