Change to the spec...missed a consistency property. Adding timing option.
[repair.git] / Repair / RepairInterpreter / SimpleHash.h
1 #ifndef SIMPLEHASH_H
2 #define SIMPLEHASH_H
3
4 /* LinkedHashNode *****************************************************/
5
6 class LinkedHashNode {
7     
8 public:
9     LinkedHashNode *next;
10     int data;
11     int key;  
12     LinkedHashNode(int key, int data, LinkedHashNode *next);
13     LinkedHashNode();
14
15 };
16
17 /* SimpleList *********************************************************/
18
19 class SimpleList {
20 private:
21     LinkedHashNode head;
22     LinkedHashNode *ptr;
23 public:
24     SimpleList();
25     void add(int data);
26     int contains(int data);
27     void reset();
28     int hasMoreElements();
29     int nextElement();
30 };
31
32
33 /* SimpleIterator *****************************************************/
34
35 class SimpleIterator {
36
37 private:
38
39     LinkedHashNode *cur;
40
41 public:
42
43     inline SimpleIterator(LinkedHashNode *start) {
44         cur = start;
45     }
46
47     inline int hasNext() {
48         return (int)cur->next == 0 ? 0 : 1;
49     }
50
51     inline int next() {
52         cur = cur->next;
53         return cur->data;
54     }
55
56     inline int key() {
57         return cur->key;
58     }
59
60     inline int size() {
61         int temp = 0;
62         while (cur->next) {
63             temp++;
64             cur = cur->next;
65         }
66         return temp;
67     }
68
69 };
70
71 /* SimpleHash *********************************************************/
72
73 class SimpleHash {
74
75 private:
76     int numelements;
77
78     int size;
79     LinkedHashNode *bucket;
80     LinkedHashNode all;    
81     LinkedHashNode *last;
82
83     int numparents;
84     SimpleHash* parents[10];
85
86 public:
87
88     SimpleHash();
89
90     SimpleHash(int size);
91
92     ~SimpleHash();
93
94     int add(int key, int data);
95
96     bool contains(int key);
97
98     bool contains(int key, int data);
99
100     int get(int key, int& data);
101
102     int countdata(int data);
103
104     void addParent(SimpleHash* parent);
105
106     inline SimpleIterator* iterator() {
107         return new SimpleIterator(&all);
108     }
109
110     inline int count() {
111         return numelements;
112     }
113
114     int count(int key);
115
116 };
117
118 /* SimpleHashExcepion  *************************************************/
119
120 class SimpleHashException {
121 public:
122     SimpleHashException();
123 };
124
125 #endif
126