added more methods to Dictionary.

made a simple optimization in dic.c
This commit is contained in:
hyunghwan.chung
2017-01-06 14:49:42 +00:00
parent 23d80e77aa
commit 6e335cd4fb
3 changed files with 93 additions and 28 deletions

View File

@ -88,7 +88,7 @@ static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc)
static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic, stix_oop_char_t key, stix_oop_t value)
{
stix_ooi_t tally;
stix_oow_t index;
stix_oow_t hv, index;
stix_oop_association_t ass;
stix_oow_t tmp_count = 0;
@ -98,7 +98,8 @@ static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic,
STIX_ASSERT (stix, STIX_CLASSOF(stix,dic->tally) == stix->_small_integer);
STIX_ASSERT (stix, STIX_CLASSOF(stix,dic->bucket) == stix->_array);
index = stix_hashoochars(key->slot, STIX_OBJ_GET_SIZE(key)) % STIX_OBJ_GET_SIZE(dic->bucket);
hv = stix_hashoochars(key->slot, STIX_OBJ_GET_SIZE(key));
index = hv % STIX_OBJ_GET_SIZE(dic->bucket);
/* find */
while (dic->bucket->slot[index] != stix->_nil)
@ -164,7 +165,7 @@ static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic,
dic->bucket = bucket;
/* recalculate the index for the expanded bucket */
index = stix_hashoochars(key->slot, STIX_OBJ_GET_SIZE(key)) % STIX_OBJ_GET_SIZE(dic->bucket);
index = hv % STIX_OBJ_GET_SIZE(dic->bucket);
while (dic->bucket->slot[index] != stix->_nil)
index = (index + 1) % STIX_OBJ_GET_SIZE(dic->bucket);