Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
515862cc
Commit
515862cc
authored
Jul 30, 2012
by
Yukihiro Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
khash refactoring; no more MRB_KHASH_INITIAL_SIZE
parent
857370c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
16 deletions
+22
-16
include/mrbconf.h
include/mrbconf.h
+3
-3
include/mruby/khash.h
include/mruby/khash.h
+19
-13
No files found.
include/mrbconf.h
View file @
515862cc
...
@@ -13,15 +13,15 @@
...
@@ -13,15 +13,15 @@
/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */
/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */
//#define MRB_USE_FLOAT
//#define MRB_USE_FLOAT
/* initial size of khash table bucket; should be power of 2 (n >= 8) */
//#define MRB_INITIAL_HASH_SIZE 32
/* argv max size in mrb_funcall */
/* argv max size in mrb_funcall */
//#define MRB_FUNCALL_ARGC_MAX 16
//#define MRB_FUNCALL_ARGC_MAX 16
/* number of object per heap page */
/* number of object per heap page */
//#define MRB_HEAP_PAGE_SIZE 1024
//#define MRB_HEAP_PAGE_SIZE 1024
/* default size of khash table bucket */
//#define KHASH_DEFAULT_SIZE 32
/* -DDISABLE_XXXX to drop the feature */
/* -DDISABLE_XXXX to drop the feature */
#define DISABLE_REGEXP
/* regular expression classes */
#define DISABLE_REGEXP
/* regular expression classes */
//#define DISABLE_SPRINTF /* Kernel.sprintf method */
//#define DISABLE_SPRINTF /* Kernel.sprintf method */
...
...
include/mruby/khash.h
View file @
515862cc
...
@@ -17,9 +17,10 @@ extern "C" {
...
@@ -17,9 +17,10 @@ extern "C" {
typedef
uint32_t
khint_t
;
typedef
uint32_t
khint_t
;
typedef
khint_t
khiter_t
;
typedef
khint_t
khiter_t
;
#ifndef
MRB_INITIAL_HASH
_SIZE
#ifndef
KHASH_DEFAULT
_SIZE
# define
MRB_INITIAL_HASH
_SIZE 32
# define
KHASH_DEFAULT
_SIZE 32
#endif
#endif
#define KHASH_MIN_SIZE 8
#define UPPER_BOUND(x) ((x)>>2|(x>>1))
#define UPPER_BOUND(x) ((x)>>2|(x>>1))
...
@@ -32,7 +33,15 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
...
@@ -32,7 +33,15 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
#define __ac_isempty(e_flag, d_flag, i) (e_flag[(i)/8]&__m[(i)%8])
#define __ac_isempty(e_flag, d_flag, i) (e_flag[(i)/8]&__m[(i)%8])
#define __ac_isdel(e_flag, d_flag, i) (d_flag[(i)/8]&__m[(i)%8])
#define __ac_isdel(e_flag, d_flag, i) (d_flag[(i)/8]&__m[(i)%8])
#define __ac_iseither(e_flag, d_flag, i) (__ac_isempty(e_flag,d_flag,i)||__ac_isdel(e_flag,d_flag,i))
#define __ac_iseither(e_flag, d_flag, i) (__ac_isempty(e_flag,d_flag,i)||__ac_isdel(e_flag,d_flag,i))
#define khash_power2(v) do { \
v--;\
v |= v >> 1;\
v |= v >> 2;\
v |= v >> 4;\
v |= v >> 8;\
v |= v >> 16;\
v++;\
} while (0);
/* declare struct kh_xxx and kh_xxx_funcs
/* declare struct kh_xxx and kh_xxx_funcs
...
@@ -92,13 +101,16 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
...
@@ -92,13 +101,16 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
} \
} \
kh_##name##_t *kh_init_##name##_size(mrb_state *mrb, khint_t size) { \
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)); \
kh_##name##_t *h = (kh_##name##_t*)mrb_calloc(mrb, 1, sizeof(kh_##name##_t)); \
if (size < KHASH_MIN_SIZE) \
size = KHASH_MIN_SIZE; \
khash_power2(size); \
h->n_buckets = size; \
h->n_buckets = size; \
h->mrb = mrb; \
h->mrb = mrb; \
kh_alloc_##name(h); \
kh_alloc_##name(h); \
return h; \
return h; \
} \
} \
kh_##name##_t *kh_init_##name(mrb_state *mrb){ \
kh_##name##_t *kh_init_##name(mrb_state *mrb){ \
return kh_init_##name##_size(mrb,
MRB_INITIAL_HASH_SIZE);
\
return kh_init_##name##_size(mrb,
KHASH_DEFAULT_SIZE);
\
} \
} \
void kh_destroy_##name(kh_##name##_t *h) \
void kh_destroy_##name(kh_##name##_t *h) \
{ \
{ \
...
@@ -130,15 +142,9 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
...
@@ -130,15 +142,9 @@ 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<MRB_INITIAL_HASH_SIZE) { \
if (new_n_buckets < KHASH_MIN_SIZE) \
new_n_buckets = MRB_INITIAL_HASH_SIZE; \
new_n_buckets = KHASH_MIN_SIZE; \
} else { \
khash_power2(new_n_buckets); \
khint_t limit = new_n_buckets; \
new_n_buckets = MRB_INITIAL_HASH_SIZE; \
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; \
khkey_t *old_keys = h->keys; \
khkey_t *old_keys = h->keys; \
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment