AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::slam::DynamicSet< PosType, ElemType, SizePolicy > Class Template Referenceabstract

A Set class that supports dynamically adding and removing set items. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/latest/src/axom/slam/DynamicSet.hpp>

Inheritance diagram for axom::slam::DynamicSet< PosType, ElemType, SizePolicy >:

Classes

class  DynamicSetIterator
 An stl-compliant random iterator type for a DynamicSet. More...
 
class  SetBuilder
 Helper class for constructing a DynamicSet. More...
 

Public Types

using PositionType = PosType
 
using ElementType = ElemType
 
using SetVectorType = std::vector< ElementType >
 
using SizePolicyType = SizePolicy
 
using const_iterator = DynamicSetIterator< ElementType, true >
 
using const_iterator_pair = std::pair< const_iterator, const_iterator >
 
using iterator = DynamicSetIterator< ElementType, false >
 
using iterator_pair = std::pair< iterator, iterator >
 

Public Member Functions

 DynamicSet (PositionType size=SizePolicyType::DEFAULT_VALUE)
 Constructor for a DynamicSet. More...
 
 DynamicSet (const SetBuilder &builder)
 Constructor for a DynamicSet from a SetBuilder. More...
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cend () const
 
virtual ElementType at (PositionType) const=0
 Random access to the entities of the set. More...
 
DynamicSet element access functions
ElementType at (PositionType pos) const
 Access the element at position pos. More...
 
const ElementTypeoperator[] (IndexType pos) const
 Access the element at position pos. More...
 
ElementTypeoperator[] (IndexType pos)
 Access the element at position pos. More...
 
SetVectorTypedata ()
 Returns a reference to the underlying set data. More...
 
const SetVectorTypedata () const
 Returns a const reference to the underlying set data. More...
 
IndexType findIndex (ElementType e) const
 Given a value, find the index of the first entry containing it. More...
 
bool contains (ElementType e) const
 Checks whether an element exists within the DynamicSet. More...
 
Functions that deal with the set cardinality and indexing
AXOM_HOST_DEVICE PositionType size () const
 Returns the number of possible elements in the set. More...
 
AXOM_HOST_DEVICE bool empty () const
 Uses SizePolicy::empty() to determine if the set is empty. More...
 
PositionSet< PositionTypepositions () const
 Returns a positionset over the set elements. More...
 
PositionType numberOfValidEntries () const
 Return the number of valid entries in the set. More...
 
bool isSubset () const
 Returns true if this set is a subset of another set. More...
 
Functions that deal with validity checks
bool isValidEntry (IndexType i) const
 Predicate to check if the entry at index i is valid. More...
 
bool isValid (bool verboseOutput=false) const
 Returns true if the DynamicSet instance is valid. More...
 
Functions that modify the set cardinality
IndexType insert ()
 Insert an entry at the end of the set with value = ( size()-1 ) More...
 
IndexType insert (ElementType val)
 Insert an entry at the end of the set with the given value. More...
 
void remove (IndexType idx)
 Mark the corresponding entry as invalid. More...
 
void reset (PositionType sz)
 Resets to a default DynamicSet of size sz. More...
 

Static Public Attributes

static constexpr ElementType INVALID_ENTRY = ~0
 value to mark indices of deleted elements More...
 

Private Member Functions

AXOM_HOST_DEVICE slam::DefaultPositionTypesize ()
 

Detailed Description

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
class axom::slam::DynamicSet< PosType, ElemType, SizePolicy >

A Set class that supports dynamically adding and removing set items.

\detail An entry in the set is valid if it is not equal to INVALID_ENTRY.

An example to traverse the elements

DynamicSet<> some_set;
... // initialize some_set
const IndexType N = some_set.size()
for(IndexType i=0; i< N; ++i)
{
if( some_set.isValidEntry(i) )
{
ElementType el = some_set[i];
... // do something with el
} // END if the entry is valid
} //END for all set entries
ElemType ElementType
Definition: DynamicSet.hpp:58
std::int32_t IndexType
Definition: Types.hpp:66

Member Typedef Documentation

◆ PositionType

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
using axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::PositionType = PosType

◆ ElementType

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
using axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::ElementType = ElemType

◆ SetVectorType

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
using axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::SetVectorType = std::vector<ElementType>

◆ SizePolicyType

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
using axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::SizePolicyType = SizePolicy

◆ const_iterator

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
using axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::const_iterator = DynamicSetIterator<ElementType, true>

◆ const_iterator_pair

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
using axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::const_iterator_pair = std::pair<const_iterator, const_iterator>

◆ iterator

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
using axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::iterator = DynamicSetIterator<ElementType, false>

◆ iterator_pair

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
using axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::iterator_pair = std::pair<iterator, iterator>

Constructor & Destructor Documentation

