1 /* SYMBOL TABLE HANDLING */
5 #define IDF_HASHSIZE 307 /* size of hashtable, must be odd */
7 #define IDF_STARTHASH(hs) (hs = 0)
8 #define IDF_ENHASH(hs,ch) (hs = (hs << 2) + ch)
9 #define IDF_STOPHASH(hs) (hs = hs % IDF_HASHSIZE)
11 static struct idf *IDF_hashtable[IDF_HASHSIZE];
12 /* All identifiers can in principle be reached through
13 IDF_hashtable; IDF_hashtable[hc] is the start of a chain of
14 idf's whose tags all hash to hc.
15 Any identifier is entered into this
16 list, regardless of the nature of its declaration
17 (variable, selector, structure tag, etc.).
20 _PROTOTYPE(static struct idf *IDF_new, (char *, int, int));
28 IDF_new(tg, size, cpy)
33 static struct idf *pidf;
34 static struct idf null_idf;
35 register struct idf *id;
38 static unsigned int icnt;
45 pidf = (struct idf *) Malloc(NIDS * sizeof (struct idf));
54 icnt = size > IBUFSIZ ? size : IBUFSIZ;
65 else id->id_text = tg;
76 print("Hash table tally:\n");
77 for (i = 0; i < IDF_HASHSIZE; i++) {
78 register struct idf *notch = IDF_hashtable[i];
84 print("'%s' ", notch->id_text);
85 notch = notch->id_next;
90 print("total = %d\n", total_count);
91 print("End hash table tally\n");
101 for (i = 0; i < IDF_HASHSIZE; i++) {
102 register struct idf *notch = IDF_hashtable[i];
106 notch = notch->id_next;
110 #endif /* IDF_DEBUG */
116 /* str2idf() returns an entry in the symbol table for the
117 identifier tg. If necessary, an entry is created.
119 register char *cp = tg;
121 register struct idf *notch;
122 register unsigned int hash;
133 /* The tag tg with length size and known hash value hash is
134 looked up in the identifier table; if not found, it is
135 entered if cpy >= 0. A pointer to it is returned.
136 Notice that the chains of idf's are sorted alphabetically.
138 hook = &IDF_hashtable[hash];
140 while ((notch = *hook)) {
141 register char *s1 = tg;
145 while (!(c = (*s1 - *cp++))) {
151 if (c == 0) return notch;
153 hook = ¬ch->id_next;
155 /* a new struct idf must be inserted at the hook */
156 if (cpy < 0) return 0;
157 notch = IDF_new(tg, size, cpy);
158 notch->id_next = *hook;
159 *hook = notch; /* hooked in */