From 8b4ddf10e71e1c8fabd33c72b282f7da65ff682f Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期二, 14 七月 2020 15:59:44 +0800 Subject: [PATCH] commit --- queue/hashtable.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) diff --git a/queue/hashtable.c b/queue/hashtable.c index 4662afb..629d2af 100755 --- a/queue/hashtable.c +++ b/queue/hashtable.c @@ -2,6 +2,7 @@ #include "hashtable.h" #include "mm.h" #include "sem_util.h" +#include <set> typedef struct tailq_entry_t { @@ -118,6 +119,10 @@ } + + + + void hashtable_removeall(hashtable_t *hashtable) { tailq_entry_t *item; @@ -224,3 +229,37 @@ //閲婃斁璇诲啓閿� 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; +} \ No newline at end of file -- Gitblit v1.8.0