Back to index

tor  0.2.3.18-rc
Defines | Functions
ht.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define HT_HEAD(name, type)
#define HT_INITIALIZER()   { NULL, 0, 0, 0, -1 }
#define HT_ENTRY(type)
#define HT_EMPTY(head)   ((head)->hth_n_entries == 0)
#define HT_SIZE(head)   ((head)->hth_n_entries)
#define HT_MEM_USAGE(head)   (sizeof(*head) + (head)->hth_table_length * sizeof(void*))
#define HT_FIND(name, head, elm)   name##_HT_FIND((head), (elm))
#define HT_INSERT(name, head, elm)   name##_HT_INSERT((head), (elm))
#define HT_REPLACE(name, head, elm)   name##_HT_REPLACE((head), (elm))
#define HT_REMOVE(name, head, elm)   name##_HT_REMOVE((head), (elm))
#define HT_START(name, head)   name##_HT_START(head)
#define HT_NEXT(name, head, elm)   name##_HT_NEXT((head), (elm))
#define HT_NEXT_RMV(name, head, elm)   name##_HT_NEXT_RMV((head), (elm))
#define HT_CLEAR(name, head)   name##_HT_CLEAR(head)
#define HT_INIT(name, head)   name##_HT_INIT(head)
#define HT_SET_HASH_(elm, field, hashfn)   do { (elm)->field.hte_hash = hashfn(elm); } while (0)
#define HT_SET_HASHVAL_(elm, field, val)   do { (elm)->field.hte_hash = (val); } while (0)
#define HT_ELT_HASH_(elm, field, hashfn)   ((elm)->field.hte_hash)
#define HT_BUCKET_(head, field, elm, hashfn)
#define HT_FOREACH(x, name, head)
#define HT_PROTOTYPE(name, type, field, hashfn, eqfn)
#define HT_GENERATE(name, type, field, hashfn, eqfn, load, mallocfn,reallocfn, freefn)
#define HT_FIND_OR_INSERT_(name, field, hashfn, head, eltype, elm, var, y, n)
 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_FOI_INSERT_(field, head, elm, newent, var)

Functions

static INLINE unsigned ht_improve_hash (unsigned h)
static INLINE unsigned ht_string_hash (const char *s)
 Basic string hash function, from Python's str.__hash__()

Define Documentation

#define HT_BUCKET_ (   head,
  field,
  elm,
  hashfn 
)
Value:
((head)->hth_table[HT_ELT_HASH_(elm,field,hashfn)                   \
        % head->hth_table_length])

Definition at line 121 of file ht.h.

#define HT_CLEAR (   name,
  head 
)    name##_HT_CLEAR(head)

Definition at line 59 of file ht.h.

#define HT_ELT_HASH_ (   elm,
  field,
  hashfn 
)    ((elm)->field.hte_hash)

Definition at line 109 of file ht.h.

#define HT_EMPTY (   head)    ((head)->hth_n_entries == 0)

Definition at line 41 of file ht.h.

#define HT_ENTRY (   type)
Value:
struct {                                      \
    struct type *hte_next;                      \
    unsigned hte_hash;                          \
  }

Definition at line 34 of file ht.h.

#define HT_FIND (   name,
  head,
  elm 
)    name##_HT_FIND((head), (elm))

Definition at line 52 of file ht.h.

#define HT_FIND_OR_INSERT_ (   name,
  field,
  hashfn,
  head,
  eltype,
  elm,
  var,
  y,
 
)
Value:
{                                                                     \
    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;                                                                \
    }                                                                   \
  }

Implements an over-optimized "find and insert if absent" block; not meant for direct usage by typical code, or usage outside the critical path.

Definition at line 409 of file ht.h.

#define HT_FOI_INSERT_ (   field,
  head,
  elm,
  newent,
  var 
)
Value:
{                                                         \
    HT_SET_HASHVAL_(newent, field, (elm)->field.hte_hash);  \
    newent->field.hte_next = NULL;                          \
    *var = newent;                                          \
    ++((head)->hth_n_entries);                              \
  }

