p2  0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
khash.h File Reference

klib hash table library based on double hashing http://en.wikipedia.org/wiki/Double_hashing . More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+ Include dependency graph for khash.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define AC_VERSION_KHASH_H   "0.2.6p"
 
#define KHASH_FLAG(name, h, i)   *(uint32_t *)(h->table + kh_flag_##name(i))
 
#define KHASH_KEY(name, h, i)   *kh_key_##name(h, i)
 
#define KHASH_VAL(name, h, i)   *kh_val_##name(h, i)
 
#define __ac_isempty(flag, i)   ((flag[i>>4]>>((i&0xfU)<<1))&2)
 
#define __ac_set_isempty_false(flag, i)   (flag[i>>4]&=~(2ul<<((i&0xfU)<<1)))
 
#define __kh_isempty(name, h, i)   ((KHASH_FLAG(name, h, i)>>((i&0xfU)<<1))&2)
 
#define __kh_isdel(name, h, i)   ((KHASH_FLAG(name, h, i)>>((i&0xfU)<<1))&1)
 
#define __kh_iseither(name, h, i)   ((KHASH_FLAG(name, h, i)>>((i&0xfU)<<1))&3)
 
#define __kh_set_isdel_false(name, h, i)   (KHASH_FLAG(name, h, i)&=~(1ul<<((i&0xfU)<<1)))
 
#define __kh_set_isempty_false(name, h, i)   (KHASH_FLAG(name, h, i)&=~(2ul<<((i&0xfU)<<1)))
 
#define __kh_set_isboth_false(name, h, i)   (KHASH_FLAG(name, h, i)&=~(3ul<<((i&0xfU)<<1)))
 
#define __kh_set_isdel_true(name, h, i)   (KHASH_FLAG(name, h, i)|=1ul<<((i&0xfU)<<1))
 
#define __ac_inc(k)   ((k) | 1)
 
#define __ac_fsize(m)   ((m) < 16? 1 : (m)>>4)
 
#define PN_TABLE_HEADER   PN_SIZE n_buckets, size, n_occupied, upper_bound
 
#define KHASH_INIT(name, kh_t, khkey_t, khval_t, khkey_t2, kh_is_map, __hash_func, __hash_equal, __hash_func2, __hash_equal2)
 
#define kh_int_hash_func(key)   (uint32_t)(key)
 
#define kh_int_hash_equal(a, b)   (a == b)
 
#define kh_int64_hash_func(key)   (uint32_t)((key)>>33^(key)^(key)<<11)
 
#define kh_int64_hash_equal(a, b)   (a == b)
 
#define kh_pnstr_hash_func(key)   __luaS_hash_string(PN_STR_PTR(key))
 
#define kh_pnstr_hash_equal(a, b)   (strcmp(PN_STR_PTR(a), PN_STR_PTR(b)) == 0)
 
#define kh_str_hash_func(key)   __luaS_hash_string(key)
 
#define kh_str_hash_equal(a, b)   (strcmp(PN_STR_PTR(a), b) == 0)
 
#define kh_pn_hash_func(key)   (uint32_t)PN_UNIQ(key)
 
#define kh_pn_hash_equal(a, b)   (a == b)
 
#define kh_int_hash_func2(k)   __ac_Wang_hash((khint_t)key)
 
#define kh_clear(name, h)   kh_clear_##name(P, h)
 
#define kh_resize(name, h, s)   h = kh_resize_##name(P, h, s)
 
#define kh_put(name, h, k, r)   kh_put_##name(P, h, k, r)
 
#define kh_get(name, h, k)   kh_get_##name(P, h, k)
 
#define kh_del(name, h, k)   kh_del_##name(P, h, k)
 
#define kh_exist(name, h, x)   (!__kh_iseither(name, (h), (x)))
 
#define kh_key(name, h, x)   (KHASH_KEY(name, h, x))
 
#define kh_val(name, h, x)   (KHASH_VAL(name, h, x))
 
#define kh_begin(h)   (khint_t)(0)
 
#define kh_end(h)   ((h)->n_buckets)
 
#define kh_size(h)   ((h)->size)
 
#define kh_n_buckets(h)   ((h)->n_buckets)
 
#define kh_mem(name, h)   (((struct PNTable *)h)->n_buckets == 0 ? 0 : kh_size_##name(((struct PNTable *)h)->n_buckets))
 
#define KHASH_MAP_INIT_STR(name, t)
 
