2 * Copyright (c) 1996 Barton P. Miller
4 * We provide the Paradyn Parallel Performance Tools (below
5 * described as Paradyn") on an AS IS basis, and do not warrant its
6 * validity or performance. We reserve the right to update, modify,
7 * or discontinue this software at any time. We shall have no
8 * obligation to supply such updates or modifications or any other
9 * form of support to you.
11 * This license is for research uses. For such uses, there is no
12 * charge. We define "research use" to mean you may freely use it
13 * inside your organization for whatever purposes you see fit. But you
14 * may not re-distribute Paradyn or parts of Paradyn, in any form
15 * source or binary (including derivatives), electronic or otherwise,
16 * to any other organization or entity without our permission.
18 * (for other uses, please contact us at paradyn@cs.wisc.edu)
20 * All warranties, including without limitation, any warranty of
21 * merchantability or fitness for a particular purpose, are hereby
24 * By your use of Paradyn, you understand and agree that we (or any
25 * other person or entity with proprietary rights in Paradyn) are
26 * under no obligation to provide either maintenance services,
27 * update services, notices of latent defects, or correction of
28 * defects for Paradyn.
30 * Even if advised of the possibility of such damages, under no
31 * circumstances shall we (or any other person or entity with
32 * proprietary rights in the software licensed hereunder) be liable
33 * to you or any third party for direct, indirect, or consequential
34 * damages of any character regardless of type of action, including,
35 * without limitation, loss of profits, loss of use, loss of good
36 * will, or computer failure or malfunction. You agree to indemnify
37 * us (and any other person or entity with proprietary rights in the
38 * software licensed hereunder) for any and all liability it may
39 * incur to third parties resulting from your use of Paradyn.
44 * $Log: stringPool.C,v $
45 * Revision 1.10 1996/11/12 17:50:17 mjrg
46 * Removed warnings, changes for compiling with Visual C++ and xlc
48 * Revision 1.9 1996/08/16 21:32:05 tamches
49 * updated copyright for release 1.1
51 * Revision 1.8 1995/11/28 15:58:35 naim
52 * Minor fix. Chaning constant 4090 to SP_PAGE_SIZE - naim
54 * Revision 1.7 1995/02/16 09:28:13 markc
55 * Removed compiler warnings.
56 * Changed Boolean to bool
58 * Revision 1.6 1994/09/22 03:19:13 markc
59 * Changed private pointers to char*
61 * Revision 1.5 1994/08/05 16:02:05 hollings
62 * More consistant use of stringHandle vs. char *.
64 * Revision 1.4 1994/07/28 22:22:06 krisna
65 * changed definitions of ReadFunc and WriteFunc to conform to prototypes
67 * Revision 1.3 1994/07/14 23:43:14 hollings
68 * added abort for malloc failure.
70 * Revision 1.2 1994/01/26 04:53:43 hollings
71 * Change to using <module>/h/{*.h}
78 #include "util/h/list.h"
79 #include "util/h/stringPool.h"
81 #define SP_PAGE_SIZE 4090
84 * Hash Function from Aho, Sethi, Ulman _Compilers_ (Second Edition)
88 static int hash(const char *ch, int size)
90 register unsigned int h = 0, g;
92 for (; *ch != '\0'; ch++) {
94 if ((g = (h & 0xf0000000))) {
102 stringPool::stringPool()
104 memset(table, '\0', sizeof(table));
105 currPage = new char[SP_PAGE_SIZE];
109 stringHandle stringPool::find(const char *data)
114 hid = hash(data, TAB_SIZE);
115 for (curr=table[hid]; curr; curr=curr->next) {
116 if (!strcmp(data, curr->data)) {
123 char *stringPool::getSpace(int size)
127 if ((int)(currPos - currPage) + size > SP_PAGE_SIZE) {
128 // create a new page.
129 currPage = new char[SP_PAGE_SIZE];
130 if (!currPage) abort();
138 stringHandle stringPool::findAndAdd(const char *data)
147 hid = hash(data, TAB_SIZE);
148 temp = new stringEntry;
149 temp->data = getSpace(strlen(data)+1);
150 strcpy(temp->data, data);
151 temp->next = table[hid];
153 val = (stringHandle) temp->data;