IndexSet (struct)

The IndexSet can be used to express a set of indices, where the index range is relatively contiguous. This can be useful to create a set of indices pointing to a larger array, for example. An IndexSet is particularly useful for efficiently removing duplicate indices, as it only allocates a few buffers as opposed to using a Dictionary.

IndexSet IndexSet IndexSet

/*
** Example: IndexSet
*/

require Containers;
  
operator entry() {

  IndexSet indexSet;
  indexSet.add(3);
  indexSet.add(9);
  indexSet.add(3);
  indexSet.add(4);
  indexSet.add(9);
  
  report("Contains '2': " + indexSet.has(2));
  report("Contains '3': " + indexSet.has(3));
  
  report("Indices:");
  for( Size i = 0; i < indexSet.size(); ++i )
    report( indexSet.get(i) );
  
}

/*
** Output:

Contains '2': false
Contains '3': true
Indices:
3
9
4

*/

Methods

  IndexSet ( in IndexSet other )
  IndexSet ()
  add ! ( in IndexSet other )
Boolean add ! ( in UInt32 index )
  clear ! ()
IndexSet clone ? ()
  free ! ()
UInt32 get ? ( in Size offset )
:ref:`UInt32 <uint32>`<> getIndices ? ()
Boolean has ? ( in UInt32 index )
Size potentialIndexRange ? ()
  removeAtOffset ! ( in UInt32 offset )
Size size ? ()

Methods in detail

IndexSet ( in IndexSet other )

copy constructor


IndexSet ()

default constructor


IndexSet.add! ( in IndexSet other )

merges another set into this one


Boolean IndexSet.add! ( in UInt32 index )

adds a new index to the set. returns true if the index wasn’t in the set yet


IndexSet.clear! ()

empties the set

注釈

In order to reduce memory usage, the indices array is not released, and will be reused to avoid reallocs.


IndexSet IndexSet.clone? ()

clone method


IndexSet.free! ()

empties the set and frees all internal containers


UInt32 IndexSet.get? ( in Size offset )

returns the index of element, at an offset between 0 and IndexSet.size-1.


UInt32.getIndices? ()

returns the index list buffer. However, if IndexSet.clear was previously called, IndexSet.size must be used to know how number of indices (the last portion of the array can contain garbage data).


Boolean IndexSet.has? ( in UInt32 index )

returns true if a given index is part of the set


Size IndexSet.potentialIndexRange? ()

returns the potential range for the indices


IndexSet.removeAtOffset! ( in UInt32 offset )

Removes the element at this.indices[offset] and shuffles the last element to replace it. Be careful: “offset” is not the element index itself, but rather its position in the indices array.


Size IndexSet.size? ()

returns the size of the set