| | |
| | | #include "hashtable.h" |
| | | #include "mm.h" |
| | | #include "sem_util.h" |
| | | #include <set> |
| | | |
| | | typedef struct tailq_entry_t |
| | | { |
| | |
| | | */ |
| | | TAILQ_ENTRY(tailq_entry_t) joint; |
| | | } tailq_entry_t; |
| | | |
| | | static int hashtable_mutex; |
| | | |
| | | #define START_KEY 1000 |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | void* _hashtable_put(hashtable_t *hashtable, int key, void *value) |
| | | void * _hashtable_put(hashtable_t *hashtable, int key, void *value) |
| | | { |
| | | size_t code = hashcode(key); |
| | | void *oldvalue; |
| | |
| | | return NULL; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | void hashtable_removeall(hashtable_t *hashtable) |
| | | { |
| | |
| | | return res; |
| | | } |
| | | |
| | | void* hashtable_put(hashtable_t *hashtable, int key, void *value) { |
| | | void hashtable_put(hashtable_t *hashtable, int key, void *value) { |
| | | SemUtil::dec(hashtable->mutex); |
| | | while (hashtable->readcnt > 0) |
| | | { |
| | |
| | | //释放读写锁 |
| | | SemUtil::inc(hashtable->wlock); |
| | | } |
| | | |
| | | |
| | | |
| | | void hashtable_foreach(hashtable_t *hashtable, hashtable_foreach_cb cb) { |
| | | tailq_entry_t *item; |
| | | for (int i = 0; i < MAPSIZE; i++) { |
| | | tailq_header_t *my_tailq_head = hashtable->array[i] ; |
| | | |
| | | if (my_tailq_head == NULL ) |
| | | continue; |
| | | |
| | | TAILQ_FOREACH(item, my_tailq_head, joint) |
| | | { |
| | | cb(item->key, item -> value); |
| | | } |
| | | } |
| | | } |
| | | |
| | | std::set<int> * hashtable_keyset(hashtable_t *hashtable) { |
| | | std::set<int> *keyset = new std::set<int>; |
| | | tailq_entry_t *item; |
| | | for (int i = 0; i < MAPSIZE; i++) { |
| | | tailq_header_t *my_tailq_head = hashtable->array[i] ; |
| | | |
| | | if (my_tailq_head == NULL ) |
| | | continue; |
| | | |
| | | TAILQ_FOREACH(item, my_tailq_head, joint) |
| | | { |
| | | keyset->insert(item->key); |
| | | } |
| | | } |
| | | return keyset; |
| | | } |