From 864a17d0be7e98c4d7da82e7185f1ae364546338 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 21 Feb 2016 01:52:34 +0900 Subject: [PATCH] khiter_t -> int --- extlib/benz/dict.c | 6 +-- extlib/benz/gc.c | 8 ++-- extlib/benz/include/picrin/private/khash.h | 43 ++++++++++------------ extlib/benz/lib.c | 4 +- extlib/benz/macro.c | 4 +- extlib/benz/read.c | 4 +- extlib/benz/symbol.c | 2 +- extlib/benz/weak.c | 6 +-- extlib/benz/write.c | 6 +-- 9 files changed, 39 insertions(+), 44 deletions(-) diff --git a/extlib/benz/dict.c b/extlib/benz/dict.c index 2d468c09..164513e7 100644 --- a/extlib/benz/dict.c +++ b/extlib/benz/dict.c @@ -22,7 +22,7 @@ pic_value pic_dict_ref(pic_state *pic, pic_value dict, pic_value key) { khash_t(dict) *h = &pic_dict_ptr(pic, dict)->hash; - khiter_t it; + int it; it = kh_get(dict, h, pic_sym_ptr(pic, key)); if (it == kh_end(h)) { @@ -36,7 +36,7 @@ pic_dict_set(pic_state *pic, pic_value dict, pic_value key, pic_value val) { khash_t(dict) *h = &pic_dict_ptr(pic, dict)->hash; int ret; - khiter_t it; + int it; it = kh_put(dict, h, pic_sym_ptr(pic, key), &ret); kh_val(h, it) = val; @@ -60,7 +60,7 @@ void pic_dict_del(pic_state *pic, pic_value dict, pic_value key) { khash_t(dict) *h = &pic_dict_ptr(pic, dict)->hash; - khiter_t it; + int it; it = kh_get(dict, h, pic_sym_ptr(pic, key)); if (it == kh_end(h)) { diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index 348f2ee9..4ab029ad 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -344,7 +344,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) } case PIC_TYPE_ENV: { khash_t(env) *h = &obj->u.env.map; - khiter_t it; + int it; for (it = kh_begin(h); it != kh_end(h); ++it) { if (kh_exist(h, it)) { @@ -425,7 +425,7 @@ gc_mark_phase(pic_state *pic) pic_callinfo *ci; struct pic_proc **xhandler; struct pic_list *list; - khiter_t it; + int it; size_t j; assert(pic->heap->weaks == NULL); @@ -503,7 +503,7 @@ gc_mark_phase(pic_state *pic) do { struct pic_object *key; pic_value val; - khiter_t it; + int it; khash_t(weak) *h; struct pic_weak *weak; @@ -644,7 +644,7 @@ static void gc_sweep_phase(pic_state *pic) { struct heap_page *page; - khiter_t it; + int it; khash_t(weak) *h; khash_t(oblist) *s = &pic->oblist; pic_sym *sym; diff --git a/extlib/benz/include/picrin/private/khash.h b/extlib/benz/include/picrin/private/khash.h index a75a5cec..83c62860 100644 --- a/extlib/benz/include/picrin/private/khash.h +++ b/extlib/benz/include/picrin/private/khash.h @@ -24,13 +24,8 @@ SOFTWARE. */ -#ifndef AC_KHASH_H -#define AC_KHASH_H - -#include - -typedef int khint_t; -typedef khint_t khiter_t; +#ifndef PICRIN_KHASH_H +#define PICRIN_KHASH_H #define ac_isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2) #define ac_isdel(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&1) @@ -48,18 +43,18 @@ typedef khint_t khiter_t; #define KHASH_DECLARE(name, khkey_t, khval_t) \ typedef struct { \ - khint_t n_buckets, size, n_occupied, upper_bound; \ + int n_buckets, size, n_occupied, upper_bound; \ int *flags; \ khkey_t *keys; \ khval_t *vals; \ } kh_##name##_t; \ void kh_init_##name(kh_##name##_t *h); \ - void kh_destroy_##name(pic_state *, kh_##name##_t *h); \ + void kh_destroy_##name(pic_state *, kh_##name##_t *h); \ void kh_clear_##name(kh_##name##_t *h); \ - khint_t kh_get_##name(pic_state *, const kh_##name##_t *h, khkey_t key); \ - void kh_resize_##name(pic_state *, kh_##name##_t *h, khint_t new_n_buckets); \ - khint_t kh_put_##name(pic_state *, kh_##name##_t *h, khkey_t key, int *ret); \ - void kh_del_##name(kh_##name##_t *h, khint_t x); + int kh_get_##name(pic_state *, const kh_##name##_t *h, khkey_t key); \ + void kh_resize_##name(pic_state *, kh_##name##_t *h, int new_n_buckets); \ + int kh_put_##name(pic_state *, kh_##name##_t *h, khkey_t key, int *ret); \ + void kh_del_##name(kh_##name##_t *h, int x); #define KHASH_DEFINE(name, khkey_t, khval_t, hash_func, hash_equal) \ KHASH_DEFINE2(name, khkey_t, khval_t, 1, hash_func, hash_equal) @@ -80,11 +75,11 @@ typedef khint_t khiter_t; h->size = h->n_occupied = 0; \ } \ } \ - khint_t kh_get_##name(pic_state *pic, const kh_##name##_t *h, khkey_t key) \ + int kh_get_##name(pic_state *pic, const kh_##name##_t *h, khkey_t key) \ { \ (void)pic; \ if (h->n_buckets) { \ - khint_t k, i, last, mask, step = 0; \ + int k, i, last, mask, step = 0; \ mask = h->n_buckets - 1; \ k = hash_func(key); i = k & mask; \ last = i; \ @@ -95,10 +90,10 @@ typedef khint_t khiter_t; return ac_iseither(h->flags, i)? h->n_buckets : i; \ } else return 0; \ } \ - void kh_resize_##name(pic_state *pic, kh_##name##_t *h, khint_t new_n_buckets) \ + void kh_resize_##name(pic_state *pic, kh_##name##_t *h, int new_n_buckets) \ { /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \ int *new_flags = 0; \ - khint_t j = 1; \ + int j = 1; \ { \ ac_roundup32(new_n_buckets); \ if (new_n_buckets < 4) new_n_buckets = 4; \ @@ -119,12 +114,12 @@ typedef khint_t khiter_t; if (ac_iseither(h->flags, j) == 0) { \ khkey_t key = h->keys[j]; \ khval_t val; \ - khint_t new_mask; \ + int new_mask; \ new_mask = new_n_buckets - 1; \ if (kh_is_map) val = h->vals[j]; \ ac_set_isdel_true(h->flags, j); \ while (1) { /* kick-out process; sort of like in Cuckoo hashing */ \ - khint_t k, i, step = 0; \ + int k, i, step = 0; \ k = hash_func(key); \ i = k & new_mask; \ while (!ac_isempty(new_flags, i)) i = (i + (++step)) & new_mask; \ @@ -152,9 +147,9 @@ typedef khint_t khiter_t; h->upper_bound = ac_hash_upper(h->n_buckets); \ } \ } \ - khint_t kh_put_##name(pic_state *pic, kh_##name##_t *h, khkey_t key, int *ret) \ + int kh_put_##name(pic_state *pic, kh_##name##_t *h, khkey_t key, int *ret) \ { \ - khint_t x; \ + int x; \ if (h->n_occupied >= h->upper_bound) { /* update the hash table */ \ if (h->n_buckets > (h->size<<1)) { \ kh_resize_##name(pic, h, h->n_buckets - 1); /* clear "deleted" elements */ \ @@ -163,7 +158,7 @@ typedef khint_t khiter_t; } \ } /* TODO: to implement automatically shrinking; resize() already support shrinking */ \ { \ - khint_t k, i, site, last, mask = h->n_buckets - 1, step = 0; \ + int k, i, site, last, mask = h->n_buckets - 1, step = 0; \ x = site = h->n_buckets; k = hash_func(key); i = k & mask; \ if (ac_isempty(h->flags, i)) x = i; /* for speed up */ \ else { \ @@ -192,7 +187,7 @@ typedef khint_t khiter_t; } else *ret = 0; /* Don't touch h->keys[x] if present and not deleted */ \ return x; \ } \ - void kh_del_##name(kh_##name##_t *h, khint_t x) \ + void kh_del_##name(kh_##name##_t *h, int x) \ { \ if (x != h->n_buckets && !ac_iseither(h->flags, x)) { \ ac_set_isdel_true(h->flags, x); \ @@ -231,7 +226,7 @@ PIC_INLINE int kh_str_hash_func(const char *s) { #define kh_key(h, x) ((h)->keys[x]) #define kh_val(h, x) ((h)->vals[x]) #define kh_value(h, x) ((h)->vals[x]) -#define kh_begin(h) (khint_t)(0) +#define kh_begin(h) (0) #define kh_end(h) ((h)->n_buckets) #define kh_size(h) ((h)->size) #define kh_n_buckets(h) ((h)->n_buckets) diff --git a/extlib/benz/lib.c b/extlib/benz/lib.c index f44505c9..00ef206c 100644 --- a/extlib/benz/lib.c +++ b/extlib/benz/lib.c @@ -13,7 +13,7 @@ static struct pic_lib * get_library_opt(pic_state *pic, const char *lib) { khash_t(ltable) *h = &pic->ltable; - khiter_t it; + int it; it = kh_get(ltable, h, lib); if (it == kh_end(h)) { @@ -61,7 +61,7 @@ pic_make_library(pic_state *pic, const char *lib) khash_t(ltable) *h = &pic->ltable; const char *old_lib; pic_value name, env, exports; - khiter_t it; + int it; int ret; if (pic->lib) { diff --git a/extlib/benz/macro.c b/extlib/benz/macro.c index 8a176081..0de7e6b5 100644 --- a/extlib/benz/macro.c +++ b/extlib/benz/macro.c @@ -43,7 +43,7 @@ pic_add_identifier(pic_state *pic, pic_value id, pic_value env) pic_value pic_put_identifier(pic_state *pic, pic_value id, pic_value uid, pic_value env) { - khiter_t it; + int it; int ret; it = kh_put(env, &pic_env_ptr(pic, env)->map, pic_id_ptr(pic, id), &ret); @@ -55,7 +55,7 @@ pic_put_identifier(pic_state *pic, pic_value id, pic_value uid, pic_value env) static bool search_scope(pic_state *pic, pic_value id, pic_value env, pic_value *uid) { - khiter_t it; + int it; it = kh_get(env, &pic_env_ptr(pic, env)->map, pic_id_ptr(pic, id)); if (it == kh_end(&pic_env_ptr(pic, env)->map)) { diff --git a/extlib/benz/read.c b/extlib/benz/read.c index 573d8b4e..157ef7b2 100644 --- a/extlib/benz/read.c +++ b/extlib/benz/read.c @@ -611,7 +611,7 @@ read_label_set(pic_state *pic, xFILE *file, int i) khash_t(read) *h = &pic->reader.labels; pic_value val; int c, ret; - khiter_t it; + int it; it = kh_put(read, h, i, &ret); @@ -665,7 +665,7 @@ static pic_value read_label_ref(pic_state *pic, xFILE PIC_UNUSED(*file), int i) { khash_t(read) *h = &pic->reader.labels; - khiter_t it; + int it; it = kh_get(read, h, i); if (it == kh_end(h)) { diff --git a/extlib/benz/symbol.c b/extlib/benz/symbol.c index 81f02925..795ce367 100644 --- a/extlib/benz/symbol.c +++ b/extlib/benz/symbol.c @@ -17,7 +17,7 @@ pic_intern(pic_state *pic, pic_value str) { khash_t(oblist) *h = &pic->oblist; pic_sym *sym; - khiter_t it; + int it; int ret; it = kh_put(oblist, h, pic_str_ptr(pic, str), &ret); diff --git a/extlib/benz/weak.c b/extlib/benz/weak.c index 2a294e4a..6ab88f89 100644 --- a/extlib/benz/weak.c +++ b/extlib/benz/weak.c @@ -23,7 +23,7 @@ pic_value pic_weak_ref(pic_state *pic, pic_value weak, pic_value key) { khash_t(weak) *h = &pic_weak_ptr(pic, weak)->hash; - khiter_t it; + int it; it = kh_get(weak, h, pic_obj_ptr(key)); if (it == kh_end(h)) { @@ -37,7 +37,7 @@ pic_weak_set(pic_state *pic, pic_value weak, pic_value key, pic_value val) { khash_t(weak) *h = &pic_weak_ptr(pic, weak)->hash; int ret; - khiter_t it; + int it; it = kh_put(weak, h, pic_obj_ptr(key), &ret); kh_val(h, it) = val; @@ -55,7 +55,7 @@ void pic_weak_del(pic_state *pic, pic_value weak, pic_value key) { khash_t(weak) *h = &pic_weak_ptr(pic, weak)->hash; - khiter_t it; + int it; it = kh_get(weak, h, pic_obj_ptr(key)); if (it == kh_end(h)) { diff --git a/extlib/benz/write.c b/extlib/benz/write.c index 810f1b12..382cff61 100644 --- a/extlib/benz/write.c +++ b/extlib/benz/write.c @@ -129,7 +129,7 @@ write_pair_help(struct writer_control *p, pic_value pair) pic_state *pic = p->pic; khash_t(l) *lh = &p->labels; khash_t(v) *vh = &p->visited; - khiter_t it; + int it; int ret; write_core(p, pic_car(pic, pair)); @@ -265,7 +265,7 @@ write_core(struct writer_control *p, pic_value obj) khash_t(l) *lh = &p->labels; khash_t(v) *vh = &p->visited; xFILE *file = p->file; - khiter_t it; + int it; int ret; /* shared objects */ @@ -351,7 +351,7 @@ traverse(struct writer_control *p, pic_value obj) case PIC_TYPE_VECTOR: case PIC_TYPE_DICT: { khash_t(l) *h = &p->labels; - khiter_t it; + int it; int ret; it = kh_put(l, h, pic_obj_ptr(obj), &ret);