summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/conts/map.h32
-rw-r--r--tests/map.c4
2 files changed, 18 insertions, 18 deletions
diff --git a/include/conts/map.h b/include/conts/map.h
index 2060658..571eda2 100644
--- a/include/conts/map.h
+++ b/include/conts/map.h
@@ -1,9 +1,9 @@
-#ifndef MAP_KEY
-#error "Need map key"
+#ifndef MAP_KEY_TYPE
+#error "Need map key type"
#endif
-#ifndef MAP_TYPE
-#error "Need map type"
+#ifndef MAP_VALUE_TYPE
+#error "Need map value type"
#endif
#ifndef MAP_CMP
@@ -72,14 +72,14 @@ enum conts_map_state {
#endif /* CONTS_MAP_H */
-static inline size_t MAP(generic_hash)(MAP_KEY *key)
+static inline size_t MAP(generic_hash)(MAP_KEY_TYPE *key)
{
return conts_map_generic_hash((const char *)key, sizeof(*key));
}
struct MAP_TUPLE {
- MAP_KEY key;
- MAP_TYPE data;
+ MAP_KEY_TYPE key;
+ MAP_VALUE_TYPE data;
};
#define MAP_SPVEC(x) CONTS_JOIN(MAP(spvec), x)
@@ -127,7 +127,7 @@ static inline void MAP(destroy)(struct MAP_ROOT *root)
MAP_SPVEC(destroy)(&root->buf);
}
-static inline MAP_TYPE *MAP(find_hash)(struct MAP_ROOT *root, MAP_KEY key, uint32_t hash)
+static inline MAP_VALUE_TYPE *MAP(find_hash)(struct MAP_ROOT *root, MAP_KEY_TYPE key, uint32_t hash)
{
for (size_t s = MAP_SPVEC(len)(&root->buf); s >= conts_spvec_size(0); s /= 2) {
@@ -160,17 +160,17 @@ static inline MAP_TYPE *MAP(find_hash)(struct MAP_ROOT *root, MAP_KEY key, uint3
return NULL;
}
-static inline MAP_TYPE *MAP(find)(struct MAP_ROOT *root, MAP_KEY key)
+static inline MAP_VALUE_TYPE *MAP(find)(struct MAP_ROOT *root, MAP_KEY_TYPE key)
{
uint32_t hash = MAP_HASH(key) & 0x3fffffff;
return MAP(find_hash)(root, key, hash);
}
-static inline MAP_TYPE *MAP(insert)(struct MAP_ROOT *root, MAP_KEY key, MAP_TYPE data)
+static inline MAP_VALUE_TYPE *MAP(insert)(struct MAP_ROOT *root, MAP_KEY_TYPE key, MAP_VALUE_TYPE data)
{
/* mask top bit away to get 31 bit hash value as used by the nodes */
uint32_t hash = MAP_HASH(key) & 0x3fffffff;
- MAP_TYPE *exists = MAP(find_hash)(root, key, hash);
+ MAP_VALUE_TYPE *exists = MAP(find_hash)(root, key, hash);
if (exists)
return exists;
@@ -219,7 +219,7 @@ static inline MAP_TYPE *MAP(insert)(struct MAP_ROOT *root, MAP_KEY key, MAP_TYPE
return NULL;
}
-static inline void MAP(remove_found)(struct MAP_ROOT *root, MAP_TYPE *data)
+static inline void MAP(remove_found)(struct MAP_ROOT *root, MAP_VALUE_TYPE *data)
{
struct MAP_TUPLE *tuple = CONTAINER_OF(data, struct MAP_TUPLE, data);
struct MAP_NODE *node = CONTAINER_OF(tuple, struct MAP_NODE, t);
@@ -227,9 +227,9 @@ static inline void MAP(remove_found)(struct MAP_ROOT *root, MAP_TYPE *data)
root->n--;
}
-static inline void MAP(remove)(struct MAP_ROOT *root, MAP_KEY key)
+static inline void MAP(remove)(struct MAP_ROOT *root, MAP_KEY_TYPE key)
{
- MAP_TYPE *found = MAP(find)(root, key);
+ MAP_VALUE_TYPE *found = MAP(find)(root, key);
if (!found)
return;
@@ -289,8 +289,8 @@ static inline size_t MAP(len)(struct MAP_ROOT *root)
#undef MAP_TUPLE
#undef MAP_BUCKET
#undef MAP_ROOT
-#undef MAP_KEY
-#undef MAP_TYPE
+#undef MAP_KEY_TYPE
+#undef MAP_VALUE_TYPE
#undef MAP_CMP
#undef MAP_HASH
#undef MAP_NAME
diff --git a/tests/map.c b/tests/map.c
index 9af0b01..195f273 100644
--- a/tests/map.c
+++ b/tests/map.c
@@ -3,8 +3,8 @@
#include "test.h"
/* required defs */
-#define MAP_KEY int
-#define MAP_TYPE int
+#define MAP_KEY_TYPE int
+#define MAP_VALUE_TYPE int
#define MAP_HASH(a) ints_generic_hash(&(a))
#define MAP_CMP(a, b) ((a) - (b))
#define MAP_NAME ints