X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_hashtable.c;h=fa9aba32feb1e98c252dff68f2ea39904f9b3ab9;hb=176328b42924a56b53e4c7255ef83acb5847c621;hp=d5e844b54153e8e727af2d478bbf4faaa683af83;hpb=e70e95962c26832628d586e07f9cd1a2e1852d72;p=palacios.git diff --git a/palacios/src/palacios/vmm_hashtable.c b/palacios/src/palacios/vmm_hashtable.c index d5e844b..fa9aba3 100644 --- a/palacios/src/palacios/vmm_hashtable.c +++ b/palacios/src/palacios/vmm_hashtable.c @@ -125,7 +125,7 @@ ulong_t hash_long(ulong_t val, uint_t bits) { ulong_t hash_buffer(uchar_t * msg, uint_t length) { ulong_t hash = 0; ulong_t temp = 0; - int i; + uint_t i; for (i = 0; i < length; i++) { hash = (hash << 4) + *(msg + i) + i; @@ -233,7 +233,7 @@ struct hashtable * create_hashtable(uint_t min_size, htable->entry_count = 0; htable->hash_fn = hash_fn; htable->eq_fn = eq_fn; - htable->load_limit = (uint_t) ceil((double)(size * max_load_factor)); + htable->load_limit = (uint_t) v3_ceil((double)(size * max_load_factor)); return htable; } @@ -317,7 +317,7 @@ static int hashtable_expand(struct hashtable * htable) { htable->table_length = new_size; - htable->load_limit = (uint_t) ceil(new_size * max_load_factor); + htable->load_limit = (uint_t) v3_ceil(new_size * max_load_factor); return -1; } @@ -394,6 +394,55 @@ int hashtable_change(struct hashtable * htable, addr_t key, addr_t value, int fr +int hashtable_inc(struct hashtable * htable, addr_t key, addr_t value) { + struct hash_entry * tmp_entry; + uint_t hash_value; + uint_t index; + + hash_value = do_hash(htable, key); + + index = indexFor(htable->table_length, hash_value); + + tmp_entry = htable->table[index]; + + while (tmp_entry != NULL) { + /* Check hash value to short circuit heavier comparison */ + if ((hash_value == tmp_entry->hash) && (htable->eq_fn(key, tmp_entry->key))) { + + tmp_entry->value += value; + return -1; + } + tmp_entry = tmp_entry->next; + } + return 0; +} + + +int hashtable_dec(struct hashtable * htable, addr_t key, addr_t value) { + struct hash_entry * tmp_entry; + uint_t hash_value; + uint_t index; + + hash_value = do_hash(htable, key); + + index = indexFor(htable->table_length, hash_value); + + tmp_entry = htable->table[index]; + + while (tmp_entry != NULL) { + /* Check hash value to short circuit heavier comparison */ + if ((hash_value == tmp_entry->hash) && (htable->eq_fn(key, tmp_entry->key))) { + + tmp_entry->value -= value; + return -1; + } + tmp_entry = tmp_entry->next; + } + return 0; +} + + + /*****************************************************************************/ /* returns value associated with key */