1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
132
133 // Fast inlined test
134 int test( uint elem ) const {
135 uint word = elem >> 5; // Get the longword offset
136 if( word >= size ) return 0; // Beyond the last?
137 uint32 mask = 1L << (elem & 31); // Get bit mask
138 return data[word] & mask; // Get bit
139 }
140
141 // Fast inlined set
142 void set( uint elem ) {
143 uint word = elem >> 5; // Get the longword offset
144 if( word >= size ) { // Beyond the last?
145 test_set_grow(elem); // Then grow and set
146 } else {
147 uint32 mask = 1L << (elem & 31); // Get bit mask
148 data[word] |= mask; // Set bit
149 }
150 }
151
152
153 private:
154 SetI_ *iterate(uint&) const;
155 };
156
157 //------------------------------Iteration--------------------------------------
158 // Loop thru all elements of the set, setting "elem" to the element numbers
159 // in random order. Inserted or deleted elements during this operation may
160 // or may not be iterated over; untouched elements will be affected once.
161 // Usage: for( VectorSetI i(s); i.test(); i++ ) { body = i.elem; }
162
163 class VectorSetI : public StackObj {
164 friend class VectorSet;
165 const VectorSet *s;
166 uint i, j;
167 uint32 mask;
168 uint next(void);
169
170 public:
171 uint elem; // The publically accessible element
|
1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
132
133 // Fast inlined test
134 int test( uint elem ) const {
135 uint word = elem >> 5; // Get the longword offset
136 if( word >= size ) return 0; // Beyond the last?
137 uint32 mask = 1L << (elem & 31); // Get bit mask
138 return data[word] & mask; // Get bit
139 }
140
141 // Fast inlined set
142 void set( uint elem ) {
143 uint word = elem >> 5; // Get the longword offset
144 if( word >= size ) { // Beyond the last?
145 test_set_grow(elem); // Then grow and set
146 } else {
147 uint32 mask = 1L << (elem & 31); // Get bit mask
148 data[word] |= mask; // Set bit
149 }
150 }
151
152 // Fast inlined remove
153 void remove( uint elem ) {
154 uint word = elem >> 5; // Get the longword offset
155 if( word < size ) {
156 uint32 mask = 1L << (elem & 31); // Get bit mask
157 data[word] &= ~mask; // Clear bit
158 }
159 }
160
161 private:
162 SetI_ *iterate(uint&) const;
163 };
164
165 //------------------------------Iteration--------------------------------------
166 // Loop thru all elements of the set, setting "elem" to the element numbers
167 // in random order. Inserted or deleted elements during this operation may
168 // or may not be iterated over; untouched elements will be affected once.
169 // Usage: for( VectorSetI i(s); i.test(); i++ ) { body = i.elem; }
170
171 class VectorSetI : public StackObj {
172 friend class VectorSet;
173 const VectorSet *s;
174 uint i, j;
175 uint32 mask;
176 uint next(void);
177
178 public:
179 uint elem; // The publically accessible element
|