#define KHASH_MAP_INIT_PN(name, t)
 

Typedefs

typedef uint32_t khint_t
 
typedef khint_t khiter_t
 

Functions

static khint_t __kh_X31_hash_string (const char *s)
 
static khint_t __luaS_hash_string (const char *s)
 
static khint_t __ac_Wang_hash (khint_t key)
 

Variables

static const double __kh_HASH_UPPER = 0.77
 

Detailed Description

klib hash table library based on double hashing http://en.wikipedia.org/wiki/Double_hashing .

modified to suit potion's gc. https://github.com/attractivechaos/klib

See also
core/table.h

Definition in file khash.h.

Macro Definition Documentation

#define AC_VERSION_KHASH_H   "0.2.6p"

Definition at line 14 of file khash.h.

#define KHASH_FLAG (   name,
  h,
 
)    *(uint32_t *)(h->table + kh_flag_##name(i))

Definition at line 23 of file khash.h.

#define KHASH_KEY (   name,
  h,
 
)    *kh_key_##name(h, i)

Definition at line 24 of file khash.h.

#define KHASH_VAL (   name,
  h,
 
)    *kh_val_##name(h, i)

Definition at line 25 of file khash.h.

#define __ac_isempty (   flag,
 
)    ((flag[i>>4]>>((i&0xfU)<<1))&2)

Definition at line 27 of file khash.h.

#define __ac_set_isempty_false (   flag,
 
)    (flag[i>>4]&=~(2ul<<((i&0xfU)<<1)))

Definition at line 28 of file khash.h.

#define __kh_isempty (   name,
  h,
 
)    ((KHASH_FLAG(name, h, i)>>((i&0xfU)<<1))&2)

Definition at line 29 of file khash.h.

#define __kh_isdel (   name,
  h,
 
)    ((KHASH_FLAG(name, h, i)>>((i&0xfU)<<1))&1)

Definition at line 30 of file khash.h.

#define __kh_iseither (   name,
  h,
 
)    ((KHASH_FLAG(name, h, i)>>((i&0xfU)<<1))&3)

Definition at line 31 of file khash.h.

#define __kh_set_isdel_false (   name,
  h,
 
)    (KHASH_FLAG(name, h, i)&=~(1ul<<((i&0xfU)<<1)))

Definition at line 32 of file khash.h.

#define __kh_set_isempty_false (   name,
  h,
 
)    (KHASH_FLAG(name, h, i)&=~(2ul<<((i&0xfU)<<1)))

Definition at line 33 of file khash.h.

#define __kh_set_isboth_false (   name,
  h,
 
)    (KHASH_FLAG(name, h, i)&=~(3ul<<((i&0xfU)<<1)))

Definition at line 34 of file khash.h.

#define __kh_set_isdel_true (   name,
  h,
 
)    (KHASH_FLAG(name, h, i)|=1ul<<((i&0xfU)<<1))

Definition at line 35 of file khash.h.

#define __ac_inc (   k)    ((k) | 1)

Definition at line 37 of file khash.h.

#define __ac_fsize (   m)    ((m) < 16? 1 : (m)>>4)

Definition at line 38 of file khash.h.

#define PN_TABLE_HEADER   PN_SIZE n_buckets, size, n_occupied, upper_bound

Definition at line 42 of file khash.h.

#define KHASH_INIT (   name,
  kh_t,
  khkey_t,
  khval_t,
  khkey_t2,
  kh_is_map,
  __hash_func,
  __hash_equal,
  __hash_func2,
  __hash_equal2 
)

Definition at line 44 of file khash.h.

#define kh_int_hash_func (   key)    (uint32_t)(key)

Definition at line 176 of file khash.h.

#define kh_int_hash_equal (   a,
 
)    (a == b)

Definition at line 177 of file khash.h.

#define kh_int64_hash_func (   key)    (uint32_t)((key)>>33^(key)^(key)<<11)

Definition at line 178 of file khash.h.

#define kh_int64_hash_equal (   a,
 
)    (a == b)

Definition at line 179 of file khash.h.

#define kh_pnstr_hash_func (   key)    __luaS_hash_string(PN_STR_PTR(key))

Definition at line 196 of file khash.h.

#define kh_pnstr_hash_equal (   a,
 
)    (strcmp(PN_STR_PTR(a), PN_STR_PTR(b)) == 0)

Definition at line 197 of file khash.h.

