commit 9e4500f7dcf19c26dd951bfd08e69b1a77bc303e
parent dba45dcff656af2296096ae60ed01f416ecd64b3
Author: Remy Noulin <loader2x@gmail.com>
Date: Fri, 2 Aug 2019 14:34:30 +0200
remove comparison of key addresses to allow having a struct as a key
In a normal usecase, the address of the key given to the find
macro is different from the address of the key in the hashtable
hashtable.h | 36 ++++++++++++++++++------------------
package.yml | 2 +-
2 files changed, 19 insertions(+), 19 deletions(-)
Diffstat:
2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/hashtable.h b/hashtable.h
@@ -593,7 +593,7 @@ u32 ilog2Hashtable(u32 value);
if (UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
UNIQVAR(moreOrLess) = 0;\
while (UNIQVAR(node) && UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
(name).newNodeInDArray = false;\
(name).res = false; goto UNIQVAR(mreturn);\
}\
@@ -605,7 +605,7 @@ u32 ilog2Hashtable(u32 value);
UNIQVAR(moreOrLess) = 1;\
UNIQVAR(node) = (*(name).list)[UNIQVAR(mhash)][1];\
while (UNIQVAR(node) && UNIQVAR(hash) <= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
(name).newNodeInDArray = false;\
(name).res = false; goto UNIQVAR(mreturn);\
}\
@@ -667,7 +667,7 @@ u32 ilog2Hashtable(u32 value);
if (UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
UNIQVAR(moreOrLess) = 0;\
while (UNIQVAR(node) && UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
vPointer = &(UNIQVAR(node)->value);\
isNew = false;\
(name).newNodeInDArray = false;\
@@ -681,7 +681,7 @@ u32 ilog2Hashtable(u32 value);
UNIQVAR(moreOrLess) = 1;\
UNIQVAR(node) = (*(name).list)[UNIQVAR(mhash)][1];\
while (UNIQVAR(node) && UNIQVAR(hash) <= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
vPointer = &(UNIQVAR(node)->value);\
isNew = false;\
(name).newNodeInDArray = false;\
@@ -733,7 +733,7 @@ u32 ilog2Hashtable(u32 value);
if (UNIQVAR(node)) {\
if (UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
while (UNIQVAR(node) && UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
vPointer = &UNIQVAR(node)->value;\
(name).res = true;\
goto UNIQVAR(mreturn);\
@@ -744,7 +744,7 @@ u32 ilog2Hashtable(u32 value);
else {\
UNIQVAR(node) = (*(name).list)[UNIQVAR(mhash)][1];\
while (UNIQVAR(node) && UNIQVAR(hash) <= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
vPointer = &UNIQVAR(node)->value;\
(name).res = true;\
goto UNIQVAR(mreturn);\
@@ -770,7 +770,7 @@ u32 ilog2Hashtable(u32 value);
if (UNIQVAR(node)) {\
if (UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
while (UNIQVAR(node) && UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
result = UNIQVAR(node)->value;\
(name).res = true;\
goto UNIQVAR(mreturn);\
@@ -781,7 +781,7 @@ u32 ilog2Hashtable(u32 value);
else {\
UNIQVAR(node) = (*(name).list)[UNIQVAR(mhash)][1];\
while (UNIQVAR(node) && UNIQVAR(hash) <= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
result = UNIQVAR(node)->value;\
(name).res = true;\
goto UNIQVAR(mreturn);\
@@ -807,7 +807,7 @@ u32 ilog2Hashtable(u32 value);
if (UNIQVAR(node)) {\
if (UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
while (UNIQVAR(node) && UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
result = UNIQVAR(node)->key;\
(name).res = true;\
goto UNIQVAR(mreturn);\
@@ -818,7 +818,7 @@ u32 ilog2Hashtable(u32 value);
else {\
UNIQVAR(node) = (*(name).list)[UNIQVAR(mhash)][1];\
while (UNIQVAR(node) && UNIQVAR(hash) <= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
result = UNIQVAR(node)->key;\
(name).res = true;\
goto UNIQVAR(mreturn);\
@@ -845,7 +845,7 @@ u32 ilog2Hashtable(u32 value);
if (UNIQVAR(node)) {\
if (UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
while (UNIQVAR(node) && UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
freeNodeFunc(&UNIQVAR(node)->key, &UNIQVAR(node)->value);\
hashtableInternalDelNode(name, UNIQVAR(node), UNIQVAR(mhash), UNIQVAR(prev), 0);\
(name).res = true;\
@@ -858,7 +858,7 @@ u32 ilog2Hashtable(u32 value);
else {\
UNIQVAR(node) = (*(name).list)[UNIQVAR(mhash)][1];\
while (UNIQVAR(node) && UNIQVAR(hash) <= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
freeNodeFunc(&UNIQVAR(node)->key, &UNIQVAR(node)->value);\
hashtableInternalDelNode(name, UNIQVAR(node), UNIQVAR(mhash), UNIQVAR(prev), 1);\
(name).res = true;\
@@ -949,7 +949,7 @@ u32 ilog2Hashtable(u32 value);
if (UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
UNIQVAR(moreOrLess) = 0;\
while (UNIQVAR(node) && UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
nodePointer = UNIQVAR(node);\
(nodeContext).node = nodePointer;\
(nodeContext).prev = UNIQVAR(prev);\
@@ -968,7 +968,7 @@ u32 ilog2Hashtable(u32 value);
UNIQVAR(moreOrLess) = 1;\
UNIQVAR(node) = (*(name).list)[UNIQVAR(mhash)][1];\
while (UNIQVAR(node) && UNIQVAR(hash) <= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
nodePointer = UNIQVAR(node);\
(nodeContext).node = nodePointer;\
(nodeContext).prev = UNIQVAR(prev);\
@@ -1119,7 +1119,7 @@ u32 ilog2Hashtable(u32 value);
if (UNIQVAR(node)) {\
if (UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
while (UNIQVAR(node) && UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
result = UNIQVAR(node);\
(nodeContext).node = UNIQVAR(node);\
(nodeContext).prev = UNIQVAR(prev);\
@@ -1136,7 +1136,7 @@ u32 ilog2Hashtable(u32 value);
else {\
UNIQVAR(node) = (*(name).list)[UNIQVAR(mhash)][1];\
while (UNIQVAR(node) && UNIQVAR(hash) <= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
result = UNIQVAR(node);\
(nodeContext).node = UNIQVAR(node);\
(nodeContext).prev = UNIQVAR(prev);\
@@ -1241,7 +1241,7 @@ u32 ilog2Hashtable(u32 value);
if (UNIQVAR(node)) {\
if (UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
while (UNIQVAR(node) && UNIQVAR(hash) >= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
hashtableInternalUnlink(name, UNIQVAR(node), UNIQVAR(mhash), UNIQVAR(prev), 0);\
result = UNIQVAR(node);\
(name).res = true;\
@@ -1254,7 +1254,7 @@ u32 ilog2Hashtable(u32 value);
else {\
UNIQVAR(node) = (*(name).list)[UNIQVAR(mhash)][1];\
while (UNIQVAR(node) && UNIQVAR(hash) <= UNIQVAR(node)->hash) {\
- if (UNIQVAR(hash) == UNIQVAR(node)->hash && ((k == UNIQVAR(node)->key) || (cmpFunc(k, UNIQVAR(node)->key) == 0))) {\
+ if (UNIQVAR(hash) == UNIQVAR(node)->hash && (cmpFunc(k, UNIQVAR(node)->key) == 0)) {\
hashtableInternalUnlink(name, UNIQVAR(node), UNIQVAR(mhash), UNIQVAR(prev), 1);\
result = UNIQVAR(node);\
(name).res = true;\
diff --git a/package.yml b/package.yml
@@ -1,6 +1,6 @@
---
name: hashtable
- version: 0.0.14
+ version: 0.0.16
description: "hash table macros for creating hash table functions, it supports any type key, value, hash"
bin: ./hashtable.c
cflags: "-O1 -std=gnu11 -fPIC -pipe"