annotate src/share/vm/libadt/set.hpp @ 1972:f95d63e2154a

6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
author stefank
date Tue, 23 Nov 2010 13:22:55 -0800
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_LIBADT_SET_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_LIBADT_SET_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "libadt/port.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30
0
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // Sets - An Abstract Data Type
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 //INTERFACE
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 class SparseSet;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 class VectorSet;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 class ListSet;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 class CoSet;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 class ostream;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 class SetI_;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // These sets can grow or shrink, based on the initial size and the largest
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // element currently in them. Basically, they allow a bunch of bits to be
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // grouped together, tested, set & cleared, intersected, etc. The basic
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Set class is an abstract class, and cannot be constructed. Instead,
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // one of VectorSet, SparseSet, or ListSet is created. Each variation has
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // different asymptotic running times for different operations, and different
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // constants of proportionality as well.
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // {n = number of elements, N = largest element}
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // VectorSet SparseSet ListSet
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // Create O(N) O(1) O(1)
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // Clear O(N) O(1) O(1)
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // Insert O(1) O(1) O(log n)
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // Delete O(1) O(1) O(log n)
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // Member O(1) O(1) O(log n)
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // Size O(N) O(1) O(1)
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Copy O(N) O(n) O(n)
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // Union O(N) O(n) O(n log n)
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // Intersect O(N) O(n) O(n log n)
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // Difference O(N) O(n) O(n log n)
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // Equal O(N) O(n) O(n log n)
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // ChooseMember O(N) O(1) O(1)
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Sort O(1) O(n log n) O(1)
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // Forall O(N) O(n) O(n)
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // Complement O(1) O(1) O(1)
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // TIME: N/32 n 8*n Accesses
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // SPACE: N/8 4*N+4*n 8*n Bytes
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // Create: Make an empty set
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // Clear: Remove all the elements of a Set
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // Insert: Insert an element into a Set; duplicates are ignored
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // Delete: Removes an element from a Set
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // Member: Tests for membership in a Set
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // Size: Returns the number of members of a Set
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // Copy: Copy or assign one Set to another
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // Union: Union 2 sets together
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Intersect: Intersect 2 sets together
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // Difference: Compute A & !B; remove from set A those elements in set B
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // Equal: Test for equality between 2 sets
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // ChooseMember Pick a random member
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // Sort: If no other operation changes the set membership, a following
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // Forall will iterate the members in ascending order.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Forall: Iterate over the elements of a Set. Operations that modify
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // the set membership during iteration work, but the iterator may
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // skip any member or duplicate any member.
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // Complement: Only supported in the Co-Set variations. It adds a small
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // constant-time test to every Set operation.
a61af66fc99e Initial load
duke
parents:
diff changeset
91 //
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // PERFORMANCE ISSUES:
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // If you "cast away" the specific set variation you are using, and then do
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // operations on the basic "Set" object you will pay a virtual function call
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // to get back the specific set variation. On the other hand, using the
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // generic Set means you can change underlying implementations by just
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // changing the initial declaration. Examples:
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // void foo(VectorSet vs1, VectorSet vs2) { vs1 |= vs2; }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // "foo" must be called with a VectorSet. The vector set union operation
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // is called directly.
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // void foo(Set vs1, Set vs2) { vs1 |= vs2; }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // "foo" may be called with *any* kind of sets; suppose it is called with
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // VectorSets. Two virtual function calls are used to figure out the that vs1
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // and vs2 are VectorSets. In addition, if vs2 is not a VectorSet then a
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // temporary VectorSet copy of vs2 will be made before the union proceeds.
a61af66fc99e Initial load
duke
parents:
diff changeset
106 //
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // VectorSets have a small constant. Time and space are proportional to the
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // largest element. Fine for dense sets and largest element < 10,000.
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // SparseSets have a medium constant. Time is proportional to the number of
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // elements, space is proportional to the largest element.
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // Fine (but big) with the largest element < 100,000.
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // ListSets have a big constant. Time *and space* are proportional to the
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // number of elements. They work well for a few elements of *any* size
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // (i.e. sets of pointers)!
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 //------------------------------Set--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
117 class Set : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // Creates a new, empty set.
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // DO NOT CONSTRUCT A Set. THIS IS AN ABSTRACT CLASS, FOR INHERITENCE ONLY
a61af66fc99e Initial load
duke
parents:
diff changeset
122 Set(Arena *arena) : _set_arena(arena) {};
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // Creates a new set from an existing set
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // DO NOT CONSTRUCT A Set. THIS IS AN ABSTRACT CLASS, FOR INHERITENCE ONLY
a61af66fc99e Initial load
duke
parents:
diff changeset
126 Set(const Set &) {};
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // Set assignment; deep-copy guts
a61af66fc99e Initial load
duke
parents:
diff changeset
129 virtual Set &operator =(const Set &s)=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 virtual Set &clone(void) const=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // Virtual destructor
a61af66fc99e Initial load
duke
parents:
diff changeset
133 virtual ~Set() {};
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Add member to set
a61af66fc99e Initial load
duke
parents:
diff changeset
136 virtual Set &operator <<=(uint elem)=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // virtual Set operator << (uint elem);
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // Delete member from set
a61af66fc99e Initial load
duke
parents:
diff changeset
140 virtual Set &operator >>=(uint elem)=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // virtual Set operator >> (uint elem);
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Membership test. Result is Zero (absent)/ Non-Zero (present)
a61af66fc99e Initial load
duke
parents:
diff changeset
144 virtual int operator [](uint elem) const=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // Intersect sets
a61af66fc99e Initial load
duke
parents:
diff changeset
147 virtual Set &operator &=(const Set &s)=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // virtual Set operator & (const Set &s) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // Union sets
a61af66fc99e Initial load
duke
parents:
diff changeset
151 virtual Set &operator |=(const Set &s)=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // virtual Set operator | (const Set &s) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // Difference sets
a61af66fc99e Initial load
duke
parents:
diff changeset
155 virtual Set &operator -=(const Set &s)=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // virtual Set operator - (const Set &s) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // Tests for equality. Result is Zero (false)/ Non-Zero (true)
a61af66fc99e Initial load
duke
parents:
diff changeset
159 virtual int operator ==(const Set &s) const=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 int operator !=(const Set &s) const { return !(*this == s); }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 virtual int disjoint(const Set &s) const=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // Tests for strict subset. Result is Zero (false)/ Non-Zero (true)
a61af66fc99e Initial load
duke
parents:
diff changeset
164 virtual int operator < (const Set &s) const=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 int operator > (const Set &s) const { return s < *this; }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Tests for subset. Result is Zero (false)/ Non-Zero (true)
a61af66fc99e Initial load
duke
parents:
diff changeset
168 virtual int operator <=(const Set &s) const=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 int operator >=(const Set &s) const { return s <= *this; }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // Return any member of the Set. Undefined if the Set is empty.
a61af66fc99e Initial load
duke
parents:
diff changeset
172 virtual uint getelem(void) const=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // Clear all the elements in the Set
a61af66fc99e Initial load
duke
parents:
diff changeset
175 virtual void Clear(void)=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // Return the number of members in the Set
a61af66fc99e Initial load
duke
parents:
diff changeset
178 virtual uint Size(void) const=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // If an iterator follows a "Sort()" without any Set-modifying operations
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // inbetween then the iterator will visit the elements in ascending order.
a61af66fc99e Initial load
duke
parents:
diff changeset
182 virtual void Sort(void)=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // Convert a set to printable string in an allocated buffer.
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // The caller must deallocate the string.
a61af66fc99e Initial load
duke
parents:
diff changeset
186 virtual char *setstr(void) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // Print the Set on "stdout". Can be conveniently called in the debugger
a61af66fc99e Initial load
duke
parents:
diff changeset
189 void print() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // Parse text from the string into the Set. Return length parsed.
a61af66fc99e Initial load
duke
parents:
diff changeset
192 virtual int parse(const char *s);
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // Convert a generic Set to a specific Set
a61af66fc99e Initial load
duke
parents:
diff changeset
195 /* Removed for MCC BUG
a61af66fc99e Initial load
duke
parents:
diff changeset
196 virtual operator const SparseSet* (void) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 virtual operator const VectorSet* (void) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
198 virtual operator const ListSet * (void) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 virtual operator const CoSet * (void) const; */
a61af66fc99e Initial load
duke
parents:
diff changeset
200 virtual const SparseSet *asSparseSet(void) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 virtual const VectorSet *asVectorSet(void) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 virtual const ListSet *asListSet (void) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
203 virtual const CoSet *asCoSet (void) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // Hash the set. Sets of different types but identical elements will NOT
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // hash the same. Same set type, same elements WILL hash the same.
a61af66fc99e Initial load
duke
parents:
diff changeset
207 virtual int hash() const = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
210 friend class SetI;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 friend class CoSet;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 virtual class SetI_ *iterate(uint&) const=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // Need storeage for the set
a61af66fc99e Initial load
duke
parents:
diff changeset
215 Arena *_set_arena;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 };
a61af66fc99e Initial load
duke
parents:
diff changeset
217 typedef Set&((*Set_Constructor)(Arena *arena));
a61af66fc99e Initial load
duke
parents:
diff changeset
218 extern Set &ListSet_Construct(Arena *arena);
a61af66fc99e Initial load
duke
parents:
diff changeset
219 extern Set &VectorSet_Construct(Arena *arena);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 extern Set &SparseSet_Construct(Arena *arena);
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 //------------------------------Iteration--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // Loop thru all elements of the set, setting "elem" to the element numbers
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // in random order. Inserted or deleted elements during this operation may
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // or may not be iterated over; untouched elements will be affected once.
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // Usage: for( SetI i(s); i.test(); i++ ) { body = i.elem; } ...OR...
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // for( i.reset(s); i.test(); i++ ) { body = i.elem; }
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 class SetI_ : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
232 friend class SetI;
a61af66fc99e Initial load
duke
parents:
diff changeset
233 virtual ~SetI_();
a61af66fc99e Initial load
duke
parents:
diff changeset
234 virtual uint next(void)=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 virtual int test(void)=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 };
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 class SetI {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
240 SetI_ *impl;
a61af66fc99e Initial load
duke
parents:
diff changeset
241 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
242 uint elem; // The publically accessible element
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 SetI( const Set *s ) { impl = s->iterate(elem); }
a61af66fc99e Initial load
duke
parents:
diff changeset
245 ~SetI() { delete impl; }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 void reset( const Set *s ) { delete impl; impl = s->iterate(elem); }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 void operator ++(void) { elem = impl->next(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 int test(void) { return impl->test(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 };
a61af66fc99e Initial load
duke
parents:
diff changeset
250
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
251 #endif // SHARE_VM_LIBADT_SET_HPP