summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-04-07 02:03:43 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-04-07 02:03:43 +0900
commitc5c87424a853445cc04c018fbbd2f21407c3fcf9 (patch)
tree5be952b1887a3dcbbb45fca96e3d47117d89c21b /include
parent4e2ae3e3760fc38192ac1e1f81211f365664cd7c (diff)
parent0d9cc9ccc6fac19f1d99660bdc2014e314e89b43 (diff)
downloadmruby-c5c87424a853445cc04c018fbbd2f21407c3fcf9.tar.gz
mruby-c5c87424a853445cc04c018fbbd2f21407c3fcf9.zip
Merge branch 'master' of github.com:mruby/mruby
Diffstat (limited to 'include')
-rw-r--r--include/mruby/khash.h11
1 files changed, 5 insertions, 6 deletions
diff --git a/include/mruby/khash.h b/include/mruby/khash.h
index 28bbfe434..a2e6ef6f7 100644
--- a/include/mruby/khash.h
+++ b/include/mruby/khash.h
@@ -44,7 +44,6 @@ static const uint8_t __m_either[] = {0x03, 0x0c, 0x30, 0xc0};
v |= v >> 16;\
v++;\
} while (0)
-#define khash_mask(h) ((h)->n_buckets-1)
#define khash_inc(h) ((h)->n_buckets/2-1)
#define khash_upper_bound(h) (UPPER_BOUND((h)->n_buckets))
@@ -133,15 +132,15 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
} \
khint_t kh_get_##name(mrb_state *mrb, kh_##name##_t *h, khkey_t key) \
{ \
- khint_t k = __hash_func(mrb,key) & khash_mask(h); \
+ khint_t k = __hash_func(mrb,key) % h->n_buckets; \
(void)mrb; \
while (!__ac_isempty(h->ed_flags, k)) { \
if (!__ac_isdel(h->ed_flags, k)) { \
if (__hash_equal(mrb,h->keys[k], key)) return k; \
} \
- k = (k+khash_inc(h)) & khash_mask(h); \
+ k = (k+khash_inc(h)) % h->n_buckets; \
} \
- return h->n_buckets; \
+ return kh_end(h); \
} \
void kh_resize_##name(mrb_state *mrb, kh_##name##_t *h, khint_t new_n_buckets) \
{ \
@@ -172,10 +171,10 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
if (h->n_occupied >= khash_upper_bound(h)) { \
kh_resize_##name(mrb, h, h->n_buckets*2); \
} \
- k = __hash_func(mrb,key) & khash_mask(h); \
+ k = __hash_func(mrb,key) % h->n_buckets; \
while (!__ac_iseither(h->ed_flags, k)) { \
if (__hash_equal(mrb,h->keys[k], key)) break; \
- k = (k+khash_inc(h)) & khash_mask(h); \
+ k = (k+khash_inc(h)) % h->n_buckets; \
} \
if (__ac_isempty(h->ed_flags, k)) { \
/* put at empty */ \