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
cd681904
Commit
cd681904
authored
Jun 19, 2012
by
crimsonwoods
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split declaration and definition for 'khash_xxx'.
parent
7744315d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
32 deletions
+50
-32
include/mruby/khash.h
include/mruby/khash.h
+41
-22
src/class.c
src/class.c
+0
-3
src/hash.c
src/hash.c
+2
-1
src/kernel.c
src/kernel.c
+0
-3
src/khash.c
src/khash.c
+5
-0
src/symbol.c
src/symbol.c
+2
-1
src/variable.c
src/variable.c
+0
-2
No files found.
include/mruby/khash.h
View file @
cd681904
...
...
@@ -32,16 +32,14 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
#define __ac_iseither(e_flag, d_flag, i) (__ac_isempty(e_flag,d_flag,i)||__ac_isdel(e_flag,d_flag,i))
/*
struct kh_xxx
/*
declare struct kh_xxx and kh_xxx_funcs
name: ash name
khkey_t: key data type
khval_t: value data type
kh_is_map: (not implemented / not used in RiteVM )
__hash_func: hash function
__hash_equal: hash comparation function
*/
#define KHASH_
INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)
\
#define KHASH_
DECLARE(name, khkey_t, khval_t, kh_is_map)
\
typedef struct kh_##name { \
khint_t n_buckets; \
khint_t size; \
...
...
@@ -55,7 +53,26 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
khint_t inc; \
mrb_state *mrb; \
} kh_##name##_t; \
static void kh_alloc_##name(kh_##name##_t *h) \
void kh_alloc_##name(kh_##name##_t *h); \
kh_##name##_t *kh_init_##name(mrb_state *mrb); \
void kh_destroy_##name(kh_##name##_t *h); \
void kh_clear_##name(kh_##name##_t *h); \
khint_t kh_get_##name(kh_##name##_t *h, khkey_t key); \
khint_t kh_put_##name(kh_##name##_t *h, khkey_t key); \
void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
void kh_del_##name(kh_##name##_t *h, khint_t x); \
/* define kh_xxx_funcs
name: ash name
khkey_t: key data type
khval_t: value data type
kh_is_map: (not implemented / not used in RiteVM )
__hash_func: hash function
__hash_equal: hash comparation function
*/
#define KHASH_DEFINE(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
void kh_alloc_##name(kh_##name##_t *h) \
{ \
khint_t sz = h->n_buckets; \
h->size = h->n_occupied = 0; \
...
...
@@ -69,14 +86,14 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
h->mask = sz-1; \
h->inc = sz/2-1; \
} \
static inline kh_##name##_t *kh_init_##name(mrb_state *mrb){
\
kh_##name##_t *kh_init_##name(mrb_state *mrb){
\
kh_##name##_t *h = (kh_##name##_t*)mrb_calloc(mrb, 1, sizeof(kh_##name##_t)); \
h->n_buckets = INITIAL_HASH_SIZE; \
h->mrb = mrb; \
kh_alloc_##name(h); \
return h; \
} \
static inline void kh_destroy_##name(kh_##name##_t *h)
\
void kh_destroy_##name(kh_##name##_t *h)
\
{ \
if( h ){ \
mrb_free(h->mrb, h->keys); \
...
...
@@ -85,7 +102,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
mrb_free(h->mrb, h); \
} \
} \
static inline void kh_clear_##name(kh_##name##_t *h)
\
void kh_clear_##name(kh_##name##_t *h)
\
{ \
if( h && h->e_flags ){ \
memset(h->e_flags, 0xff, h->n_buckets/8*sizeof(uint8_t)); \
...
...
@@ -93,7 +110,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
h->size = h->n_occupied = 0; \
} \
} \
static inline khint_t kh_get_##name(kh_##name##_t *h, khkey_t key)
\
khint_t kh_get_##name(kh_##name##_t *h, khkey_t key)
\
{ \
khint_t k = __hash_func(h->mrb,key) & (h->mask); \
while( !__ac_isempty(h->e_flags, h->d_flags, k) ){ \
...
...
@@ -104,8 +121,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
} \
return h->n_buckets; \
} \
static inline khint_t kh_put_##name(kh_##name##_t *h, khkey_t key); \
static 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<INITIAL_HASH_SIZE ){ \
new_n_buckets = INITIAL_HASH_SIZE; \
...
...
@@ -114,7 +130,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
new_n_buckets = INITIAL_HASH_SIZE; \
while( new_n_buckets < limit ) new_n_buckets *= 2; \
} \
{ \
{
\
uint8_t *old_e_flags = h->e_flags; \
khkey_t *old_keys = h->keys; \
khval_t *old_vals = h->vals; \
...
...
@@ -124,17 +140,17 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
kh_alloc_##name(h); \
/* relocate */
\
for( i=0 ; i<old_n_buckets ; i++ ){ \
if( !__ac_isempty(old_e_flags, old_d_flags, i) ){ \
khint_t k = kh_put_##name(h, old_keys[i]); \
kh_value(h,k) = old_vals[i]; \
} \
if( !__ac_isempty(old_e_flags, old_d_flags, i) ){
\
khint_t k = kh_put_##name(h, old_keys[i]);
\
kh_value(h,k) = old_vals[i];
\
}
\
} \
mrb_free(h->mrb, old_e_flags); \
mrb_free(h->mrb, old_keys); \
mrb_free(h->mrb, old_vals); \
} \
} \
static inline khint_t kh_put_##name(kh_##name##_t *h, khkey_t key)
\
khint_t kh_put_##name(kh_##name##_t *h, khkey_t key)
\
{ \
khint_t k; \
if( h->n_occupied >= h->upper_bound ){ \
...
...
@@ -159,12 +175,13 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
} \
return k; \
} \
static inline void kh_del_##name(kh_##name##_t *h, khint_t x)
\
void kh_del_##name(kh_##name##_t *h, khint_t x)
\
{ \
h->d_flags[x/8] |= __m[x%8]; \
h->size--; \
}
#define khash_t(name) kh_##name##_t
#define kh_init(name,mrb) kh_init_##name(mrb)
...
...
@@ -197,11 +214,13 @@ static inline khint_t __ac_X31_hash_string(const char *s)
#define kh_str_hash_func(mrb,key) __ac_X31_hash_string(key)
#define kh_str_hash_equal(mrb,a, b) (strcmp(a, b) == 0)
#define KHASH_MAP_INIT_INT(name, khval_t) \
KHASH_INIT(name, uint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal)
typedef
const
char
*
kh_cstr_t
;
#define KHASH_MAP_INIT_STR(name, khval_t) \
KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal)
/* declare common hash types. */
#include "mruby.h"
KHASH_DECLARE
(
mt
,
mrb_sym
,
struct
RProc
*
,
1
)
KHASH_DECLARE
(
iv
,
mrb_sym
,
mrb_value
,
1
)
#if defined(__cplusplus)
}
/* extern "C" { */
...
...
src/class.c
View file @
cd681904
...
...
@@ -17,9 +17,6 @@
#include "mruby/khash.h"
KHASH_INIT
(
mt
,
mrb_sym
,
struct
RProc
*
,
1
,
kh_int_hash_func
,
kh_int_hash_equal
)
KHASH_INIT
(
iv
,
mrb_sym
,
mrb_value
,
1
,
kh_int_hash_func
,
kh_int_hash_equal
)
typedef
struct
fc_result
{
mrb_sym
name
;
struct
RClass
*
klass
;
...
...
src/hash.c
View file @
cd681904
...
...
@@ -31,7 +31,8 @@ mrb_hash_ht_hash_equal(mrb_state *mrb, mrb_value a, mrb_value b)
return
mrb_eql
(
mrb
,
a
,
b
);
}
KHASH_INIT
(
ht
,
mrb_value
,
mrb_value
,
1
,
mrb_hash_ht_hash_func
,
mrb_hash_ht_hash_equal
);
KHASH_DECLARE
(
ht
,
mrb_value
,
mrb_value
,
1
);
KHASH_DEFINE
(
ht
,
mrb_value
,
mrb_value
,
1
,
mrb_hash_ht_hash_func
,
mrb_hash_ht_hash_equal
);
static
void
mrb_hash_modify
(
mrb_state
*
mrb
,
mrb_value
hash
);
...
...
src/kernel.c
View file @
cd681904
...
...
@@ -34,9 +34,6 @@ typedef enum {
NOEX_RESPONDS
=
0x80
}
mrb_method_flag_t
;
KHASH_INIT
(
mt
,
mrb_sym
,
struct
RProc
*
,
1
,
kh_int_hash_func
,
kh_int_hash_equal
)
KHASH_INIT
(
iv
,
mrb_sym
,
mrb_value
,
1
,
kh_int_hash_func
,
kh_int_hash_equal
)
struct
obj_ivar_tag
{
mrb_value
obj
;
int
(
*
func
)(
mrb_sym
key
,
mrb_value
val
,
void
*
arg
);
...
...
src/khash.c
0 → 100644
View file @
cd681904
#include "mruby/khash.h"
KHASH_DEFINE
(
mt
,
mrb_sym
,
struct
RProc
*
,
1
,
kh_int_hash_func
,
kh_int_hash_equal
)
KHASH_DEFINE
(
iv
,
mrb_sym
,
mrb_value
,
1
,
kh_int_hash_func
,
kh_int_hash_equal
)
src/symbol.c
View file @
cd681904
...
...
@@ -36,7 +36,8 @@ sym_hash_func(mrb_state *mrb, const symbol_name s)
}
#define sym_hash_equal(mrb,a, b) (a.len == b.len && memcmp(a.name, b.name, a.len) == 0)
KHASH_INIT
(
n2s
,
symbol_name
,
mrb_sym
,
1
,
sym_hash_func
,
sym_hash_equal
)
KHASH_DECLARE
(
n2s
,
symbol_name
,
mrb_sym
,
1
)
KHASH_DEFINE
(
n2s
,
symbol_name
,
mrb_sym
,
1
,
sym_hash_func
,
sym_hash_equal
)
/* ------------------------------------------------------ */
mrb_sym
mrb_intern2
(
mrb_state
*
mrb
,
const
char
*
name
,
int
len
)
...
...
src/variable.c
View file @
cd681904
...
...
@@ -19,8 +19,6 @@
#include "st.h"
#endif
KHASH_INIT
(
iv
,
mrb_sym
,
mrb_value
,
1
,
kh_int_hash_func
,
kh_int_hash_equal
)
static
void
mark_tbl
(
mrb_state
*
mrb
,
struct
kh_iv
*
h
)
{
...
...
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