From d1e5e8158087a641d76762684c21e44c3fa0bbff Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jul 2015 09:13:19 +0900 Subject: [PATCH] khash doesn't need to require int32 --- extlib/benz/codegen.c | 13 ++++++------ extlib/benz/include/picrin/khash.h | 32 ++++++++---------------------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/extlib/benz/codegen.c b/extlib/benz/codegen.c index 987124d2..5f0eb014 100644 --- a/extlib/benz/codegen.c +++ b/extlib/benz/codegen.c @@ -435,6 +435,7 @@ analyze_lambda(pic_state *pic, analyze_scope *up, pic_value form) pic_value rest = pic_undef_value(); pic_vec *args, *locals, *captures; size_t i, j; + khiter_t it; formals = pic_list_ref(pic, form, 1); body = pic_list_ref(pic, form, 2); @@ -455,16 +456,16 @@ analyze_lambda(pic_state *pic, analyze_scope *up, pic_value form) } locals = pic_make_vec(pic, kh_size(&scope->locals)); - for (i = kh_begin(&scope->locals), j = 0; i < kh_end(&scope->locals); ++i) { - if (kh_exist(&scope->locals, i)) { - locals->data[j++] = pic_obj_value(kh_key(&scope->locals, i)); + for (it = kh_begin(&scope->locals), j = 0; it < kh_end(&scope->locals); ++it) { + if (kh_exist(&scope->locals, it)) { + locals->data[j++] = pic_obj_value(kh_key(&scope->locals, it)); } } captures = pic_make_vec(pic, kh_size(&scope->captures)); - for (i = kh_begin(&scope->captures), j = 0; i < kh_end(&scope->captures); ++i) { - if (kh_exist(&scope->captures, i)) { - captures->data[j++] = pic_obj_value(kh_key(&scope->captures, i)); + for (it = kh_begin(&scope->captures), j = 0; it < kh_end(&scope->captures); ++it) { + if (kh_exist(&scope->captures, it)) { + captures->data[j++] = pic_obj_value(kh_key(&scope->captures, it)); } } diff --git a/extlib/benz/include/picrin/khash.h b/extlib/benz/include/picrin/khash.h index 78d0feef..3d8d2ed9 100644 --- a/extlib/benz/include/picrin/khash.h +++ b/extlib/benz/include/picrin/khash.h @@ -27,21 +27,7 @@ #ifndef AC_KHASH_H #define AC_KHASH_H -#include - -#if UINT_MAX == 0xffffffffu -typedef unsigned int khint32_t; -#elif ULONG_MAX == 0xffffffffu -typedef unsigned long khint32_t; -#endif - -#if ULONG_MAX == ULLONG_MAX -typedef unsigned long khint64_t; -#else -typedef unsigned long long khint64_t; -#endif - -typedef khint32_t khint_t; +typedef int khint_t; typedef khint_t khiter_t; #define ac_isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2) @@ -78,7 +64,7 @@ PIC_INLINE khint_t ac_Wang_hash(khint_t key) #define KHASH_DECLARE(name, khkey_t, khval_t) \ typedef struct { \ khint_t n_buckets, size, n_occupied, upper_bound; \ - khint32_t *flags; \ + int *flags; \ khkey_t *keys; \ khval_t *vals; \ } kh_##name##_t; \ @@ -105,7 +91,7 @@ PIC_INLINE khint_t ac_Wang_hash(khint_t key) void kh_clear_##name(kh_##name##_t *h) \ { \ if (h->flags) { \ - memset(h->flags, 0xaa, ac_fsize(h->n_buckets) * sizeof(khint32_t)); \ + memset(h->flags, 0xaa, ac_fsize(h->n_buckets) * sizeof(int)); \ h->size = h->n_occupied = 0; \ } \ } \ @@ -125,15 +111,15 @@ PIC_INLINE khint_t ac_Wang_hash(khint_t key) } \ void kh_resize_##name(pic_state *pic, kh_##name##_t *h, khint_t new_n_buckets) \ { /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \ - khint32_t *new_flags = 0; \ + int *new_flags = 0; \ khint_t j = 1; \ { \ ac_roundup32(new_n_buckets); \ if (new_n_buckets < 4) new_n_buckets = 4; \ if (h->size >= ac_hash_upper(new_n_buckets)) j = 0; /* requested size is too small */ \ else { /* hash table size to be changed (shrink or expand); rehash */ \ - new_flags = pic_malloc(pic, ac_fsize(new_n_buckets) * sizeof(khint32_t)); \ - memset(new_flags, 0xaa, ac_fsize(new_n_buckets) * sizeof(khint32_t)); \ + new_flags = pic_malloc(pic, ac_fsize(new_n_buckets) * sizeof(int)); \ + memset(new_flags, 0xaa, ac_fsize(new_n_buckets) * sizeof(int)); \ if (h->n_buckets < new_n_buckets) { /* expand */ \ h->keys = pic_realloc(pic, (void *)h->keys, new_n_buckets * sizeof(khkey_t)); \ if (kh_is_map) { \ @@ -230,12 +216,10 @@ PIC_INLINE khint_t ac_Wang_hash(khint_t key) /* --- BEGIN OF HASH FUNCTIONS --- */ -#define kh_ptr_hash_func(key) (khint32_t)(long)(key) +#define kh_ptr_hash_func(key) (int)(long)(key) #define kh_ptr_hash_equal(a, b) ((a) == (b)) -#define kh_int_hash_func(key) (khint32_t)(key) +#define kh_int_hash_func(key) (int)(key) #define kh_int_hash_equal(a, b) ((a) == (b)) -#define kh_int64_hash_func(key) (khint32_t)((key)>>33^(key)^(key)<<11) -#define kh_int64_hash_equal(a, b) ((a) == (b)) #define kh_str_hash_func(key) ac_X31_hash_string(key) #define kh_str_hash_equal(a, b) (strcmp(a, b) == 0) #define kh_int_hash_func2(k) ac_Wang_hash((khint_t)key)