Commit c6f62104 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #409 from monaka/pr-configurable-initial_hash_size

MRB_INITIAL_HASH_SIZE : Make the initial hash size configurable.
parents 14410d13 b1cc715b
......@@ -17,7 +17,10 @@ extern "C" {
typedef uint32_t khint_t;
typedef khint_t khiter_t;
#define INITIAL_HASH_SIZE 32
#if !defined(MRB_INITIAL_HASH_SIZE)
# define MRB_INITIAL_HASH_SIZE 32
#endif
#define UPPER_BOUND(x) ((x)>>2|(x>>1))
//extern uint8_t __m[];
......@@ -88,7 +91,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
} \
kh_##name##_t *kh_init_##name(mrb_state *mrb){ \
kh_##name##_t *h = (kh_##name##_t*)mrb_calloc(mrb, 1, sizeof(kh_##name##_t)); \
h->n_buckets = INITIAL_HASH_SIZE; \
h->n_buckets = MRB_INITIAL_HASH_SIZE; \
h->mrb = mrb; \
kh_alloc_##name(h); \
return h; \
......@@ -123,12 +126,14 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
} \
void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
{ \
if( new_n_buckets<INITIAL_HASH_SIZE ){ \
new_n_buckets = INITIAL_HASH_SIZE; \
if( new_n_buckets<MRB_INITIAL_HASH_SIZE ){ \
new_n_buckets = MRB_INITIAL_HASH_SIZE; \
} else { \
khint_t limit = new_n_buckets; \
new_n_buckets = INITIAL_HASH_SIZE; \
while( new_n_buckets < limit ) new_n_buckets *= 2; \
new_n_buckets = MRB_INITIAL_HASH_SIZE; \
while( new_n_buckets < limit ) { \
new_n_buckets *= 2; \
} \
} \
{ \
uint8_t *old_e_flags = h->e_flags; \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment