Add additional functionality to Simplehash.
[repair.git] / Repair / RepairCompiler / MCC / Runtime / SimpleHash.cc
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;