aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/container.c8
-rw-r--r--src/common/ht.h72
2 files changed, 40 insertions, 40 deletions
diff --git a/src/common/container.c b/src/common/container.c
index 81a946af3..23ec9d3c8 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -1027,7 +1027,7 @@ digestmap_set(digestmap_t *map, const char *key, void *val)
* the hash table that we do in the unoptimized code above. (Each of
* HT_INSERT and HT_FIND calls HT_SET_HASH and HT_FIND_P.)
*/
- _HT_FIND_OR_INSERT(digestmap_impl, node, digestmap_entry_hash, &(map->head),
+ HT_FIND_OR_INSERT_(digestmap_impl, node, digestmap_entry_hash, &(map->head),
digestmap_entry_t, &search, ptr,
{
/* we found an entry. */
@@ -1041,7 +1041,7 @@ digestmap_set(digestmap_t *map, const char *key, void *val)
tor_malloc_zero(sizeof(digestmap_entry_t));
memcpy(newent->key, key, DIGEST_LEN);
newent->val = val;
- _HT_FOI_INSERT(node, &(map->head), &search, newent, ptr);
+ HT_FOI_INSERT_(node, &(map->head), &search, newent, ptr);
return NULL;
});
#endif
@@ -1354,14 +1354,14 @@ digestmap_free(digestmap_t *map, void (*free_val)(void*))
void
strmap_assert_ok(const strmap_t *map)
{
- tor_assert(!_strmap_impl_HT_REP_IS_BAD(&map->head));
+ tor_assert(!strmap_impl_HT_REP_IS_BAD_(&map->head));
}
/** Fail with an assertion error if anything has gone wrong with the internal
* representation of <b>map</b>. */
void
digestmap_assert_ok(const digestmap_t *map)
{
- tor_assert(!_digestmap_impl_HT_REP_IS_BAD(&map->head));
+ tor_assert(!digestmap_impl_HT_REP_IS_BAD_(&map->head));
}
/** Return true iff <b>map</b> has no entries. */
diff --git a/src/common/ht.h b/src/common/ht.h
index 12977cbb7..f7d4ce17c 100644
--- a/src/common/ht.h
+++ b/src/common/ht.h
@@ -102,24 +102,24 @@ ht_string_hash(const char *s)
}
#ifndef HT_NO_CACHE_HASH_VALUES
-#define _HT_SET_HASH(elm, field, hashfn) \
+#define HT_SET_HASH_(elm, field, hashfn) \
do { (elm)->field.hte_hash = hashfn(elm); } while (0)
-#define _HT_SET_HASHVAL(elm, field, val) \
+#define HT_SET_HASHVAL_(elm, field, val) \
do { (elm)->field.hte_hash = (val); } while (0)
-#define _HT_ELT_HASH(elm, field, hashfn) \
+#define HT_ELT_HASH_(elm, field, hashfn) \
((elm)->field.hte_hash)
#else
-#define _HT_SET_HASH(elm, field, hashfn) \
+#define HT_SET_HASH_(elm, field, hashfn) \
((void)0)
-#define _HT_ELT_HASH(elm, field, hashfn) \
+#define HT_ELT_HASH_(elm, field, hashfn) \
(hashfn(elm))
-#define _HT_SET_HASHVAL(elm, field, val) \
+#define HT_SET_HASHVAL_(elm, field, val) \
((void)0)
#endif
/* 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])
+#define HT_BUCKET_(head, field, elm, hashfn) \
+ ((head)->hth_table[HT_ELT_HASH_(elm,field,hashfn) % head->hth_table_length])
#define HT_FOREACH(x, name, head) \
for ((x) = HT_START(name, head); \
@@ -129,7 +129,7 @@ ht_string_hash(const char *s)
#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); \
- int _##name##_HT_REP_IS_BAD(const struct name *ht); \
+ int name##_HT_REP_IS_BAD_(const struct name *ht); \
static INLINE void \
name##_HT_INIT(struct name *head) { \
head->hth_table_length = 0; \
@@ -141,12 +141,12 @@ ht_string_hash(const char *s)
/* Helper: returns a pointer to the right location in the table \
* 'head' to find or insert the element 'elm'. */ \
static INLINE struct type ** \
- _##name##_HT_FIND_P(struct name *head, struct type *elm) \
+ name##_HT_FIND_P_(struct name *head, struct type *elm) \
{ \
struct type **p; \
if (!head->hth_table) \
return NULL; \
- p = &_HT_BUCKET(head, field, elm, hashfn); \
+ p = &HT_BUCKET_(head, field, elm, hashfn); \
while (*p) { \
if (eqfn(*p, elm)) \
return p; \
@@ -161,8 +161,8 @@ ht_string_hash(const char *s)
{ \
struct type **p; \
struct name *h = (struct name *) head; \
- _HT_SET_HASH(elm, field, hashfn); \
- p = _##name##_HT_FIND_P(h, elm); \
+ HT_SET_HASH_(elm, field, hashfn); \
+ p = name##_HT_FIND_P_(h, elm); \
return p ? *p : NULL; \
} \
/* Insert the element 'elm' into the table 'head'. Do not call this \
@@ -174,8 +174,8 @@ ht_string_hash(const char *s)
if (!head->hth_table || head->hth_n_entries >= head->hth_load_limit) \
name##_HT_GROW(head, head->hth_n_entries+1); \
++head->hth_n_entries; \
- _HT_SET_HASH(elm, field, hashfn); \
- p = &_HT_BUCKET(head, field, elm, hashfn); \
+ HT_SET_HASH_(elm, field, hashfn); \
+ p = &HT_BUCKET_(head, field, elm, hashfn); \
elm->field.hte_next = *p; \
*p = elm; \
} \
@@ -188,8 +188,8 @@ ht_string_hash(const char *s)
struct type **p, *r; \
if (!head->hth_table || head->hth_n_entries >= head->hth_load_limit) \
name##_HT_GROW(head, head->hth_n_entries+1); \
- _HT_SET_HASH(elm, field, hashfn); \
- p = _##name##_HT_FIND_P(head, elm); \
+ HT_SET_HASH_(elm, field, hashfn); \
+ p = name##_HT_FIND_P_(head, elm); \
r = *p; \
*p = elm; \
if (r && (r!=elm)) { \
@@ -207,8 +207,8 @@ ht_string_hash(const char *s)
name##_HT_REMOVE(struct name *head, struct type *elm) \
{ \
struct type **p, *r; \
- _HT_SET_HASH(elm, field, hashfn); \
- p = _##name##_HT_FIND_P(head,elm); \
+ HT_SET_HASH_(elm, field, hashfn); \
+ p = name##_HT_FIND_P_(head,elm); \
if (!p || !*p) \
return NULL; \
r = *p; \
@@ -269,7 +269,7 @@ ht_string_hash(const char *s)
if ((*elm)->field.hte_next) { \
return &(*elm)->field.hte_next; \
} else { \
- unsigned b = (_HT_ELT_HASH(*elm, field, hashfn) % head->hth_table_length)+1; \
+ unsigned b = (HT_ELT_HASH_(*elm, field, hashfn) % head->hth_table_length)+1; \
while (b < head->hth_table_length) { \
if (head->hth_table[b]) \
return &head->hth_table[b]; \
@@ -281,7 +281,7 @@ ht_string_hash(const char *s)
static INLINE struct type ** \
name##_HT_NEXT_RMV(struct name *head, struct type **elm) \
{ \
- unsigned h = _HT_ELT_HASH(*elm, field, hashfn); \
+ unsigned h = HT_ELT_HASH_(*elm, field, hashfn); \
*elm = (*elm)->field.hte_next; \
--head->hth_n_entries; \
if (*elm) { \
@@ -338,7 +338,7 @@ ht_string_hash(const char *s)
elm = head->hth_table[b]; \
while (elm) { \
next = elm->field.hte_next; \
- b2 = _HT_ELT_HASH(elm, field, hashfn) % new_len; \
+ b2 = HT_ELT_HASH_(elm, field, hashfn) % new_len; \
elm->field.hte_next = new_table[b2]; \
new_table[b2] = elm; \
elm = next; \
@@ -356,7 +356,7 @@ ht_string_hash(const char *s)
for (b=0; b < head->hth_table_length; ++b) { \
struct type *e, **pE; \
for (pE = &new_table[b], e = *pE; e != NULL; e = *pE) { \
- b2 = _HT_ELT_HASH(e, field, hashfn) % new_len; \
+ b2 = HT_ELT_HASH_(e, field, hashfn) % new_len; \
if (b2 == b) { \
pE = &e->field.hte_next; \
} else { \
@@ -386,7 +386,7 @@ ht_string_hash(const char *s)
/* Debugging helper: return false iff the representation of 'head' is \
* internally consistent. */ \
int \
- _##name##_HT_REP_IS_BAD(const struct name *head) \
+ name##_HT_REP_IS_BAD_(const struct name *head) \
{ \
unsigned n, i; \
struct type *elm; \
@@ -408,9 +408,9 @@ ht_string_hash(const char *s)
return 5; \
for (n = i = 0; i < head->hth_table_length; ++i) { \
for (elm = head->hth_table[i]; elm; elm = elm->field.hte_next) { \
- if (_HT_ELT_HASH(elm, field, hashfn) != hashfn(elm)) \
+ if (HT_ELT_HASH_(elm, field, hashfn) != hashfn(elm)) \
return 1000 + i; \
- if ((_HT_ELT_HASH(elm, field, hashfn) % head->hth_table_length) != i) \
+ if ((HT_ELT_HASH_(elm, field, hashfn) % head->hth_table_length) != i) \
return 10000 + i; \
++n; \
} \
@@ -423,24 +423,24 @@ ht_string_hash(const char *s)
/** Implements an over-optimized "find and insert if absent" block;
* not meant for direct usage by typical code, or usage outside the critical
* path.*/
-#define _HT_FIND_OR_INSERT(name, field, hashfn, head, eltype, elm, var, y, n) \
+#define HT_FIND_OR_INSERT_(name, field, hashfn, head, eltype, elm, var, y, n) \
{ \
- struct name *_##var##_head = head; \
- struct eltype **var; \
- if (!_##var##_head->hth_table || \
- _##var##_head->hth_n_entries >= _##var##_head->hth_load_limit) \
- name##_HT_GROW(_##var##_head, _##var##_head->hth_n_entries+1); \
- _HT_SET_HASH((elm), field, hashfn); \
- var = _##name##_HT_FIND_P(_##var##_head, (elm)); \
+ struct name *var##_head_ = head; \
+ struct eltype **var; \
+ if (!var##_head_->hth_table || \
+ var##_head_->hth_n_entries >= var##_head_->hth_load_limit) \
+ name##_HT_GROW(var##_head_, var##_head_->hth_n_entries+1); \
+ HT_SET_HASH_((elm), field, hashfn); \
+ var = name##_HT_FIND_P_(var##_head_, (elm)); \
if (*var) { \
y; \
} else { \
n; \
} \
}
-#define _HT_FOI_INSERT(field, head, elm, newent, var) \
+#define HT_FOI_INSERT_(field, head, elm, newent, var) \
{ \
- _HT_SET_HASHVAL(newent, field, (elm)->field.hte_hash); \
+ HT_SET_HASHVAL_(newent, field, (elm)->field.hte_hash); \
newent->field.hte_next = NULL; \
*var = newent; \
++((head)->hth_n_entries); \