Fix nightly test warnings in hashtable implementation.
[bertos.git] / bertos / struct / hashtable.h
index 9a102a8a9ce9a35327540f94be9470f45159e66f..07a514d5e90330007f558310b946f2af6536b8a4 100644 (file)
@@ -30,7 +30,9 @@
  * Copyright 2004 Giovanni Bajo
  * -->
  *
- * \author Giovanni Bajo <rasky@develer.com>
+ * \defgroup hashtable Hash table implementation
+ * \ingroup struct
+ * \{
  *
  * \brief Portable hash table
  *
@@ -50,6 +52,8 @@
  * a marker for a free node, so it is invalid to store a NULL pointer in the table
  * with \c ht_insert().
  *
+ * \author Giovanni Bajo <rasky@develer.com>
+ *
  * $WIZ$ module_name = "hashtable"
  * $WIZ$ module_configuration = "bertos/cfg/cfg_hashtable.h"
  */
@@ -118,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
@@ -138,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
 
 /**
@@ -266,4 +292,10 @@ INLINE HashIterator ht_iter_next(HashIterator h)
        return h;
 }
 
+int hashtable_testSetup(void);
+int hashtable_testRun(void);
+int hashtable_testTearDown(void);
+
+/** \} */ // \defgroup hashtable
+
 #endif /* STRUCT_HASHTABLE_H */