BeRTOS
|
Portable hash table implementation. More...
#include "hashtable.h"
#include "cfg/cfg_hashtable.h"
#include <cfg/debug.h>
#include <cfg/compiler.h>
#include <cfg/macros.h>
#include <string.h>
Go to the source code of this file.
Functions | |
uint8_t * | key_internal_get_ptr (struct HashTable *ht, HashNodePtr node) |
For hash tables with internal keys, compute the pointer to the internal key for a given node. | |
void | ht_init (struct HashTable *ht) |
Initialize (and clear) a hash table in a memory buffer. | |
bool | ht_insert_with_key (struct HashTable *ht, const void *key, uint8_t key_length, const void *data) |
Insert an element into the hash table. | |
bool | ht_insert (struct HashTable *ht, const void *data) |
Insert an element into the hash table. | |
const void * | ht_find (struct HashTable *ht, const void *key, uint8_t key_length) |
Find an element in the hash table. |
Portable hash table implementation.
Some rationales of our choices in implementation:
HashNode
and HashTable
structures in the header file. Nevertheless, they should be used as opaque types (that is, the users should not access the structure fields directly).HashNode
to the user (who only manipulates HashTable
). Without the macro, the user would have had to define both the HashNode
and the HashTable
manually, and pass both of them to ht_init()
(which would have created the link between the two). Instead, the link is created with a literal initialization.calc_hash()
).struct
HashTable till now, so we had to add a first bit flag, but the overhead will disappear if a second flag is added for a different reason later. ht_insert()
, one with the key passed as parameter and one without, but in the common case (external keys) both can be used. Definition in file hashtable.c.
const void* ht_find | ( | struct HashTable * | ht, |
const void * | key, | ||
uint8_t | key_length | ||
) |
Find an element in the hash table.
ht | Handle of the hash table |
key | Key of the element |
key_length | Length of the key in characters |
Definition at line 274 of file hashtable.c.
void ht_init | ( | struct HashTable * | ht | ) |
Initialize (and clear) a hash table in a memory buffer.
ht | Hash table declared with DECLARE_HASHTABLE |
Definition at line 203 of file hashtable.c.
bool ht_insert | ( | struct HashTable * | ht, |
const void * | data | ||
) |
Insert an element into the hash table.
ht | Handle of the hash table |
data | Data to be inserted into the table |
Definition at line 254 of file hashtable.c.
bool ht_insert_with_key | ( | struct HashTable * | ht, |
const void * | key, | ||
uint8_t | key_length, | ||
const void * | data | ||
) |
Insert an element into the hash table.
ht | Handle of the hash table |
key | Key of the element |
key_length | Length of the key in characters |
data | Data to be inserted into the table |
Definition at line 235 of file hashtable.c.
uint8_t* key_internal_get_ptr | ( | struct HashTable * | ht, |
HashNodePtr | node | ||
) | [inline] |
For hash tables with internal keys, compute the pointer to the internal key for a given node.
Definition at line 99 of file hashtable.c.