annotate src/share/vm/libadt/vectset.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 3763ca6579b7
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_VECTSET_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_LIBADT_VECTSET_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/set.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // Vector Sets - An Abstract Data Type
a61af66fc99e Initial load
duke
parents:
diff changeset
31 //INTERFACE
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // These sets can grow or shrink, based on the initial size and the largest
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // element currently in them. Slow and bulky for sparse sets, these sets
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // are super for dense sets. They are fast and compact when dense.
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // TIME:
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // O(1) - Insert, Delete, Member, Sort
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // O(max_element) - Create, Clear, Size, Copy, Union, Intersect, Difference,
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Equal, ChooseMember, Forall
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // SPACE: (max_element)/(8*sizeof(int))
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 //------------------------------VectorSet--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
46 class VectorSet : public Set {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 friend class VectorSetI; // Friendly iterator class
a61af66fc99e Initial load
duke
parents:
diff changeset
48 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
49 uint size; // Size of data IN LONGWORDS (32bits)
a61af66fc99e Initial load
duke
parents:
diff changeset
50 uint32 *data; // The data, bit packed
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 void slamin( const VectorSet& s ); // Initialize one set with another
a61af66fc99e Initial load
duke
parents:
diff changeset
53 int compare(const VectorSet &s) const; // Compare set contents
a61af66fc99e Initial load
duke
parents:
diff changeset
54 void grow(uint newsize); // Grow vector to required bitsize
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
57 VectorSet(Arena *arena); // Creates a new, empty set.
a61af66fc99e Initial load
duke
parents:
diff changeset
58 VectorSet(const VectorSet &s) : Set(s._set_arena) {slamin(s);} // Set clone; deep-copy guts
a61af66fc99e Initial load
duke
parents:
diff changeset
59 Set &operator =(const Set &s); // Set clone; deep-copy guts
a61af66fc99e Initial load
duke
parents:
diff changeset
60 VectorSet &operator =(const VectorSet &s) // Set clone; deep-copy guts
a61af66fc99e Initial load
duke
parents:
diff changeset
61 { if( &s != this ) { slamin(s); } return *this; }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 ~VectorSet() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
63 Set &clone(void) const { return *(new VectorSet(*this)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 Set &operator <<=(uint elem); // Add member to set
a61af66fc99e Initial load
duke
parents:
diff changeset
66 VectorSet operator << (uint elem) // Add member to new set
a61af66fc99e Initial load
duke
parents:
diff changeset
67 { VectorSet foo(*this); foo <<= elem; return foo; }
a61af66fc99e Initial load
duke
parents:
diff changeset
68 Set &operator >>=(uint elem); // Delete member from set
a61af66fc99e Initial load
duke
parents:
diff changeset
69 VectorSet operator >> (uint elem) // Delete member from new set
a61af66fc99e Initial load
duke
parents:
diff changeset
70 { VectorSet foo(*this); foo >>= elem; return foo; }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 VectorSet &operator &=(const VectorSet &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
73 Set &operator &=(const Set &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
74 VectorSet operator & (const VectorSet &s) const
a61af66fc99e Initial load
duke
parents:
diff changeset
75 { VectorSet foo(*this); foo &= s; return foo; }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 VectorSet &operator |=(const VectorSet &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
78 Set &operator |=(const Set &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
79 VectorSet operator | (const VectorSet &s) const
a61af66fc99e Initial load
duke
parents:
diff changeset
80 { VectorSet foo(*this); foo |= s; return foo; }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 VectorSet &operator -=(const VectorSet &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
83 Set &operator -=(const Set &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
84 VectorSet operator - (const VectorSet &s) const
a61af66fc99e Initial load
duke
parents:
diff changeset
85 { VectorSet foo(*this); foo -= s; return foo; }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 int operator ==(const VectorSet &s) const; // True if sets are equal
a61af66fc99e Initial load
duke
parents:
diff changeset
88 int operator ==(const Set &s) const; // True if sets are equal
a61af66fc99e Initial load
duke
parents:
diff changeset
89 int operator < (const VectorSet &s) const; // True if strict subset
a61af66fc99e Initial load
duke
parents:
diff changeset
90 int operator < (const Set &s) const; // True if strict subset
a61af66fc99e Initial load
duke
parents:
diff changeset
91 int operator <=(const VectorSet &s) const; // True if subset relation holds.
a61af66fc99e Initial load
duke
parents:
diff changeset
92 int operator <=(const Set &s) const; // True if subset relation holds.
a61af66fc99e Initial load
duke
parents:
diff changeset
93 int disjoint (const Set &s) const; // True if sets are disjoint
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 int operator [](uint elem) const; // Test for membership
a61af66fc99e Initial load
duke
parents:
diff changeset
96 uint getelem(void) const; // Return a random element
a61af66fc99e Initial load
duke
parents:
diff changeset
97 void Clear(void); // Clear a set
a61af66fc99e Initial load
duke
parents:
diff changeset
98 uint Size(void) const; // Number of elements in the Set.
a61af66fc99e Initial load
duke
parents:
diff changeset
99 void Sort(void); // Sort before iterating
a61af66fc99e Initial load
duke
parents:
diff changeset
100 int hash() const; // Hash function
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 /* Removed for MCC BUG
a61af66fc99e Initial load
duke
parents:
diff changeset
103 operator const VectorSet* (void) const { return this; } */
a61af66fc99e Initial load
duke
parents:
diff changeset
104 const VectorSet *asVectorSet() const { return this; }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // Expose internals for speed-critical fast iterators
a61af66fc99e Initial load
duke
parents:
diff changeset
107 uint word_size() const { return size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 uint32 *EXPOSE() const { return data; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Fast inlined "test and set". Replaces the idiom:
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // if( visited[idx] ) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // visited <<= idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // With:
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // if( visited.test_set(idx) ) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 //
a61af66fc99e Initial load
duke
parents:
diff changeset
116 int test_set( uint elem ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 uint word = elem >> 5; // Get the longword offset
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if( word >= size ) // Beyond the last?
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return test_set_grow(elem); // Then grow; set; return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 uint32 mask = 1L << (elem & 31); // Get bit mask
a61af66fc99e Initial load
duke
parents:
diff changeset
121 uint32 datum = data[word] & mask;// Get bit
a61af66fc99e Initial load
duke
parents:
diff changeset
122 data[word] |= mask; // Set bit
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return datum; // Return bit
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 int test_set_grow( uint elem ) { // Insert & return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 (*this) <<= elem; // Insert into set
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return 0; // Return 0!
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // Fast inlined test
a61af66fc99e Initial load
duke
parents:
diff changeset
131 int test( uint elem ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 uint word = elem >> 5; // Get the longword offset
a61af66fc99e Initial load
duke
parents:
diff changeset
133 if( word >= size ) return 0; // Beyond the last?
a61af66fc99e Initial load
duke
parents:
diff changeset
134 uint32 mask = 1L << (elem & 31); // Get bit mask
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return data[word] & mask; // Get bit
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // Fast inlined set
a61af66fc99e Initial load
duke
parents:
diff changeset
139 void set( uint elem ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 uint word = elem >> 5; // Get the longword offset
a61af66fc99e Initial load
duke
parents:
diff changeset
141 if( word >= size ) { // Beyond the last?
a61af66fc99e Initial load
duke
parents:
diff changeset
142 test_set_grow(elem); // Then grow and set
a61af66fc99e Initial load
duke
parents:
diff changeset
143 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 uint32 mask = 1L << (elem & 31); // Get bit mask
a61af66fc99e Initial load
duke
parents:
diff changeset
145 data[word] |= mask; // Set bit
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
151 friend class VSetI_;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 SetI_ *iterate(uint&) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 };
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 //------------------------------Iteration--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // Loop thru all elements of the set, setting "elem" to the element numbers
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // in random order. Inserted or deleted elements during this operation may
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // or may not be iterated over; untouched elements will be affected once.
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // Usage: for( VectorSetI i(s); i.test(); i++ ) { body = i.elem; }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 class VSetI_ : public SetI_ {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 friend class VectorSet;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 friend class VectorSetI;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 const VectorSet *s;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 uint i, j;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 uint32 mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 VSetI_(const VectorSet *vset);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 uint next(void);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 int test(void) { return i < s->size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 };
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 class VectorSetI : public SetI {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
174 VectorSetI( const VectorSet *s ) : SetI(s) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 void operator ++(void) { elem = ((VSetI_*)impl)->next(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 int test(void) { return ((VSetI_*)impl)->test(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 };
a61af66fc99e Initial load
duke
parents:
diff changeset
178
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
179 #endif // SHARE_VM_LIBADT_VECTSET_HPP