X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fstruct%2Fhashtable.h;h=07a514d5e90330007f558310b946f2af6536b8a4;hb=b7784f18c5317450f776e69dac33c0fd978507ec;hp=e59548cd73134c044fbc4f24f0acb0d64d301146;hpb=56bc36208843a05a8879f31a1b1a6bcb0f1de176;p=bertos.git diff --git a/bertos/struct/hashtable.h b/bertos/struct/hashtable.h index e59548cd..07a514d5 100644 --- a/bertos/struct/hashtable.h +++ b/bertos/struct/hashtable.h @@ -30,6 +30,10 @@ * Copyright 2004 Giovanni Bajo * --> * + * \defgroup hashtable Hash table implementation + * \ingroup struct + * \{ + * * \brief Portable hash table * * This file implements a portable hash table, with the following features: @@ -48,23 +52,21 @@ * a marker for a free node, so it is invalid to store a NULL pointer in the table * with \c ht_insert(). * - * \version $Id$ * \author Giovanni Bajo + * + * $WIZ$ module_name = "hashtable" + * $WIZ$ module_configuration = "bertos/cfg/cfg_hashtable.h" */ -#ifndef MWARE_HASHTABLE_H -#define MWARE_HASHTABLE_H +#ifndef STRUCT_HASHTABLE_H +#define STRUCT_HASHTABLE_H + +#include "cfg/cfg_hashtable.h" #include #include #include -/** - * Enable/disable support to declare special hash tables which maintain a copy of - * the key internally instead of relying on the hook to extract it from the data. - */ -#define CONFIG_HT_OPTIONAL_INTERNAL_KEY 1 - /// Maximum length of the internal key (use (2^n)-1 for slight speedup) #define INTERNAL_KEY_MAX_LENGTH 15 @@ -120,12 +122,26 @@ typedef struct */ #define DECLARE_HASHTABLE(name, size, hook_gk) \ static const void* name##_nodes[1 << UINT32_LOG2(size)]; \ - struct HashTable name = { name##_nodes, UINT32_LOG2(size), { false }, hook_gk } + struct HashTable name = \ + { \ + .mem = name##_nodes, \ + .max_elts_log2 = UINT32_LOG2(size), \ + .flags = { .key_internal = false }, \ + .key_data.hook = hook_gk \ + } + /** Exactly like \c DECLARE_HASHTABLE, but the variable will be declared as static. */ #define DECLARE_HASHTABLE_STATIC(name, size, hook_gk) \ - static const void* name##_nodes[1 << UINT32_LOG2(size)]; \ - static struct HashTable name = { name##_nodes, UINT32_LOG2(size), { false }, { hook_gk } } + enum { name##_SIZE = (1 << UINT32_LOG2(size)), }; \ + static const void* name##_nodes[name##_SIZE]; \ + static struct HashTable name = \ + { \ + .mem = name##_nodes, \ + .max_elts_log2 = UINT32_LOG2(size), \ + .flags = { .key_internal = false }, \ + .key_data.hook = hook_gk \ + } #if CONFIG_HT_OPTIONAL_INTERNAL_KEY /** Declare a hash table with internal copies of the keys. This version does not @@ -140,9 +156,17 @@ typedef struct /** Exactly like \c DECLARE_HASHTABLE_INTERNALKEY, but the variable will be declared as static. */ #define DECLARE_HASHTABLE_INTERNALKEY_STATIC(name, size) \ - static uint8_t name##_keys[(1 << UINT32_LOG2(size)) * (INTERNAL_KEY_MAX_LENGTH + 1)]; \ - static const void* name##_nodes[1 << UINT32_LOG2(size)]; \ - static struct HashTable name = { name##_nodes, UINT32_LOG2(size), { true }, name##_keys } + enum { name##_KEYS = ((1 << UINT32_LOG2(size)) * (INTERNAL_KEY_MAX_LENGTH + 1)), \ + name##_SIZE = (1 << UINT32_LOG2(size)), }; \ + static uint8_t name##_keys[name##_KEYS]; \ + static const void* name##_nodes[name##_SIZE]; \ + static struct HashTable name = \ + { \ + .mem = name##_nodes, \ + .max_elts_log2 = UINT32_LOG2(size), \ + .flags = { .key_internal = true }, \ + .key_data.mem = name##_keys \ + } #endif /** @@ -151,7 +175,7 @@ typedef struct * \param ht Hash table declared with \c DECLARE_HASHTABLE * * \note This function must be called before using the hash table. Optionally, - * it can be called later in the program to clear the hash table, + * it can be called later in the program to clear the hash table, * removing all its elements. */ void ht_init(struct HashTable* ht); @@ -268,4 +292,10 @@ INLINE HashIterator ht_iter_next(HashIterator h) return h; } -#endif /* MWARE_HASHTABLE_H */ +int hashtable_testSetup(void); +int hashtable_testRun(void); +int hashtable_testTearDown(void); + +/** \} */ // \defgroup hashtable + +#endif /* STRUCT_HASHTABLE_H */