Make ht.h conform to Tor's code style again

When porting over changes from libevent, a bunch of tabs and a couple of
long lines got introduced.
This commit is contained in:
Sebastian Hahn 2012-02-14 11:13:06 +01:00
parent a31fb42d2e
commit efcdc930fb

View File

@ -103,23 +103,24 @@ ht_string_hash(const char *s)
#ifndef HT_NO_CACHE_HASH_VALUES #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) 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) 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) ((elm)->field.hte_hash)
#else #else
#define HT_SET_HASH_(elm, field, hashfn) \ #define HT_SET_HASH_(elm, field, hashfn) \
((void)0) ((void)0)
#define HT_ELT_HASH_(elm, field, hashfn) \ #define HT_ELT_HASH_(elm, field, hashfn) \
(hashfn(elm)) (hashfn(elm))
#define HT_SET_HASHVAL_(elm, field, val) \ #define HT_SET_HASHVAL_(elm, field, val) \
((void)0) ((void)0)
#endif #endif
/* Helper: alias for the bucket containing 'elm'. */ /* Helper: alias for the bucket containing 'elm'. */
#define HT_BUCKET_(head, field, elm, hashfn) \ #define HT_BUCKET_(head, field, elm, hashfn) \
((head)->hth_table[HT_ELT_HASH_(elm,field,hashfn) % head->hth_table_length]) ((head)->hth_table[HT_ELT_HASH_(elm,field,hashfn) \
% head->hth_table_length])
#define HT_FOREACH(x, name, head) \ #define HT_FOREACH(x, name, head) \
for ((x) = HT_START(name, head); \ for ((x) = HT_START(name, head); \
@ -129,7 +130,7 @@ ht_string_hash(const char *s)
#define HT_PROTOTYPE(name, type, field, hashfn, eqfn) \ #define HT_PROTOTYPE(name, type, field, hashfn, eqfn) \
int name##_HT_GROW(struct name *ht, unsigned min_capacity); \ int name##_HT_GROW(struct name *ht, unsigned min_capacity); \
void name##_HT_CLEAR(struct name *ht); \ 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 \ static INLINE void \
name##_HT_INIT(struct name *head) { \ name##_HT_INIT(struct name *head) { \
head->hth_table_length = 0; \ head->hth_table_length = 0; \
@ -141,12 +142,12 @@ ht_string_hash(const char *s)
/* Helper: returns a pointer to the right location in the table \ /* Helper: returns a pointer to the right location in the table \
* 'head' to find or insert the element 'elm'. */ \ * 'head' to find or insert the element 'elm'. */ \
static INLINE struct type ** \ 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; \ struct type **p; \
if (!head->hth_table) \ if (!head->hth_table) \
return NULL; \ return NULL; \
p = &HT_BUCKET_(head, field, elm, hashfn); \ p = &HT_BUCKET_(head, field, elm, hashfn); \
while (*p) { \ while (*p) { \
if (eqfn(*p, elm)) \ if (eqfn(*p, elm)) \
return p; \ return p; \
@ -162,7 +163,7 @@ ht_string_hash(const char *s)
struct type **p; \ struct type **p; \
struct name *h = (struct name *) head; \ struct name *h = (struct name *) head; \
HT_SET_HASH_(elm, field, hashfn); \ HT_SET_HASH_(elm, field, hashfn); \
p = name##_HT_FIND_P_(h, elm); \ p = name##_HT_FIND_P_(h, elm); \
return p ? *p : NULL; \ return p ? *p : NULL; \
} \ } \
/* Insert the element 'elm' into the table 'head'. Do not call this \ /* Insert the element 'elm' into the table 'head'. Do not call this \
@ -175,7 +176,7 @@ ht_string_hash(const char *s)
name##_HT_GROW(head, head->hth_n_entries+1); \ name##_HT_GROW(head, head->hth_n_entries+1); \
++head->hth_n_entries; \ ++head->hth_n_entries; \
HT_SET_HASH_(elm, field, hashfn); \ HT_SET_HASH_(elm, field, hashfn); \
p = &HT_BUCKET_(head, field, elm, hashfn); \ p = &HT_BUCKET_(head, field, elm, hashfn); \
elm->field.hte_next = *p; \ elm->field.hte_next = *p; \
*p = elm; \ *p = elm; \
} \ } \
@ -189,7 +190,7 @@ ht_string_hash(const char *s)
if (!head->hth_table || head->hth_n_entries >= head->hth_load_limit) \ if (!head->hth_table || head->hth_n_entries >= head->hth_load_limit) \
name##_HT_GROW(head, head->hth_n_entries+1); \ name##_HT_GROW(head, head->hth_n_entries+1); \
HT_SET_HASH_(elm, field, hashfn); \ HT_SET_HASH_(elm, field, hashfn); \
p = name##_HT_FIND_P_(head, elm); \ p = name##_HT_FIND_P_(head, elm); \
r = *p; \ r = *p; \
*p = elm; \ *p = elm; \
if (r && (r!=elm)) { \ if (r && (r!=elm)) { \
@ -208,7 +209,7 @@ ht_string_hash(const char *s)
{ \ { \
struct type **p, *r; \ struct type **p, *r; \
HT_SET_HASH_(elm, field, hashfn); \ HT_SET_HASH_(elm, field, hashfn); \
p = name##_HT_FIND_P_(head,elm); \ p = name##_HT_FIND_P_(head,elm); \
if (!p || !*p) \ if (!p || !*p) \
return NULL; \ return NULL; \
r = *p; \ r = *p; \
@ -269,7 +270,8 @@ ht_string_hash(const char *s)
if ((*elm)->field.hte_next) { \ if ((*elm)->field.hte_next) { \
return &(*elm)->field.hte_next; \ return &(*elm)->field.hte_next; \
} else { \ } 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) { \ while (b < head->hth_table_length) { \
if (head->hth_table[b]) \ if (head->hth_table[b]) \
return &head->hth_table[b]; \ return &head->hth_table[b]; \
@ -281,7 +283,7 @@ ht_string_hash(const char *s)
static INLINE struct type ** \ static INLINE struct type ** \
name##_HT_NEXT_RMV(struct name *head, struct type **elm) \ 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; \ *elm = (*elm)->field.hte_next; \
--head->hth_n_entries; \ --head->hth_n_entries; \
if (*elm) { \ if (*elm) { \
@ -386,7 +388,7 @@ ht_string_hash(const char *s)
/* Debugging helper: return false iff the representation of 'head' is \ /* Debugging helper: return false iff the representation of 'head' is \
* internally consistent. */ \ * internally consistent. */ \
int \ int \
name##_HT_REP_IS_BAD_(const struct name *head) \ name##_HT_REP_IS_BAD_(const struct name *head) \
{ \ { \
unsigned n, i; \ unsigned n, i; \
struct type *elm; \ struct type *elm; \
@ -408,7 +410,7 @@ ht_string_hash(const char *s)
return 5; \ return 5; \
for (n = i = 0; i < head->hth_table_length; ++i) { \ for (n = i = 0; i < head->hth_table_length; ++i) { \
for (elm = head->hth_table[i]; elm; elm = elm->field.hte_next) { \ 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; \ 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; \ return 10000 + i; \