#define kh_str_hash_func (   key)    __luaS_hash_string(key)

Definition at line 198 of file khash.h.

#define kh_str_hash_equal (   a,
 
)    (strcmp(PN_STR_PTR(a), b) == 0)

Definition at line 199 of file khash.h.

#define kh_pn_hash_func (   key)    (uint32_t)PN_UNIQ(key)

Definition at line 200 of file khash.h.

#define kh_pn_hash_equal (   a,
 
)    (a == b)

Definition at line 201 of file khash.h.

#define kh_int_hash_func2 (   k)    __ac_Wang_hash((khint_t)key)

Definition at line 213 of file khash.h.

#define kh_clear (   name,
 
)    kh_clear_##name(P, h)

Definition at line 219 of file khash.h.

#define kh_resize (   name,
  h,
 
)    h = kh_resize_##name(P, h, s)

Definition at line 220 of file khash.h.

#define kh_put (   name,
  h,
  k,
 
)    kh_put_##name(P, h, k, r)

Definition at line 221 of file khash.h.

#define kh_get (   name,
  h,
 
)    kh_get_##name(P, h, k)

Definition at line 222 of file khash.h.

#define kh_del (   name,
  h,
 
)    kh_del_##name(P, h, k)

Definition at line 223 of file khash.h.

#define kh_exist (   name,
  h,
 
)    (!__kh_iseither(name, (h), (x)))

Definition at line 225 of file khash.h.

#define kh_key (   name,
  h,
 
)    (KHASH_KEY(name, h, x))

Definition at line 226 of file khash.h.

#define kh_val (   name,
  h,
 
)    (KHASH_VAL(name, h, x))

Definition at line 227 of file khash.h.

#define kh_begin (   h)    (khint_t)(0)

Definition at line 228 of file khash.h.

#define kh_end (   h)    ((h)->n_buckets)

Definition at line 229 of file khash.h.

#define kh_size (   h)    ((h)->size)

Definition at line 230 of file khash.h.

#define kh_n_buckets (   h)    ((h)->n_buckets)

Definition at line 231 of file khash.h.

#define kh_mem (   name,
 
)    (((struct PNTable *)h)->n_buckets == 0 ? 0 : kh_size_##name(((struct PNTable *)h)->n_buckets))

Definition at line 232 of file khash.h.

#define KHASH_MAP_INIT_STR (   name,
 
)
Value:
KHASH_INIT(name, t, _PN, PNUniq, const char *, 0, kh_pnstr_hash_func, \
#define KHASH_INIT(name, kh_t, khkey_t, khval_t, khkey_t2, kh_is_map, __hash_func, __hash_equal, __hash_func2, __hash_equal2)
Definition: khash.h:44
unsigned long _PN
Definition: potion.h:78
unsigned int PNUniq
Definition: potion.h:79
#define kh_str_hash_equal(a, b)
Definition: khash.h:199
#define kh_pnstr_hash_equal(a, b)
Definition: khash.h:197
#define kh_str_hash_func(key)
Definition: khash.h:198
#define kh_pnstr_hash_func(key)
Definition: khash.h:196
const char * name
Definition: compile.c:30

Definition at line 234 of file khash.h.

#define KHASH_MAP_INIT_PN (   name,
 
)
Value:
#define KHASH_INIT(name, kh_t, khkey_t, khval_t, khkey_t2, kh_is_map, __hash_func, __hash_equal, __hash_func2, __hash_equal2)
Definition: khash.h:44
unsigned long _PN
Definition: potion.h:78
#define kh_pn_hash_equal(a, b)
Definition: khash.h:201
#define kh_pn_hash_func(key)
Definition: khash.h:200
const char * name
Definition: compile.c:30

Definition at line 238 of file khash.h.

Typedef Documentation

typedef uint32_t khint_t

Definition at line 20 of file khash.h.

typedef khint_t khiter_t

Definition at line 21 of file khash.h.

Function Documentation

static khint_t __kh_X31_hash_string ( const char *  s)
inlinestatic

Definition at line 180 of file khash.h.

static khint_t __luaS_hash_string ( const char *  s)
inlinestatic

Definition at line 186 of file khash.h.

static khint_t __ac_Wang_hash ( khint_t  key)
inlinestatic

Definition at line 203 of file khash.h.

Variable Documentation

const double __kh_HASH_UPPER = 0.77
static

Definition at line 40 of file khash.h.