| | |
| | | size_t code = hashcode(key); |
| | | tailq_entry_t *item; |
| | | void *oldvalue; |
| | | |
| | | SemUtil::dec(hashtable->wlock); |
| | | tailq_header_t *my_tailq_head = hashtable->array[code] ; |
| | | if ( my_tailq_head == NULL) |
| | | { |
| | | SemUtil::inc(hashtable->wlock); |
| | | return NULL; |
| | | } |
| | | else |
| | |
| | | |
| | | /* mm_free the item as we don't need it anymore. */ |
| | | mm_free(item); |
| | | |
| | | SemUtil::inc(hashtable->wlock); |
| | | return oldvalue; |
| | | } |
| | | } |
| | | } |
| | | SemUtil::inc(hashtable->wlock); |
| | | return NULL; |
| | | |
| | | } |
| | |
| | | void hashtable_removeall(hashtable_t *hashtable) |
| | | { |
| | | tailq_entry_t *item; |
| | | SemUtil::dec(hashtable->wlock); |
| | | for (int i = 0; i < MAPSIZE; i++) |
| | | { |
| | | tailq_header_t *my_tailq_head = hashtable->array[i] ; |
| | |
| | | mm_free(my_tailq_head); |
| | | hashtable->array[i] = NULL; |
| | | } |
| | | SemUtil::inc(hashtable->wlock); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | |
| | | int hashtable_alloc_key(hashtable_t *hashtable) { |
| | | int key = START_KEY; |
| | | SemUtil::dec(hashtable->wlock); |
| | | |
| | | while(_hashtable_get(hashtable, key) != NULL) { |
| | | key++; |
| | | } |
| | | |
| | | _hashtable_put(hashtable, key, (void *)1); |
| | | SemUtil::inc(hashtable->wlock); |
| | | return key; |
| | | } |
| | | |
| | | void *hashtable_get(hashtable_t *hashtable, int key) { |
| | | SemUtil::dec(hashtable->mutex); |
| | |
| | | } |
| | | } |
| | | |
| | | int hashtable_alloc_key(hashtable_t *hashtable) { |
| | | int key = START_KEY; |
| | | SemUtil::dec(hashtable->wlock); |
| | | |
| | | while(_hashtable_get(hashtable, key) != NULL) { |
| | | key++; |
| | | } |
| | | |
| | | _hashtable_put(hashtable, key, (void *)1); |
| | | SemUtil::inc(hashtable->wlock); |
| | | return key; |
| | | } |
| | | |
| | | std::set<int> * hashtable_keyset(hashtable_t *hashtable) { |
| | | std::set<int> *keyset = new std::set<int>; |
| | | tailq_entry_t *item; |
| | |
| | | } |
| | | return keyset; |
| | | } |
| | | |
| | | |