File hashtable.c changed (mode: 100644) (index 2893edb..bf0d0de) |
... |
... |
void ht_init(struct hashtable *h, size_t size) |
22 |
22 |
|
|
23 |
23 |
void * ht_lookup(struct hashtable *h, const char *name) |
void * ht_lookup(struct hashtable *h, const char *name) |
24 |
24 |
{ |
{ |
25 |
|
size_t start = hashfunc(name); |
|
26 |
|
size_t idx = (start + 1) % h->size; |
|
27 |
|
for(; idx != start; idx = (idx + 1) % h->size){ |
|
|
25 |
|
size_t start = hashfunc(name) & (h->size -1); |
|
26 |
|
size_t idx = (start + 1) & (h->size -1); |
|
27 |
|
for(; idx != start; idx = (idx + 1) & (h->size -1)){ |
28 |
28 |
if(h->bucket[idx].name){ |
if(h->bucket[idx].name){ |
29 |
29 |
if( !strcmp(h->bucket[idx].name, name)){ |
if( !strcmp(h->bucket[idx].name, name)){ |
30 |
30 |
return h->bucket[idx].val; |
return h->bucket[idx].val; |
|
... |
... |
void * ht_lookup(struct hashtable *h, const char *name) |
39 |
39 |
static void resize(struct hashtable *h) |
static void resize(struct hashtable *h) |
40 |
40 |
{ |
{ |
41 |
41 |
struct hashtable newht; |
struct hashtable newht; |
42 |
|
ht_init(&newht, h->size*2 +1); |
|
|
42 |
|
ht_init(&newht, h->size*2); |
43 |
43 |
size_t i; |
size_t i; |
44 |
44 |
for(i = 0; i != h->size; i++){ |
for(i = 0; i != h->size; i++){ |
45 |
45 |
if(h->bucket[i].name){ |
if(h->bucket[i].name){ |
|
... |
... |
static void resize(struct hashtable *h) |
54 |
54 |
|
|
55 |
55 |
bool ht_put(struct hashtable *h, const char *name, void *val) |
bool ht_put(struct hashtable *h, const char *name, void *val) |
56 |
56 |
{ |
{ |
57 |
|
size_t start = hashfunc(name); |
|
58 |
|
size_t idx = (start + 1) % h->size; |
|
59 |
|
for(; /*idx != start*/; idx = (idx + 1) % h->size){ |
|
|
57 |
|
size_t start = hashfunc(name) & (h->size-1); |
|
58 |
|
size_t idx = (start + 1) & (h->size-1); |
|
59 |
|
for(; /*idx != start*/; idx = (idx + 1) & (h->size-1)){ |
60 |
60 |
if(!h->bucket[idx].name){ |
if(!h->bucket[idx].name){ |
61 |
61 |
h->bucket[idx].name = name; |
h->bucket[idx].name = name; |
62 |
62 |
h->bucket[idx].val = val; |
h->bucket[idx].val = val; |
File main.c changed (mode: 100644) (index 931a28d..c05ae19) |
... |
... |
static struct typenode* addPrimitiveType(const char *name) |
17 |
17 |
|
|
18 |
18 |
static void init() |
static void init() |
19 |
19 |
{ |
{ |
20 |
|
ht_init(&functions, 10009); |
|
21 |
|
ht_init(&globals, 8191); |
|
22 |
|
ht_init(&locals, 57); |
|
23 |
|
ht_init(¶ms, 23); |
|
24 |
|
ht_init(&types, 151); |
|
25 |
|
ht_init(&initialized, 2047); |
|
26 |
|
|
|
27 |
|
ht_init(&bad_natives_in_globals, 17); |
|
28 |
|
ht_init(&shadowed_variables, 17); |
|
|
20 |
|
ht_init(&functions, 1 << 13); |
|
21 |
|
ht_init(&globals, 1 << 13); |
|
22 |
|
ht_init(&locals, 1 << 6); |
|
23 |
|
ht_init(¶ms, 1 << 5); |
|
24 |
|
ht_init(&types, 1 << 7); |
|
25 |
|
ht_init(&initialized, 1 << 11); |
|
26 |
|
|
|
27 |
|
ht_init(&bad_natives_in_globals, 1 << 4); |
|
28 |
|
ht_init(&shadowed_variables, 1 << 4); |
29 |
29 |
|
|
30 |
|
ht_init(&uninitialized_globals, 2047); |
|
|
30 |
|
ht_init(&uninitialized_globals, 1 << 11); |
31 |
31 |
|
|
32 |
32 |
gHandle = addPrimitiveType("handle"); |
gHandle = addPrimitiveType("handle"); |
33 |
33 |
gInteger = addPrimitiveType("integer"); |
gInteger = addPrimitiveType("integer"); |
|
... |
... |
static void init() |
65 |
65 |
fFilter = NULL; |
fFilter = NULL; |
66 |
66 |
fCondition = NULL; |
fCondition = NULL; |
67 |
67 |
|
|
68 |
|
ht_init(&available_flags, 11); |
|
|
68 |
|
ht_init(&available_flags, 16); |
69 |
69 |
ht_put(&available_flags, "rb", (void*)flag_rb); |
ht_put(&available_flags, "rb", (void*)flag_rb); |
70 |
70 |
ht_put(&available_flags, "shadow", (void*)flag_shadowing); |
ht_put(&available_flags, "shadow", (void*)flag_shadowing); |
71 |
71 |
ht_put(&available_flags, "filter", (void*)flag_filter); |
ht_put(&available_flags, "filter", (void*)flag_filter); |