Commit b1cc715b authored by Masaki Muranaka's avatar Masaki Muranaka

MRB_INITIAL_HASH_SIZE : Make the initial hash size configurable.

parent 14410d13
...@@ -17,7 +17,10 @@ extern "C" { ...@@ -17,7 +17,10 @@ extern "C" {
typedef uint32_t khint_t; typedef uint32_t khint_t;
typedef khint_t khiter_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)) #define UPPER_BOUND(x) ((x)>>2|(x>>1))
//extern uint8_t __m[]; //extern uint8_t __m[];
...@@ -88,7 +91,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; ...@@ -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 *kh_init_##name(mrb_state *mrb){ \
kh_##name##_t *h = (kh_##name##_t*)mrb_calloc(mrb, 1, sizeof(kh_##name##_t)); \ 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; \ h->mrb = mrb; \
kh_alloc_##name(h); \ kh_alloc_##name(h); \
return h; \ return h; \
...@@ -123,12 +126,14 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; ...@@ -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) \ void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
{ \ { \
if( new_n_buckets<INITIAL_HASH_SIZE ){ \ if( new_n_buckets<MRB_INITIAL_HASH_SIZE ){ \
new_n_buckets = INITIAL_HASH_SIZE; \ new_n_buckets = MRB_INITIAL_HASH_SIZE; \
} else { \ } else { \
khint_t limit = new_n_buckets; \ khint_t limit = new_n_buckets; \
new_n_buckets = INITIAL_HASH_SIZE; \ new_n_buckets = MRB_INITIAL_HASH_SIZE; \
while( new_n_buckets < limit ) new_n_buckets *= 2; \ while( new_n_buckets < limit ) { \
new_n_buckets *= 2; \
} \
} \ } \
{ \ { \
uint8_t *old_e_flags = h->e_flags; \ 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