2 /* $Id: symtab.c,v 1.2 2009/10/29 00:56:20 christos Exp $ */
7 __RCSID("$NetBSD: closure.c,v 1.8 2006/05/24 18:01:43 christos Exp $");
9 /* TABLE_SIZE is the number of entries in the symbol table. */
10 /* TABLE_SIZE must be a power of two. */
12 #define TABLE_SIZE 1024
14 static bucket
**symbol_table
= 0;
19 hash(const char *name
)
24 assert(name
&& *name
);
27 while ((c
= *++s
) != 0)
28 k
= (31 * k
+ c
) & (TABLE_SIZE
- 1);
34 make_bucket(const char *name
)
39 bp
= (bucket
*)MALLOC(sizeof(bucket
));
44 bp
->name
= MALLOC(strlen(name
) + 1);
48 bp
->value
= UNDEFINED
;
56 strcpy(bp
->name
, name
);
62 lookup(const char *name
)
66 bpp
= symbol_table
+ hash(name
);
71 if (strcmp(name
, bp
->name
) == 0)
77 *bpp
= bp
= make_bucket(name
);
78 last_symbol
->next
= bp
;
85 create_symbol_table(void)
90 symbol_table
= (bucket
**)MALLOC(TABLE_SIZE
* sizeof(bucket
*));
91 if (symbol_table
== 0)
93 for (i
= 0; i
< TABLE_SIZE
; i
++)
96 bp
= make_bucket("error");
102 symbol_table
[hash("error")] = bp
;
106 free_symbol_table(void)
117 for (p
= first_symbol
; p
; p
= q
)