Definition at line 424 of file ht.h.

#define HT_FOREACH (   x,
  name,
  head 
)
Value:
for ((x) = HT_START(name, head);                \
       (x) != NULL;                               \
       (x) = HT_NEXT(name, head, x))

Definition at line 125 of file ht.h.

#define HT_GENERATE (   name,
  type,
  field,
  hashfn,
  eqfn,
  load,
  mallocfn,
  reallocfn,
  freefn 
)

Definition at line 287 of file ht.h.

#define HT_HEAD (   name,
  type 
)
Value:
struct name {                                                         \
    /* The hash table itself. */                                        \
    struct type **hth_table;                                            \
    /* How long is the hash table? */                                   \
    unsigned hth_table_length;                                          \
    /* How many elements does the table contain? */                     \
    unsigned hth_n_entries;                                             \
    /* How many elements will we allow in the table before resizing it? */ \
    unsigned hth_load_limit;                                            \
    /* Position of hth_table_length in the primes table. */             \
    int hth_prime_idx;                                                  \
  }

Definition at line 11 of file ht.h.

#define HT_INIT (   name,
  head 
)    name##_HT_INIT(head)

Definition at line 60 of file ht.h.

#define HT_INITIALIZER ( )    { NULL, 0, 0, 0, -1 }

Definition at line 25 of file ht.h.

#define HT_INSERT (   name,
  head,
  elm 
)    name##_HT_INSERT((head), (elm))

Definition at line 53 of file ht.h.

#define HT_MEM_USAGE (   head)    (sizeof(*head) + (head)->hth_table_length * sizeof(void*))

Definition at line 49 of file ht.h.

#define HT_NEXT (   name,
  head,
  elm 
)    name##_HT_NEXT((head), (elm))

Definition at line 57 of file ht.h.

#define HT_NEXT_RMV (   name,
  head,
  elm 
)    name##_HT_NEXT_RMV((head), (elm))

Definition at line 58 of file ht.h.

#define HT_PROTOTYPE (   name,
  type,
  field,
  hashfn,
  eqfn 
)

Definition at line 130 of file ht.h.

#define HT_REMOVE (   name,
  head,
  elm 
)    name##_HT_REMOVE((head), (elm))

Definition at line 55 of file ht.h.

#define HT_REPLACE (   name,
  head,
  elm 
)    name##_HT_REPLACE((head), (elm))

Definition at line 54 of file ht.h.

#define HT_SET_HASH_ (   elm,
  field,
  hashfn 
)    do { (elm)->field.hte_hash = hashfn(elm); } while (0)

Definition at line 105 of file ht.h.

#define HT_SET_HASHVAL_ (   elm,
  field,
  val 
)    do { (elm)->field.hte_hash = (val); } while (0)

Definition at line 107 of file ht.h.

#define HT_SIZE (   head)    ((head)->hth_n_entries)

Definition at line 45 of file ht.h.

#define HT_START (   name,
  head 
)    name##_HT_START(head)

Definition at line 56 of file ht.h.


Function Documentation

static INLINE unsigned ht_improve_hash ( unsigned  h) [static]

Definition at line 63 of file ht.h.

{
  /* Aim to protect against poor hash functions by adding logic here
   * - logic taken from java 1.4 hashtable source */
  h += ~(h << 9);
  h ^=  ((h >> 14) | (h << 18)); /* >>> */
  h +=  (h << 4);
  h ^=  ((h >> 10) | (h << 22)); /* >>> */
  return h;
}

Here is the caller graph for this function:

static INLINE unsigned ht_string_hash ( const char *  s) [static]

Basic string hash function, from Python's str.__hash__()

Definition at line 91 of file ht.h.

{
  unsigned h;
  const unsigned char *cp = (const unsigned char *)s;
  h = *cp << 7;
  while (*cp) {
    h = (1000003*h) ^ *cp++;
  }
  /* This conversion truncates the length of the string, but that's ok. */
  h ^= (unsigned)(cp-(const unsigned char*)s);
  return h;
}

Here is the caller graph for this function: