Add additional functionality to Simplehash.
authorbdemsky <bdemsky>
Sat, 14 Aug 2004 19:58:54 +0000 (19:58 +0000)
committerbdemsky <bdemsky>
Sat, 14 Aug 2004 19:58:54 +0000 (19:58 +0000)
Repair/RepairCompiler/MCC/Runtime/SimpleHash.cc
Repair/RepairCompiler/MCC/Runtime/SimpleHash.h

index 77beed787a1e7cafc4aaaa02f4dd9eceabef518e..fef3507015bbd60a83c6190f8cafafd5d7bbdfca 100755 (executable)
@@ -229,7 +229,15 @@ int SimpleHash::remove(int key, int data) {
     return 0;
 }
 
-
+void SimpleHash::addAll(SimpleHash * set) {
+  SimpleIterator it;
+  set->iterator(it);
+  while(it.hasNext()) {
+    int key=it.key();
+    int data=it.next();
+    add(key,data);
+  }
+}
 
 int SimpleHash::add(int key, int data) {
   /* Rehash code */
@@ -325,6 +333,20 @@ int SimpleHash::count(int key) {
     return count;
 }
 
+SimpleHash * SimpleHash::imageSet(int key) {
+  SimpleHash * newset=new SimpleHash(count(key));
+  unsigned int hashkey = (unsigned int)key % size;
+  
+  struct SimpleNode *ptr = bucket[hashkey];
+  while (ptr) {
+    if (ptr->key == key) {
+      newset->add(ptr->data,ptr->data);
+    }
+    ptr = ptr->next;
+  }
+  return newset;
+}
+
 int SimpleHash::get(int key, int&data) {
     unsigned int hashkey = (unsigned int)key % size;
     
index eda2467867eb7eae2d1a6ee90970434049eca46f..094c963d2c246e05c9e81706b0df6cf50a9d7cab 100755 (executable)
@@ -95,7 +95,8 @@ public:
         return numelements;
     }
     int count(int key);
-
+    void addAll(SimpleHash * set);
+    SimpleHash * imageSet(int key);
 };
 
 /* SimpleHashExcepion  *************************************************/