3 * $Log: stringPool.C,v $
4 * Revision 1.2 1994/01/26 04:53:43 hollings
5 * Change to using <module>/h/*.h
7 * Revision 1.1 1994/01/25 20:50:27 hollings
8 * First real version of utility library.
10 * Revision 1.4 1993/08/05 18:58:08 hollings
13 * Revision 1.3 1993/05/07 20:19:17 hollings
14 * Upgrade to use dyninst interface.
16 * Revision 1.2 1993/01/28 19:32:44 hollings
17 * bzero changed to memset.
19 * Revision 1.1 1992/08/03 20:42:59 hollings
27 #include "util/h/list.h"
28 #include "util/h/stringPool.h"
31 * Hash Function from Aho, Sethi, Ulman _Compilers_ (Second Edition)
35 static int hash(char *ch, int size)
37 register unsigned int h = 0, g;
39 for (; *ch != '\0'; ch++) {
41 if (g = (h & 0xf0000000)) {
49 stringPool::stringPool()
51 memset(table, '\0', sizeof(table));
52 currPage = (stringHandle) malloc(4090);;
56 stringHandle stringPool::find(char *data)
61 hid = hash(data, TAB_SIZE);
62 for (curr=table[hid]; curr; curr=curr->next) {
63 if (!strcmp(data, curr->data)) {
70 char *stringPool::getSpace(int size)
74 if ((int)(currPos - currPage) + size > PAGE_SIZE) {
76 currPage = (stringHandle) malloc(4090);
84 stringHandle stringPool::findAndAdd(char *data)
93 hid = hash(data, TAB_SIZE);
94 temp = (stringEntry *) malloc(sizeof(stringEntry));
95 temp->data = getSpace(strlen(data)+1);
96 strcpy(temp->data, data);
97 temp->next = this->table[hid];