Change to the spec...missed a consistency property. Adding timing option.
[repair.git] / Repair / RepairInterpreter / Hashtable.cc
1 #include <stdlib.h>
2 #include "Hashtable.h"
3 #include "element.h"
4
5 Hashtable::Hashtable() {
6   forward=genallocatehashtable((unsigned int (*)(void *)) & hashelement,(int (*)(void *,void *)) & elementequals);
7   parent=NULL;
8 }
9
10 void Hashtable::setparent(Hashtable *parent) {
11   this->parent=parent;
12 }
13
14 Hashtable::Hashtable(unsigned int (*hash_function)(void *),int (*comp_function)(void *, void *)) {
15   forward=genallocatehashtable(hash_function,comp_function);
16   parent=NULL;
17 }
18
19 void Hashtable::put(void *key, void*object) {
20   if (contains(key))
21     remove(key);
22   genputtable(forward,key,object);
23 }
24
25 void Hashtable::remove(void *key) {
26   genfreekey(forward,key);
27 }
28
29 void* Hashtable::get(void *key) {
30   if (!gencontains(forward,key)) {
31     if (parent!=NULL)
32       return parent->get(key);
33     else
34       return NULL;
35   } else
36     return gengettable(forward,key);
37 }
38
39 bool Hashtable::contains(void *key) {
40   if (!gencontains(forward,key)) {
41     if (parent==NULL)
42       return false;
43     else
44       return parent->contains(key);
45   }  else
46   return true;
47 }
48
49 Hashtable::~Hashtable() {
50   genfreehashtable(forward);
51 }