-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_table.h
68 lines (55 loc) · 1.19 KB
/
hash_table.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef _ZHASH_H_
#define _ZHASH_H_
//#include "../ZTypes/ZTypes.h"
#include "../ZTypes/Zlang.h"
#include <google/dense_hash_map>
using google::dense_hash_map;
using stdext::hash_compare;
struct eqstr
{
bool operator()(const ZChar* s1, const ZChar* s2) const
{
return (s1 == s2) || (s1 && s2 && zcstrcmp(s1, s2) == 0);
}
};
template <class Data>
class ZHash
{
public:
dense_hash_map < const ZChar * , Data* , hash_compare < const ZChar * > , eqstr > ZIHash;
ZHash()
{
ZIHash.set_empty_key(NULL);
}
void Insert(Data* d , ZChar * key)
{
ZIHash[key]=d;
}
void Delete(ZChar * key)
{
ZIHash.set_deleted_key (_ZC(""));
ZIHash.erase(key);
ZIHash.clear_deleted_key();
}
void PrintAll()
{
for(
dense_hash_map < const ZChar * , Data* , hash_compare < const ZChar * > , eqstr >::iterator i=ZIHash.begin();
i!=ZIHash.end();i++)
cout<<i->first<<" : "<< boost::apply_visitor(ToString(),*(i->second)) <<endl;
}
};
template <class ZHVar>
class ZScope
{
public:
int id;
ZHash<ZHVar> VarTable;
ZScope<ZHVar>* Parent;
ZHVar* lookup(ZChar * key)
{
if(VarTable.ZIHash.find(key)==VarTable.ZIHash.end()) return NULL;
else return VarTable.ZIHash.find(key)->second;
}
};
#endif