aboutsummaryrefslogtreecommitdiff
path: root/src/ext/ht.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-01-29 15:09:55 -0500
committerNick Mathewson <nickm@torproject.org>2015-01-29 15:09:55 -0500
commit5faa017b86c0ab3ec4ffc22c9ec8d6c1a67d58ea (patch)
treef086834118e3879d422a0d713d5e21744cb50882 /src/ext/ht.h
parenta3de2dfde6a92c0fe7ca755aa7bc1aa046c463a8 (diff)
parent634434514059256235d329d9430f91fb31044fd9 (diff)
downloadtor-5faa017b86c0ab3ec4ffc22c9ec8d6c1a67d58ea.tar.gz
tor-5faa017b86c0ab3ec4ffc22c9ec8d6c1a67d58ea.zip
Merge remote-tracking branch 'public/ticket11737'
Diffstat (limited to 'src/ext/ht.h')
-rw-r--r--src/ext/ht.h24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/ext/ht.h b/src/ext/ht.h
index e7a76196f5..9b3bcaf91b 100644
--- a/src/ext/ht.h
+++ b/src/ext/ht.h
@@ -121,16 +121,24 @@ ht_string_hash(const char *s)
((void)0)
#endif
+#define HT_BUCKET_NUM_(head, field, elm, hashfn) \
+ (HT_ELT_HASH_(elm,field,hashfn) % head->hth_table_length)
+
/* Helper: alias for the bucket containing 'elm'. */
#define HT_BUCKET_(head, field, elm, hashfn) \
- ((head)->hth_table[HT_ELT_HASH_(elm,field,hashfn) \
- % head->hth_table_length])
+ ((head)->hth_table[HT_BUCKET_NUM_(head, field, elm, hashfn)])
#define HT_FOREACH(x, name, head) \
for ((x) = HT_START(name, head); \
(x) != NULL; \
(x) = HT_NEXT(name, head, x))
+#ifndef HT_NDEBUG
+#define HT_ASSERT_(x) tor_assert(x)
+#else
+#define HT_ASSERT_(x) (void)0
+#endif
+
#define HT_PROTOTYPE(name, type, field, hashfn, eqfn) \
int name##_HT_GROW(struct name *ht, unsigned min_capacity); \
void name##_HT_CLEAR(struct name *ht); \
@@ -257,8 +265,11 @@ ht_string_hash(const char *s)
{ \
unsigned b = 0; \
while (b < head->hth_table_length) { \
- if (head->hth_table[b]) \
+ if (head->hth_table[b]) { \
+ HT_ASSERT_(b == \
+ HT_BUCKET_NUM_(head,field,head->hth_table[b],hashfn)); \
return &head->hth_table[b]; \
+ } \
++b; \
} \
return NULL; \
@@ -272,13 +283,18 @@ ht_string_hash(const char *s)
name##_HT_NEXT(struct name *head, struct type **elm) \
{ \
if ((*elm)->field.hte_next) { \
+ HT_ASSERT_(HT_BUCKET_NUM_(head,field,*elm,hashfn) == \
+ HT_BUCKET_NUM_(head,field,(*elm)->field.hte_next,hashfn)); \
return &(*elm)->field.hte_next; \
} else { \
unsigned b = (HT_ELT_HASH_(*elm, field, hashfn) \
% head->hth_table_length)+1; \
while (b < head->hth_table_length) { \
- if (head->hth_table[b]) \
+ if (head->hth_table[b]) { \
+ HT_ASSERT_(b == \
+ HT_BUCKET_NUM_(head,field,head->hth_table[b],hashfn)); \
return &head->hth_table[b]; \
+ } \
++b; \
} \
return NULL; \