-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashMap.h
More file actions
64 lines (44 loc) · 1.27 KB
/
hashMap.h
File metadata and controls
64 lines (44 loc) · 1.27 KB
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
#ifndef HASHMAP_H
#define HASHMAP_H
#define ARRAY 1
#define POINTER 2
typedef struct Declator{ // 修饰符(array or pointer)
int type;
struct Tree* length;
struct Declator* next;
}Declator;
typedef struct Data{
char* id_name; // 变量名
int type; // 变量类型
void* adress; // 存储地址
int size;
int scope; // 作用域
struct Declator* declator;
}Data;
typedef struct HashNode{
Data* data;
struct HashNode* next;
}HashNode;
typedef struct HashMap{
int size;
HashNode** hash_table;
}HashMap;
// Hash Function
unsigned int RSHash(const char* str, unsigned int len);
HashMap* createHashMap(int size);
// variable to data
Data* toData(int type, char* str, struct Declator* declator, int scope);
void freeHashNode(HashNode* hashNode);
// 分配内存
void getSize(HashNode* hashNode);
HashNode* createHashNode(Data* data);
// add data to hashMap
HashNode* put(HashMap* hashMap, Data* data);
void putTree(HashMap* hashMap, struct Tree *tree);
// find data in hashMap, return NULL when error
HashNode* get(HashMap* hashMap, Data* data);
void printData(HashMap* hashMap);
void destoryPartOfHashMap(HashMap* hashMap, int scope);
void destoryHashMap(HashMap* hashMap);
void printHashMap(HashMap* hashMap);
#endif