◆ DynamicSet() [1/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::DynamicSet ( PositionType  size = SizePolicyType::DEFAULT_VALUE)
inline

Constructor for a DynamicSet.

Parameters
sizeThe initial size of the set
Note
The set entries will be initialized such that set[i] = i

References axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::size().

◆ DynamicSet() [2/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::DynamicSet ( const SetBuilder builder)
inline

Constructor for a DynamicSet from a SetBuilder.

Note
The set entries will be initialized such that set[i] = i

Member Function Documentation

◆ begin() [1/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
iterator axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::begin ( )
inline

◆ begin() [2/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
const_iterator axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::begin ( ) const
inline

◆ cbegin()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
const_iterator axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::cbegin ( ) const
inline

◆ end() [1/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
iterator axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::end ( )
inline

◆ end() [2/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
const_iterator axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::end ( ) const
inline

◆ cend()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
const_iterator axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::cend ( ) const
inline

◆ at() [1/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
ElementType axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::at ( PositionType  pos) const
inline

Access the element at position pos.

Precondition
pos must be between 0 and size()

References axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::operator[]().

◆ operator[]() [1/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
const ElementType& axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::operator[] ( IndexType  pos) const
inline

Access the element at position pos.

Precondition
pos must be between 0 and size()

◆ operator[]() [2/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
ElementType& axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::operator[] ( IndexType  pos)
inline

Access the element at position pos.

Precondition
pos must be between 0 and size()

◆ data() [1/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
SetVectorType& axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::data ( )
inline

Returns a reference to the underlying set data.

◆ data() [2/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
const SetVectorType& axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::data ( ) const
inline

Returns a const reference to the underlying set data.

◆ findIndex()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
IndexType axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::findIndex ( ElementType  e) const
inline

Given a value, find the index of the first entry containing it.

Returns
The index of the first element with value e, or INVALID_ENTRY if none can be found.
Note
This is an O(n) operation in the size of the set

References axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::INVALID_ENTRY, and axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::size().

◆ contains()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
bool axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::contains ( ElementType  e) const
inline

Checks whether an element exists within the DynamicSet.

Returns
true if the set contains element with value e, false otherwise
Note
This is an O(n) operation in the size of the set

References axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::size().

◆ size()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
AXOM_HOST_DEVICE PositionType axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::size ( ) const
inlinevirtual

Returns the number of possible elements in the set.

Note
Not all elements are necessarily valid since some elements could have been deleted
See also
numberOfValidEntries(), isValidEntry()

Implements axom::slam::Set< slam::DefaultPositionType, slam::DefaultElementType >.

◆ empty()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
AXOM_HOST_DEVICE bool axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::empty ( ) const
inlinevirtual

Uses SizePolicy::empty() to determine if the set is empty.

Implements axom::slam::Set< slam::DefaultPositionType, slam::DefaultElementType >.

◆ positions()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
PositionSet<PositionType> axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::positions ( ) const
inline

Returns a positionset over the set elements.

References axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::size().

◆ numberOfValidEntries()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
PositionType axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::numberOfValidEntries ( ) const
inline

Return the number of valid entries in the set.

This is an O(n) operation, because the class makes no assumption that data was not changed by the user

References axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::INVALID_ENTRY, and axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::size().

◆ isSubset()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
bool axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::isSubset ( ) const
inlinevirtual

Returns true if this set is a subset of another set.

Implements axom::slam::Set< slam::DefaultPositionType, slam::DefaultElementType >.

◆ isValidEntry()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
bool axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::isValidEntry ( IndexType  i) const
inline

Predicate to check if the entry at index i is valid.

The entry is valid when 0 <= i < size() and the value at index i is not marked as INVALID_ENTRY

References axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::INVALID_ENTRY, and axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::size().

◆ isValid()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
bool axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::isValid ( bool  verboseOutput = false) const
inlinevirtual

Returns true if the DynamicSet instance is valid.

A DynamicSet is valid if each of its policies claim it to be valid. This includes its SizePolicy, OffsetPolicy and StridePolicy

Implements axom::slam::Set< slam::DefaultPositionType, slam::DefaultElementType >.

◆ insert() [1/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
IndexType axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::insert ( )
inline

◆ insert() [2/2]

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
IndexType axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::insert ( ElementType  val)
inline

Insert an entry at the end of the set with the given value.

Parameters
valthe value of the inserted entry

References axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::size().

◆ remove()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
void axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::remove ( IndexType  idx)
inline

Mark the corresponding entry as invalid.

Note
It is not a problem to mark an INVALID_ENTRY as INVALID_ENTRY

References axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::INVALID_ENTRY.

◆ reset()

template<typename PosType = slam::DefaultPositionType, typename ElemType = slam::DefaultElementType, typename SizePolicy = policies::DynamicRuntimeSize<PosType>>
void axom::slam::DynamicSet< PosType, ElemType, SizePolicy >::reset ( PositionType  sz)
inline

Resets to a default DynamicSet of size sz.

The entry at index i will have the value of i for 0 <= i < sz

◆ at() [2/2]

Random access to the entities of the set.

Parameters
Theindex of the desired element
Returns
The value of the element at the given position
Precondition
The position must be less than the number of elements in the set ( size() )
Note
Concrete realizations of Set also support subscript operator – operator[].
How are we planning to handle indexes that are out or range (accidentally)? Are we planning to handle indexes that are intentionally out of range (e.g. to indicate a problem, or a missing element etc..)?

Implemented in axom::slam::NullSet< slam::DefaultPositionType, slam::DefaultElementType >.

Member Data Documentation

◆ INVALID_ENTRY

template<typename P , typename E , typename S >
constexpr DynamicSet< P, E, S >::ElementType axom::slam::DynamicSet< P, E, S >::INVALID_ENTRY = ~0
staticconstexpr

value to mark indices of deleted elements


The documentation for this class was generated from the following file: