forked from nathansttt/hearts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.h
50 lines (44 loc) · 863 Bytes
/
hash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdlib.h>
#ifndef _HASH_H
#define _HASH_H
extern int creationCounter;
class State {
public:
State();
virtual ~State();
virtual unsigned long hash_key() = 0;
virtual bool equals(State *val) = 0;
virtual int type() { return 0; }
virtual void Print(int val = 0) const { }
// for debugging
int nodeNum;
};
struct HNode {
HNode(State *val, HNode *nxt = 0);
~HNode();
State *key;
HNode *next;
int hits;
};
class HashTable {
public:
HashTable(int size);
~HashTable();
void Add(State *val);
void Remove(State *val);
State *IsIn(State *val) const;
int getNumElts() const { return elts; }
void PrintStats() const;
void Clear();
void iterReset();
bool iterDone();
State *iterNext();
private:
unsigned long hash(State *val);
HNode **table;
int tsize;
int elts;
int iterIndex;
HNode *iterNode;
};
#endif