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.
46 * Revision 1.22 1995/02/16 09:27:07 markc
47 * Modified code to remove compiler warnings.
48 * Added #defines to simplify inlining.
49 * Cleaned up Object file classes.
51 * Revision 1.21 1994/09/22 03:17:22 markc
52 * added postfix ++ operator
54 * Revision 1.20 1994/08/17 18:22:54 markc
55 * Moved the definitions of the << operator into the class declaration to
58 * Revision 1.19 1994/07/26 20:07:42 hollings
59 * added cast to ensure hash table pointers are positive.
61 * Revision 1.18 1994/07/11 23:00:57 jcargill
62 * Fixed bug where added two lists with (+=) operator could result in
63 * duplicate key entries
65 * Revision 1.17 1994/07/07 03:20:36 markc
66 * Added removeAll function to list class.
67 * Added machineType headers to specify pvm, cm5, ...
69 * Revision 1.16 1994/05/30 19:37:39 hollings
70 * added pragma for external g++ functions.
79 #if defined(external_templates)
83 #if !defined(DO_INLINE_P)
87 #if !defined(DO_INLINE_F)
91 #define ListHash(ptr, size) (((unsigned int)(ptr) % (unsigned int)(size)))
93 template <class Type> class List;
94 template <class Type> class StringList;
95 template <class Type> class HTable;
97 template <class Type> class ListItem {
98 friend class List<Type>;
99 friend class StringList<Type>;
103 ListItem<Type> *next;
106 template <class Type> class List {
108 List() { head = NULL; }
109 DO_INLINE_F int empty();
110 friend ostream &operator<<(ostream &os, List<Type> &data) {
112 for (curr= data; *curr; ++curr) {
117 DO_INLINE_F void add(Type data, void *key);
118 DO_INLINE_F void add(Type data);
119 DO_INLINE_F bool addUnique(Type data);
120 bool addUnique(Type data, void *key) {
131 DO_INLINE_F Type find(void *key);
132 DO_INLINE_F bool remove(void *key);
133 DO_INLINE_F void removeAll();
136 ListItem<Type> *curr;
138 for (curr=head,c=0; curr; curr=curr->next) c++;
147 void operator +=(List<Type> mergee) {
148 ListItem<Type> *curr;
150 for (curr=mergee.head; curr; curr=curr->next) {
151 addUnique(curr->data, curr->key);
154 // postfix - the beauty of c++
155 Type operator ++(int) {
156 Type ret = (Type) NULL;
165 Type ret = (Type) NULL;
172 void map (void (*map_function)(const Type item)) {
173 const ListItem<Type> *temp_ptr = 0;
175 if (!map_function) return;
176 for (temp_ptr = head; temp_ptr && temp_ptr->data; temp_ptr = temp_ptr->next)
177 map_function (temp_ptr->data);
180 ListItem<Type> *head;
183 template <class Type> DO_INLINE_F int List<Type>::empty()
185 return (head == NULL);
188 template <class Type> DO_INLINE_F void List<Type>::add(Type data, void *key)
192 ni = new(ListItem<Type>);
200 template <class Type> DO_INLINE_F void List<Type>::add(Type data)
202 add(data, (void *) data);
205 template <class Type> DO_INLINE_F bool List<Type>::addUnique(Type data)
207 return(addUnique(data, (void *) data));
210 template <class Type> DO_INLINE_F void List<Type>::removeAll()
212 ListItem<Type> *curr, *nx;
223 template <class Type> DO_INLINE_F bool List<Type>::remove(void *key)
226 ListItem<Type> *curr;
228 for (curr=head, lag = NULL; curr; curr=curr->next) {
229 if (curr->key == key) {
237 lag->next = curr->next;
248 template <class Type> DO_INLINE_F Type List<Type>::find(void *data)
250 ListItem<Type> *curr;
252 for (curr=head; curr; curr=curr->next) {
253 if (curr->key == data) {
260 template <class Type> ostream &operator<<(ostream &os, HTable<Type> &data);
262 template <class Type> class HTable {
265 // placing function def here makes gcc happy
266 // VG(06/15/02): that nonstandard hack doesn't work with gcc 3.1...
267 // let's do this properly:
268 // (1) the function needs to be already declared (above)
269 // (2) add <> after name here, so only that instantiation is friended
270 // (3) the function is defined after this class
271 // Of course, old broken compilers don't like the standard, so we just
272 // write something that compiles (as was the case before).
273 #if defined(i386_unknown_nt4_0) && _MSC_VER < 1300
274 friend ostream& operator<< (ostream &os, HTable<Type> &data);
276 friend ostream& operator<< <> (ostream &os, HTable<Type> &data);
279 HTable(Type data) { (void) HTable(); add(data, (void *) data); }
280 DO_INLINE_F void add(Type data, void *key);
281 DO_INLINE_F HTable();
282 bool addUnique(Type data, void *key) {
293 DO_INLINE_F Type find(void *key);
294 DO_INLINE_F bool remove(void *key);
295 DO_INLINE_F HTable<Type> operator =(HTable<Type> arg);
300 Type operator ++(int) {
305 if (curr) return(curr);
306 for (currHid++; currHid < tableSize; currHid++) {
307 if (table[currHid]) {
308 currList = *table[currHid];
310 if (curr) return(curr);
321 if (curr) return(curr);
322 for (currHid++; currHid < tableSize; currHid++) {
323 if (table[currHid]) {
324 currList = *table[currHid];
326 if (curr) return(curr);
335 for (i=0; i < tableSize; i++) {
337 total += table[i]->count();
351 template <class Type> ostream &operator<<(ostream &os,
352 HTable<Type> &data) {
356 for (i=0; i < data.tableSize; i++) {
358 os << *data.table[i];
365 template <class Type> DO_INLINE_F HTable<Type> HTable<Type>::operator =(HTable<Type> arg) {
367 tableSize = arg.tableSize;
369 // find the first item.
375 template <class Type> DO_INLINE_F HTable<Type>::HTable()
382 template <class Type> DO_INLINE_F Type HTable<Type>::find(void *key)
386 if (!tableSize) return(NULL);
387 hid = ListHash(key, tableSize);
388 if (hid <0 || hid > tableSize) abort();
392 return(table[hid]->find(key));
396 template <class Type> DO_INLINE_F void HTable<Type>::add(Type data, void *key)
402 table = (List<Type>**) calloc(tableSize, sizeof(List<Type>*));
404 hid = ListHash(key, tableSize);
405 if (hid <0 || hid > tableSize) abort();
407 table[hid] = new(List<Type>);
409 table[hid]->add(data, key);
413 template <class Type> DO_INLINE_F bool HTable<Type>::remove(void *key)
417 hid = ListHash(key, tableSize);
418 if (hid <0 || hid > tableSize) abort();
420 return(table[hid]->remove(key));
425 template <class Type> class StringList: public List<Type> {
427 DO_INLINE_F Type find(void *key);
430 template <class Type> DO_INLINE_F Type StringList<Type>::find(void *data)
432 ListItem<Type> *curr;
434 for (curr=head; curr; curr=curr->next) {
435 if (!strcmp((char *) curr->key, (char *) data)) {