-
Notifications
You must be signed in to change notification settings - Fork 7
/
nmtbl.cxx
51 lines (40 loc) · 928 Bytes
/
nmtbl.cxx
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
#include "token.h"
nm_entry* nm_entry::nm_table[nm_entry::h_t_size];
//----------------------------------------------------------------//
inline unsigned nm_entry::hash(const char* name)
{
unsigned h = 0;
unsigned c;
while ((c = (unsigned)*name++) != 0) {
h = (h<<1) + c;
}
return h % nm_entry::h_t_size;
}
nm_entry* nm_entry::find(const char* name)
{
unsigned h;
nm_entry* ne;
h = hash(name);
for (ne = nm_table[h]; ne != NULL; ne = ne->next)
{
if (strcmp(name, ne->text) == 0)
break;
}
return ne;
}
nm_entry* nm_entry::add(const char* name, int v_tag)
{
unsigned h;
nm_entry* ne;
ne = find(name);
if (ne != NULL)
return ne;
h = hash(name);
ne = new (strlen(name)) nm_entry;
ne->next = nm_table[h];
nm_table[h] = ne;
ne->tag = v_tag;
ne->flags = 0;
strcpy(ne->text, name);
return ne;
}