3 * $Log: stringPool.C,v $
4 * Revision 1.5 1994/08/05 16:02:05 hollings
5 * More consistant use of stringHandle vs. char *.
7 * Revision 1.4 1994/07/28 22:22:06 krisna
8 * changed definitions of ReadFunc and WriteFunc to conform to prototypes
10 * Revision 1.3 1994/07/14 23:43:14 hollings
11 * added abort for malloc failure.
13 * Revision 1.2 1994/01/26 04:53:43 hollings
14 * Change to using <module>/h/{*.h}
16 * Revision 1.1 1994/01/25 20:50:27 hollings
17 * First real version of utility library.
19 * Revision 1.4 1993/08/05 18:58:08 hollings
22 * Revision 1.3 1993/05/07 20:19:17 hollings
23 * Upgrade to use dyninst interface.
25 * Revision 1.2 1993/01/28 19:32:44 hollings
26 * bzero changed to memset.
28 * Revision 1.1 1992/08/03 20:42:59 hollings
36 #include "util/h/list.h"
37 #include "util/h/stringPool.h"
40 * Hash Function from Aho, Sethi, Ulman _Compilers_ (Second Edition)
44 static int hash(char *ch, int size)
46 register unsigned int h = 0, g;
48 for (; *ch != '\0'; ch++) {
50 if (g = (h & 0xf0000000)) {
58 stringPool::stringPool()
60 memset(table, '\0', sizeof(table));
61 currPage = (stringHandle) malloc(4090);;
65 stringHandle stringPool::find(char *data)
70 hid = hash(data, TAB_SIZE);
71 for (curr=table[hid]; curr; curr=curr->next) {
72 if (!strcmp(data, (char *) curr->data)) {
79 stringHandle stringPool::getSpace(int size)
83 if ((int)(currPos - currPage) + size > PAGE_SIZE) {
85 currPage = (stringHandle) malloc(4090);
86 if (!currPage) abort();
94 stringHandle stringPool::findAndAdd(char *data)
103 hid = hash(data, TAB_SIZE);
104 temp = (stringEntry *) malloc(sizeof(stringEntry));
105 temp->data = getSpace(strlen(data)+1);
106 strcpy((char *) temp->data, data);
107 temp->next = this->table[hid];