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