annotate src/share/vm/libadt/vectset.cpp @ 18096:ca6d25be853b jdk8u25-b13

8044269: Analysis of archive files. Summary: Add checksum verification. Reviewed-by: iklam, dholmes, mschoene
author jiangli
date Tue, 12 Aug 2014 17:46:16 -0400
parents b9a9ed0f8eeb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6842
b9a9ed0f8eeb 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 6197
diff changeset
2 * Copyright (c) 1997, 2012, 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 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "libadt/vectset.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "memory/allocation.inline.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
28
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 // Vector Sets - An Abstract Data Type
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // %%%%% includes not needed with AVM framework - Ungar
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // #include "port.hpp"
a61af66fc99e Initial load
duke
parents:
diff changeset
33 //IMPLEMENTATION
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // #include "vectset.hpp"
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // BitsInByte is a lookup table which tells the number of bits that
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // are in the looked-up number. It is very useful in VectorSet_Size.
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 uint8 bitsInByte[256] = {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
a61af66fc99e Initial load
duke
parents:
diff changeset
41 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
a61af66fc99e Initial load
duke
parents:
diff changeset
42 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
a61af66fc99e Initial load
duke
parents:
diff changeset
43 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
a61af66fc99e Initial load
duke
parents:
diff changeset
44 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
a61af66fc99e Initial load
duke
parents:
diff changeset
45 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
a61af66fc99e Initial load
duke
parents:
diff changeset
46 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
a61af66fc99e Initial load
duke
parents:
diff changeset
47 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
a61af66fc99e Initial load
duke
parents:
diff changeset
48 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
a61af66fc99e Initial load
duke
parents:
diff changeset
49 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
a61af66fc99e Initial load
duke
parents:
diff changeset
50 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
a61af66fc99e Initial load
duke
parents:
diff changeset
51 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
a61af66fc99e Initial load
duke
parents:
diff changeset
52 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
a61af66fc99e Initial load
duke
parents:
diff changeset
53 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
a61af66fc99e Initial load
duke
parents:
diff changeset
54 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
a61af66fc99e Initial load
duke
parents:
diff changeset
55 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
a61af66fc99e Initial load
duke
parents:
diff changeset
56 };
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 //------------------------------VectorSet--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Create a new, empty Set.
a61af66fc99e Initial load
duke
parents:
diff changeset
60 VectorSet::VectorSet(Arena *arena) : Set(arena) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 size = 2; // Small initial size
a61af66fc99e Initial load
duke
parents:
diff changeset
62 data = (uint32 *)_set_arena->Amalloc(size*sizeof(uint32));
a61af66fc99e Initial load
duke
parents:
diff changeset
63 data[0] = 0; // No elements
a61af66fc99e Initial load
duke
parents:
diff changeset
64 data[1] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 //------------------------------Construct--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
68 Set &VectorSet_Construct(Arena *arena)
a61af66fc99e Initial load
duke
parents:
diff changeset
69 {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return *(new VectorSet(arena));
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 //------------------------------operator=--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
74 Set &VectorSet::operator = (const Set &set)
a61af66fc99e Initial load
duke
parents:
diff changeset
75 {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if( &set == this ) return *this;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 FREE_FAST(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // The cast is a virtual function that checks that "set" is a VectorSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
79 slamin(*(set.asVectorSet()));
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return *this;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 //------------------------------slamin-----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // Initialize one set with another. No regard is made to the existing Set.
a61af66fc99e Initial load
duke
parents:
diff changeset
85 void VectorSet::slamin(const VectorSet& s)
a61af66fc99e Initial load
duke
parents:
diff changeset
86 {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 size = s.size; // Use new size
a61af66fc99e Initial load
duke
parents:
diff changeset
88 data = (uint32*)s._set_arena->Amalloc(size*sizeof(uint32)); // Make array of required size
a61af66fc99e Initial load
duke
parents:
diff changeset
89 memcpy( data, s.data, size*sizeof(uint32) ); // Fill the array
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 //------------------------------grow-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Expand the existing set to a bigger size
a61af66fc99e Initial load
duke
parents:
diff changeset
94 void VectorSet::grow( uint newsize )
a61af66fc99e Initial load
duke
parents:
diff changeset
95 {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 newsize = (newsize+31) >> 5; // Convert to longwords
a61af66fc99e Initial load
duke
parents:
diff changeset
97 uint x = size;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 while( x < newsize ) x <<= 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 data = (uint32 *)_set_arena->Arealloc(data, size*sizeof(uint32), x*sizeof(uint32));
a61af66fc99e Initial load
duke
parents:
diff changeset
100 memset((char *)(data + size), 0, (x - size)*sizeof(uint32));
a61af66fc99e Initial load
duke
parents:
diff changeset
101 size = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 //------------------------------operator<<=------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // Insert a member into an existing Set.
a61af66fc99e Initial load
duke
parents:
diff changeset
106 Set &VectorSet::operator <<= (uint elem)
a61af66fc99e Initial load
duke
parents:
diff changeset
107 {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 register uint word = elem >> 5; // Get the longword offset
a61af66fc99e Initial load
duke
parents:
diff changeset
109 register uint32 mask = 1L << (elem & 31); // Get bit mask
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if( word >= size ) // Need to grow set?
a61af66fc99e Initial load
duke
parents:
diff changeset
112 grow(elem+1); // Then grow it
a61af66fc99e Initial load
duke
parents:
diff changeset
113 data[word] |= mask; // Set new bit
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return *this;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 //------------------------------operator>>=------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // Delete a member from an existing Set.
a61af66fc99e Initial load
duke
parents:
diff changeset
119 Set &VectorSet::operator >>= (uint elem)
a61af66fc99e Initial load
duke
parents:
diff changeset
120 {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 register uint word = elem >> 5; // Get the longword offset
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if( word >= size ) // Beyond the last?
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return *this; // Then it's clear & return clear
a61af66fc99e Initial load
duke
parents:
diff changeset
124 register uint32 mask = 1L << (elem & 31); // Get bit mask
a61af66fc99e Initial load
duke
parents:
diff changeset
125 data[word] &= ~mask; // Clear bit
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return *this;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 //------------------------------operator&=-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // Intersect one set into another.
a61af66fc99e Initial load
duke
parents:
diff changeset
131 VectorSet &VectorSet::operator &= (const VectorSet &s)
a61af66fc99e Initial load
duke
parents:
diff changeset
132 {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // NOTE: The intersection is never any larger than the smallest set.
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if( s.size < size ) size = s.size; // Get smaller size
a61af66fc99e Initial load
duke
parents:
diff changeset
135 register uint32 *u1 = data; // Pointer to the destination data
a61af66fc99e Initial load
duke
parents:
diff changeset
136 register uint32 *u2 = s.data; // Pointer to the source data
a61af66fc99e Initial load
duke
parents:
diff changeset
137 for( uint i=0; i<size; i++) // For data in set
a61af66fc99e Initial load
duke
parents:
diff changeset
138 *u1++ &= *u2++; // Copy and AND longwords
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return *this; // Return set
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 //------------------------------operator&=-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
143 Set &VectorSet::operator &= (const Set &set)
a61af66fc99e Initial load
duke
parents:
diff changeset
144 {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // The cast is a virtual function that checks that "set" is a VectorSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return (*this) &= *(set.asVectorSet());
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 //------------------------------operator|=-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // Union one set into another.
a61af66fc99e Initial load
duke
parents:
diff changeset
151 VectorSet &VectorSet::operator |= (const VectorSet &s)
a61af66fc99e Initial load
duke
parents:
diff changeset
152 {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // This many words must be unioned
a61af66fc99e Initial load
duke
parents:
diff changeset
154 register uint cnt = ((size<s.size)?size:s.size);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 register uint32 *u1 = data; // Pointer to the destination data
a61af66fc99e Initial load
duke
parents:
diff changeset
156 register uint32 *u2 = s.data; // Pointer to the source data
a61af66fc99e Initial load
duke
parents:
diff changeset
157 for( uint i=0; i<cnt; i++) // Copy and OR the two sets
a61af66fc99e Initial load
duke
parents:
diff changeset
158 *u1++ |= *u2++;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if( size < s.size ) { // Is set 2 larger than set 1?
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Extend result by larger set
a61af66fc99e Initial load
duke
parents:
diff changeset
161 grow(s.size*sizeof(uint32)*8);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 memcpy(&data[cnt], u2, (s.size - cnt)*sizeof(uint32));
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 return *this; // Return result set
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 //------------------------------operator|=-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
168 Set &VectorSet::operator |= (const Set &set)
a61af66fc99e Initial load
duke
parents:
diff changeset
169 {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // The cast is a virtual function that checks that "set" is a VectorSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
171 return (*this) |= *(set.asVectorSet());
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 //------------------------------operator-=-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // Difference one set from another.
a61af66fc99e Initial load
duke
parents:
diff changeset
176 VectorSet &VectorSet::operator -= (const VectorSet &s)
a61af66fc99e Initial load
duke
parents:
diff changeset
177 {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // This many words must be unioned
a61af66fc99e Initial load
duke
parents:
diff changeset
179 register uint cnt = ((size<s.size)?size:s.size);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 register uint32 *u1 = data; // Pointer to the destination data
a61af66fc99e Initial load
duke
parents:
diff changeset
181 register uint32 *u2 = s.data; // Pointer to the source data
a61af66fc99e Initial load
duke
parents:
diff changeset
182 for( uint i=0; i<cnt; i++ ) // For data in set
a61af66fc99e Initial load
duke
parents:
diff changeset
183 *u1++ &= ~(*u2++); // A <-- A & ~B with longwords
a61af66fc99e Initial load
duke
parents:
diff changeset
184 return *this; // Return new set
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 //------------------------------operator-=-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
188 Set &VectorSet::operator -= (const Set &set)
a61af66fc99e Initial load
duke
parents:
diff changeset
189 {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // The cast is a virtual function that checks that "set" is a VectorSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
191 return (*this) -= *(set.asVectorSet());
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 //------------------------------compare----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // Compute 2 booleans: bits in A not B, bits in B not A.
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // Return X0 -- A is not a subset of B
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // X1 -- A is a subset of B
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // 0X -- B is not a subset of A
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // 1X -- B is a subset of A
a61af66fc99e Initial load
duke
parents:
diff changeset
200 int VectorSet::compare (const VectorSet &s) const
a61af66fc99e Initial load
duke
parents:
diff changeset
201 {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 register uint32 *u1 = data; // Pointer to the destination data
a61af66fc99e Initial load
duke
parents:
diff changeset
203 register uint32 *u2 = s.data; // Pointer to the source data
a61af66fc99e Initial load
duke
parents:
diff changeset
204 register uint32 AnotB = 0, BnotA = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // This many words must be unioned
a61af66fc99e Initial load
duke
parents:
diff changeset
206 register uint cnt = ((size<s.size)?size:s.size);
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // Get bits for both sets
a61af66fc99e Initial load
duke
parents:
diff changeset
209 uint i; // Exit value of loop
a61af66fc99e Initial load
duke
parents:
diff changeset
210 for( i=0; i<cnt; i++ ) { // For data in BOTH sets
a61af66fc99e Initial load
duke
parents:
diff changeset
211 register uint32 A = *u1++; // Data from one guy
a61af66fc99e Initial load
duke
parents:
diff changeset
212 register uint32 B = *u2++; // Data from other guy
a61af66fc99e Initial load
duke
parents:
diff changeset
213 AnotB |= (A & ~B); // Compute bits in A not B
a61af66fc99e Initial load
duke
parents:
diff changeset
214 BnotA |= (B & ~A); // Compute bits in B not A
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // Get bits from bigger set
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if( size < s.size ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 for( ; i<s.size; i++ ) // For data in larger set
a61af66fc99e Initial load
duke
parents:
diff changeset
220 BnotA |= *u2++; // These bits are in B not A
a61af66fc99e Initial load
duke
parents:
diff changeset
221 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 for( ; i<size; i++ ) // For data in larger set
a61af66fc99e Initial load
duke
parents:
diff changeset
223 AnotB |= *u1++; // These bits are in A not B
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // Set & return boolean flags
a61af66fc99e Initial load
duke
parents:
diff changeset
227 return ((!BnotA)<<1) + (!AnotB);
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 //------------------------------operator==-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // Test for set equality
a61af66fc99e Initial load
duke
parents:
diff changeset
232 int VectorSet::operator == (const VectorSet &s) const
a61af66fc99e Initial load
duke
parents:
diff changeset
233 {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 return compare(s) == 3; // TRUE if A and B are mutual subsets
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 //------------------------------operator==-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
238 int VectorSet::operator == (const Set &set) const
a61af66fc99e Initial load
duke
parents:
diff changeset
239 {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // The cast is a virtual function that checks that "set" is a VectorSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
241 return (*this) == *(set.asVectorSet());
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 //------------------------------disjoint---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // Check for sets being disjoint.
a61af66fc99e Initial load
duke
parents:
diff changeset
246 int VectorSet::disjoint(const Set &set) const
a61af66fc99e Initial load
duke
parents:
diff changeset
247 {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 // The cast is a virtual function that checks that "set" is a VectorSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
249 const VectorSet &s = *(set.asVectorSet());
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // NOTE: The intersection is never any larger than the smallest set.
1983
c760f78e0a53 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 1972
diff changeset
252 register uint small_size = ((size<s.size)?size:s.size);
c760f78e0a53 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 1972
diff changeset
253 register uint32 *u1 = data; // Pointer to the destination data
c760f78e0a53 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 1972
diff changeset
254 register uint32 *u2 = s.data; // Pointer to the source data
c760f78e0a53 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 1972
diff changeset
255 for( uint i=0; i<small_size; i++) // For data in set
c760f78e0a53 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 1972
diff changeset
256 if( *u1++ & *u2++ ) // If any elements in common
c760f78e0a53 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 1972
diff changeset
257 return 0; // Then not disjoint
c760f78e0a53 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 1972
diff changeset
258 return 1; // Else disjoint
0
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 //------------------------------operator<--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // Test for strict subset
a61af66fc99e Initial load
duke
parents:
diff changeset
263 int VectorSet::operator < (const VectorSet &s) const
a61af66fc99e Initial load
duke
parents:
diff changeset
264 {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 return compare(s) == 1; // A subset B, B not subset A
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 //------------------------------operator<--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
269 int VectorSet::operator < (const Set &set) const
a61af66fc99e Initial load
duke
parents:
diff changeset
270 {
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // The cast is a virtual function that checks that "set" is a VectorSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
272 return (*this) < *(set.asVectorSet());
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 //------------------------------operator<=-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // Test for subset
a61af66fc99e Initial load
duke
parents:
diff changeset
277 int VectorSet::operator <= (const VectorSet &s) const
a61af66fc99e Initial load
duke
parents:
diff changeset
278 {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 return compare(s) & 1; // A subset B
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 //------------------------------operator<=-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
283 int VectorSet::operator <= (const Set &set) const
a61af66fc99e Initial load
duke
parents:
diff changeset
284 {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // The cast is a virtual function that checks that "set" is a VectorSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
286 return (*this) <= *(set.asVectorSet());
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 //------------------------------operator[]-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // Test for membership. A Zero/Non-Zero value is returned!
a61af66fc99e Initial load
duke
parents:
diff changeset
291 int VectorSet::operator[](uint elem) const
a61af66fc99e Initial load
duke
parents:
diff changeset
292 {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 register uint word = elem >> 5; // Get the longword offset
a61af66fc99e Initial load
duke
parents:
diff changeset
294 if( word >= size ) // Beyond the last?
a61af66fc99e Initial load
duke
parents:
diff changeset
295 return 0; // Then it's clear
a61af66fc99e Initial load
duke
parents:
diff changeset
296 register uint32 mask = 1L << (elem & 31); // Get bit mask
a61af66fc99e Initial load
duke
parents:
diff changeset
297 return ((data[word] & mask))!=0; // Return the sense of the bit
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 //------------------------------getelem----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
301 // Get any element from the set.
a61af66fc99e Initial load
duke
parents:
diff changeset
302 uint VectorSet::getelem(void) const
a61af66fc99e Initial load
duke
parents:
diff changeset
303 {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 uint i; // Exit value of loop
a61af66fc99e Initial load
duke
parents:
diff changeset
305 for( i=0; i<size; i++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
306 if( data[i] )
a61af66fc99e Initial load
duke
parents:
diff changeset
307 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
308 uint32 word = data[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
309 int j; // Exit value of loop
a61af66fc99e Initial load
duke
parents:
diff changeset
310 for( j= -1; word; j++, word>>=1 );
a61af66fc99e Initial load
duke
parents:
diff changeset
311 return (i<<5)+j;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314 //------------------------------Clear------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // Clear a set
a61af66fc99e Initial load
duke
parents:
diff changeset
316 void VectorSet::Clear(void)
a61af66fc99e Initial load
duke
parents:
diff changeset
317 {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 if( size > 100 ) { // Reclaim storage only if huge
a61af66fc99e Initial load
duke
parents:
diff changeset
319 FREE_RESOURCE_ARRAY(uint32,data,size);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 size = 2; // Small initial size
a61af66fc99e Initial load
duke
parents:
diff changeset
321 data = NEW_RESOURCE_ARRAY(uint32,size);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323 memset( data, 0, size*sizeof(uint32) );
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326 //------------------------------Size-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // Return number of elements in a Set
a61af66fc99e Initial load
duke
parents:
diff changeset
328 uint VectorSet::Size(void) const
a61af66fc99e Initial load
duke
parents:
diff changeset
329 {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 uint sum = 0; // Cumulative size so far.
a61af66fc99e Initial load
duke
parents:
diff changeset
331 uint8 *currByte = (uint8*)data;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 for( uint32 i = 0; i < (size<<2); i++) // While have bytes to process
a61af66fc99e Initial load
duke
parents:
diff changeset
333 sum += bitsInByte[*currByte++]; // Add bits in current byte to size.
a61af66fc99e Initial load
duke
parents:
diff changeset
334 return sum;
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336
a61af66fc99e Initial load
duke
parents:
diff changeset
337 //------------------------------Sort-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // Sort the elements for the next forall statement
a61af66fc99e Initial load
duke
parents:
diff changeset
339 void VectorSet::Sort(void)
a61af66fc99e Initial load
duke
parents:
diff changeset
340 {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 //------------------------------hash-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
344 int VectorSet::hash() const
a61af66fc99e Initial load
duke
parents:
diff changeset
345 {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 uint32 _xor = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 uint lim = ((size<4)?size:4);
a61af66fc99e Initial load
duke
parents:
diff changeset
348 for( uint i = 0; i < lim; i++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
349 _xor ^= data[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
350 return (int)_xor;
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352
4051
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
353 //------------------------------iterate----------------------------------------
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
354 // Used by Set::print().
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
355 class VSetI_ : public SetI_ {
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
356 VectorSetI vsi;
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
357 public:
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
358 VSetI_( const VectorSet *vset, uint &elem ) : vsi(vset) { elem = vsi.elem; }
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
359
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
360 uint next(void) { ++vsi; return vsi.elem; }
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
361 int test(void) { return vsi.test(); }
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
362 };
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
363
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
364 SetI_ *VectorSet::iterate(uint &elem) const {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 4051
diff changeset
365 return new(ResourceObj::C_HEAP, mtInternal) VSetI_(this, elem);
4051
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
366 }
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
367
0
a61af66fc99e Initial load
duke
parents:
diff changeset
368 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
369 //------------------------------next-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // Find and return the next element of a vector set, or return garbage and
2249
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1983
diff changeset
371 // make "VectorSetI::test()" fail.
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1983
diff changeset
372 uint VectorSetI::next(void)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
373 {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 j++; // Next element in word
a61af66fc99e Initial load
duke
parents:
diff changeset
375 mask = (mask & max_jint) << 1;// Next bit in word
a61af66fc99e Initial load
duke
parents:
diff changeset
376 do { // Do While still have words
a61af66fc99e Initial load
duke
parents:
diff changeset
377 while( mask ) { // While have bits in word
a61af66fc99e Initial load
duke
parents:
diff changeset
378 if( s->data[i] & mask ) { // If found a bit
a61af66fc99e Initial load
duke
parents:
diff changeset
379 return (i<<5)+j; // Return the bit address
a61af66fc99e Initial load
duke
parents:
diff changeset
380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
381 j++; // Skip to next bit
a61af66fc99e Initial load
duke
parents:
diff changeset
382 mask = (mask & max_jint) << 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
384 j = 0; // No more bits in word; setup for next word
a61af66fc99e Initial load
duke
parents:
diff changeset
385 mask = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 for( i++; (i<s->size) && (!s->data[i]); i++ ); // Skip to non-zero word
a61af66fc99e Initial load
duke
parents:
diff changeset
387 } while( i<s->size );
a61af66fc99e Initial load
duke
parents:
diff changeset
388 return max_juint; // No element, iterated them all
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }