From bd2eaf35e0787c01e8d51b8e60354482ddd39530 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Sat, 14 Aug 2004 19:58:54 +0000 Subject: [PATCH 1/1] Add additional functionality to Simplehash. --- .../RepairCompiler/MCC/Runtime/SimpleHash.cc | 24 ++++++++++++++++++- .../RepairCompiler/MCC/Runtime/SimpleHash.h | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Repair/RepairCompiler/MCC/Runtime/SimpleHash.cc b/Repair/RepairCompiler/MCC/Runtime/SimpleHash.cc index 77beed7..fef3507 100755 --- a/Repair/RepairCompiler/MCC/Runtime/SimpleHash.cc +++ b/Repair/RepairCompiler/MCC/Runtime/SimpleHash.cc @@ -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; diff --git a/Repair/RepairCompiler/MCC/Runtime/SimpleHash.h b/Repair/RepairCompiler/MCC/Runtime/SimpleHash.h index eda2467..094c963 100755 --- a/Repair/RepairCompiler/MCC/Runtime/SimpleHash.h +++ b/Repair/RepairCompiler/MCC/Runtime/SimpleHash.h @@ -95,7 +95,8 @@ public: return numelements; } int count(int key); - + void addAll(SimpleHash * set); + SimpleHash * imageSet(int key); }; /* SimpleHashExcepion *************************************************/ -- 2.34.1