1 /* $Id: hash.c,v 1.6 1994/06/24 10:42:06 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
8 * maintains the the lists of hashed patterns
9 * Functions : addtohashtable() and printhashtable()
14 struct hlist { /* linear list of pattern numbers */
19 static struct hlist *hashtable[129]; /* an array of ptr's to these lists,
20 * the index in the array is the
25 hash(string) char *string; {
27 register unsigned i,sum;
29 if (strcmp(string,"ANY") == 0) return 128;
30 for (sum=i=0,p=string;*p;i += 3)
31 sum += (*p++)<<(i&03);
36 addtohashtable(s,n) char *s; {
38 * Add a new pattern number to the hashtable.
39 * s is the key, n the pattern number
42 register struct hlist *p;
46 p = (struct hlist *) malloc(sizeof *p);
49 * Now insert in front of the list
50 * This way, the list will be sorted from high to low, which is the
51 * wrong way around, but easy
53 p->h_next = hashtable[hval];
58 prhlist(p) struct hlist *p; {
60 * Print a list in reversed order (see comment above)
65 fprintf(genc,"%d, ",p->h_patno - 1);
71 * Print the linear lists, and also output an array of
75 register struct hlist *p;
77 for (i = 1; i <= 128; i++) {
78 fprintf(genc,"int hash%d[] = { ",i);
79 prhlist(hashtable[i-1]);
82 fputs("int hashany[] = { ", genc);
83 prhlist(hashtable[128]);
84 fputs("-1 };\n",genc);
85 fputs("int *hashtab[] = {\n",genc);
86 for (i = 1; i <= 128; i++) fprintf(genc,"\thash%d,\n",i);
87 fputs("\thashany\n};\n",genc);