diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-07-30 16:41:05 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-07-30 16:41:05 +0900 |
| commit | c808f647aa8fde6e1698b25df15d7a93bafe4f42 (patch) | |
| tree | c973696e32582318fe0cd73644fa7f6c89f9a68e /include | |
| parent | c6f62104d350d3da38a8cc9ae8dab36fc1bb9893 (diff) | |
| download | mruby-c808f647aa8fde6e1698b25df15d7a93bafe4f42.tar.gz mruby-c808f647aa8fde6e1698b25df15d7a93bafe4f42.zip | |
allow specifying khash initial size
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby/khash.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/include/mruby/khash.h b/include/mruby/khash.h index a50698fc9..87ba44674 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -17,7 +17,7 @@ extern "C" { typedef uint32_t khint_t; typedef khint_t khiter_t; -#if !defined(MRB_INITIAL_HASH_SIZE) +#ifndef MRB_INITIAL_HASH_SIZE # define MRB_INITIAL_HASH_SIZE 32 #endif @@ -89,13 +89,16 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; h->mask = sz-1; \ h->inc = sz/2-1; \ } \ - kh_##name##_t *kh_init_##name(mrb_state *mrb){ \ + kh_##name##_t *kh_init_##name##_size(mrb_state *mrb, khint_t size) { \ kh_##name##_t *h = (kh_##name##_t*)mrb_calloc(mrb, 1, sizeof(kh_##name##_t)); \ - h->n_buckets = MRB_INITIAL_HASH_SIZE; \ + h->n_buckets = size; \ h->mrb = mrb; \ kh_alloc_##name(h); \ return h; \ } \ + kh_##name##_t *kh_init_##name(mrb_state *mrb){ \ + return kh_init_##name##_size(mrb, MRB_INITIAL_HASH_SIZE); \ + } \ void kh_destroy_##name(kh_##name##_t *h) \ { \ if( h ){ \ |
