From f85c9b875b060681b51f57b15074ba1c7c9f5636 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期一, 20 七月 2020 11:10:02 +0800
Subject: [PATCH] update

---
 queue/hashtable.c |   49 +++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/queue/hashtable.c b/queue/hashtable.c
index 35530df..43c59ce 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
 {
@@ -13,8 +14,6 @@
    */
   TAILQ_ENTRY(tailq_entry_t) joint;
 } tailq_entry_t;
-
-static int hashtable_mutex;
 
 #define START_KEY 1000
 
@@ -55,7 +54,7 @@
 
 }
 
-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;
@@ -63,7 +62,7 @@
   tailq_header_t *my_tailq_head = hashtable->array[code] ;
   if ( my_tailq_head == NULL)
   {
-    my_tailq_head  = (tailq_header_t*)  mm_malloc(sizeof(tailq_header_t ));
+    my_tailq_head  = (tailq_header_t*) mm_malloc(sizeof(tailq_header_t ));
     TAILQ_INIT(my_tailq_head);
     hashtable->array[code] = my_tailq_head;
     goto putnew;
@@ -117,6 +116,10 @@
   return NULL;
 
 }
+
+
+
+
 
 void hashtable_removeall(hashtable_t *hashtable)
 {
@@ -176,7 +179,7 @@
     key++;
   }
 
-  //_hashtable_put(hashtable, key, (void *)1);
+  _hashtable_put(hashtable, key, (void *)1);
   SemUtil::inc(hashtable->wlock);
   return key;
 }
@@ -204,7 +207,7 @@
    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)
   {
@@ -224,3 +227,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;
+}

--
Gitblit v1.8.0