src/share/vm/libadt/vectset.hpp

Wed, 01 Dec 2010 15:04:06 +0100

author
stefank
date
Wed, 01 Dec 2010 15:04:06 +0100
changeset 2325
c760f78e0a53
parent 2314
f95d63e2154a
child 2556
3763ca6579b7
permissions
-rw-r--r--

7003125: precompiled.hpp is included when precompiled headers are not used
Summary: Added an ifndef DONT_USE_PRECOMPILED_HEADER to precompiled.hpp. Set up DONT_USE_PRECOMPILED_HEADER when compiling with Sun Studio or when the user specifies USE_PRECOMPILED_HEADER=0. Fixed broken include dependencies.
Reviewed-by: coleenp, kvn

duke@435 1 /*
stefank@2314 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_LIBADT_VECTSET_HPP
stefank@2314 26 #define SHARE_VM_LIBADT_VECTSET_HPP
stefank@2314 27
stefank@2314 28 #include "libadt/set.hpp"
stefank@2314 29
duke@435 30 // Vector Sets - An Abstract Data Type
duke@435 31 //INTERFACE
duke@435 32
duke@435 33 // These sets can grow or shrink, based on the initial size and the largest
duke@435 34 // element currently in them. Slow and bulky for sparse sets, these sets
duke@435 35 // are super for dense sets. They are fast and compact when dense.
duke@435 36
duke@435 37 // TIME:
duke@435 38 // O(1) - Insert, Delete, Member, Sort
duke@435 39 // O(max_element) - Create, Clear, Size, Copy, Union, Intersect, Difference,
duke@435 40 // Equal, ChooseMember, Forall
duke@435 41
duke@435 42 // SPACE: (max_element)/(8*sizeof(int))
duke@435 43
duke@435 44
duke@435 45 //------------------------------VectorSet--------------------------------------
duke@435 46 class VectorSet : public Set {
duke@435 47 friend class VectorSetI; // Friendly iterator class
duke@435 48 protected:
duke@435 49 uint size; // Size of data IN LONGWORDS (32bits)
duke@435 50 uint32 *data; // The data, bit packed
duke@435 51
duke@435 52 void slamin( const VectorSet& s ); // Initialize one set with another
duke@435 53 int compare(const VectorSet &s) const; // Compare set contents
duke@435 54 void grow(uint newsize); // Grow vector to required bitsize
duke@435 55
duke@435 56 public:
duke@435 57 VectorSet(Arena *arena); // Creates a new, empty set.
duke@435 58 VectorSet(const VectorSet &s) : Set(s._set_arena) {slamin(s);} // Set clone; deep-copy guts
duke@435 59 Set &operator =(const Set &s); // Set clone; deep-copy guts
duke@435 60 VectorSet &operator =(const VectorSet &s) // Set clone; deep-copy guts
duke@435 61 { if( &s != this ) { slamin(s); } return *this; }
duke@435 62 ~VectorSet() {}
duke@435 63 Set &clone(void) const { return *(new VectorSet(*this)); }
duke@435 64
duke@435 65 Set &operator <<=(uint elem); // Add member to set
duke@435 66 VectorSet operator << (uint elem) // Add member to new set
duke@435 67 { VectorSet foo(*this); foo <<= elem; return foo; }
duke@435 68 Set &operator >>=(uint elem); // Delete member from set
duke@435 69 VectorSet operator >> (uint elem) // Delete member from new set
duke@435 70 { VectorSet foo(*this); foo >>= elem; return foo; }
duke@435 71
duke@435 72 VectorSet &operator &=(const VectorSet &s); // Intersect sets into first set
duke@435 73 Set &operator &=(const Set &s); // Intersect sets into first set
duke@435 74 VectorSet operator & (const VectorSet &s) const
duke@435 75 { VectorSet foo(*this); foo &= s; return foo; }
duke@435 76
duke@435 77 VectorSet &operator |=(const VectorSet &s); // Intersect sets into first set
duke@435 78 Set &operator |=(const Set &s); // Intersect sets into first set
duke@435 79 VectorSet operator | (const VectorSet &s) const
duke@435 80 { VectorSet foo(*this); foo |= s; return foo; }
duke@435 81
duke@435 82 VectorSet &operator -=(const VectorSet &s); // Intersect sets into first set
duke@435 83 Set &operator -=(const Set &s); // Intersect sets into first set
duke@435 84 VectorSet operator - (const VectorSet &s) const
duke@435 85 { VectorSet foo(*this); foo -= s; return foo; }
duke@435 86
duke@435 87 int operator ==(const VectorSet &s) const; // True if sets are equal
duke@435 88 int operator ==(const Set &s) const; // True if sets are equal
duke@435 89 int operator < (const VectorSet &s) const; // True if strict subset
duke@435 90 int operator < (const Set &s) const; // True if strict subset
duke@435 91 int operator <=(const VectorSet &s) const; // True if subset relation holds.
duke@435 92 int operator <=(const Set &s) const; // True if subset relation holds.
duke@435 93 int disjoint (const Set &s) const; // True if sets are disjoint
duke@435 94
duke@435 95 int operator [](uint elem) const; // Test for membership
duke@435 96 uint getelem(void) const; // Return a random element
duke@435 97 void Clear(void); // Clear a set
duke@435 98 uint Size(void) const; // Number of elements in the Set.
duke@435 99 void Sort(void); // Sort before iterating
duke@435 100 int hash() const; // Hash function
duke@435 101
duke@435 102 /* Removed for MCC BUG
duke@435 103 operator const VectorSet* (void) const { return this; } */
duke@435 104 const VectorSet *asVectorSet() const { return this; }
duke@435 105
duke@435 106 // Expose internals for speed-critical fast iterators
duke@435 107 uint word_size() const { return size; }
duke@435 108 uint32 *EXPOSE() const { return data; }
duke@435 109
duke@435 110 // Fast inlined "test and set". Replaces the idiom:
duke@435 111 // if( visited[idx] ) return;
duke@435 112 // visited <<= idx;
duke@435 113 // With:
duke@435 114 // if( visited.test_set(idx) ) return;
duke@435 115 //
duke@435 116 int test_set( uint elem ) {
duke@435 117 uint word = elem >> 5; // Get the longword offset
duke@435 118 if( word >= size ) // Beyond the last?
duke@435 119 return test_set_grow(elem); // Then grow; set; return 0;
duke@435 120 uint32 mask = 1L << (elem & 31); // Get bit mask
duke@435 121 uint32 datum = data[word] & mask;// Get bit
duke@435 122 data[word] |= mask; // Set bit
duke@435 123 return datum; // Return bit
duke@435 124 }
duke@435 125 int test_set_grow( uint elem ) { // Insert & return 0;
duke@435 126 (*this) <<= elem; // Insert into set
duke@435 127 return 0; // Return 0!
duke@435 128 }
duke@435 129
duke@435 130 // Fast inlined test
duke@435 131 int test( uint elem ) const {
duke@435 132 uint word = elem >> 5; // Get the longword offset
duke@435 133 if( word >= size ) return 0; // Beyond the last?
duke@435 134 uint32 mask = 1L << (elem & 31); // Get bit mask
duke@435 135 return data[word] & mask; // Get bit
duke@435 136 }
duke@435 137
duke@435 138 // Fast inlined set
duke@435 139 void set( uint elem ) {
duke@435 140 uint word = elem >> 5; // Get the longword offset
duke@435 141 if( word >= size ) { // Beyond the last?
duke@435 142 test_set_grow(elem); // Then grow and set
duke@435 143 } else {
duke@435 144 uint32 mask = 1L << (elem & 31); // Get bit mask
duke@435 145 data[word] |= mask; // Set bit
duke@435 146 }
duke@435 147 }
duke@435 148
duke@435 149
duke@435 150 private:
duke@435 151 friend class VSetI_;
duke@435 152 SetI_ *iterate(uint&) const;
duke@435 153 };
duke@435 154
duke@435 155 //------------------------------Iteration--------------------------------------
duke@435 156 // Loop thru all elements of the set, setting "elem" to the element numbers
duke@435 157 // in random order. Inserted or deleted elements during this operation may
duke@435 158 // or may not be iterated over; untouched elements will be affected once.
duke@435 159 // Usage: for( VectorSetI i(s); i.test(); i++ ) { body = i.elem; }
duke@435 160
duke@435 161 class VSetI_ : public SetI_ {
duke@435 162 friend class VectorSet;
duke@435 163 friend class VectorSetI;
duke@435 164 const VectorSet *s;
duke@435 165 uint i, j;
duke@435 166 uint32 mask;
duke@435 167 VSetI_(const VectorSet *vset);
duke@435 168 uint next(void);
duke@435 169 int test(void) { return i < s->size; }
duke@435 170 };
duke@435 171
duke@435 172 class VectorSetI : public SetI {
duke@435 173 public:
duke@435 174 VectorSetI( const VectorSet *s ) : SetI(s) { }
duke@435 175 void operator ++(void) { elem = ((VSetI_*)impl)->next(); }
duke@435 176 int test(void) { return ((VSetI_*)impl)->test(); }
duke@435 177 };
duke@435 178
stefank@2314 179 #endif // SHARE_VM_LIBADT_VECTSET_HPP

mercurial