GEOSX
Classes | Public Types | Public Member Functions | List of all members
LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE > Class Template Reference

This class provides an interface similar to an std::set. More...

#include <SortedArray.hpp>

Inheritance diagram for LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >:
Inheritance graph
[legend]

Public Types

using ParentClass = SortedArrayView< T, INDEX_TYPE, BUFFER_TYPE >
 Alias for the parent class.
 
using ViewType = SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > const
 The view type.
 
using ViewTypeConst = SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > const
 The const view type. More...
 
using ValueType = T
 The type of the values contained in the SortedArrayView.
 
using IndexType = INDEX_TYPE
 The integer type used for indexing.
 
using value_type = T
 The type of the values contained in the SortedArrayView, here for stl compatability.
 
using size_type = INDEX_TYPE
 The integer type used for indexing, here for stl compatability.
 

Public Member Functions

void setName (std::string const &name)
 Set the name to be displayed whenever the underlying Buffer's user call back is called. More...
 
Constructors, destructor and assignment operators.
 SortedArray ()
 Default constructor.
 
 SortedArray (SortedArray const &src)
 The copy constructor, performs a deep copy. More...
 
 SortedArray (SortedArray &&src)=default
 Default move constructor, performs a shallow copy. More...
 
 ~SortedArray ()
 Destructor, frees the values array.
 
SortedArrayoperator= (SortedArray const &src)
 Copy assignment operator, performs a deep copy. More...
 
SortedArrayoperator= (SortedArray &&src)
 Default move assignment operator, performs a shallow copy. More...
 
SortedArrayView creation methods
SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > toView () const &
 
SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > toView () const &&=delete
 Overload for rvalues that is deleted. More...
 
SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > toViewConst () const &
 
SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > toViewConst () const &&=delete
 Overload for rvalues that is deleted. More...
 
Attribute querying methods
constexpr INDEX_TYPE size () const
 
Methods that provide access to the data.
constexpr T const * data () const
 
Methods to insert or remove values
bool insert (T const &value)
 Insert the given value into the array if it doesn't already exist. More...
 
template<typename ITER >
INDEX_TYPE insert (ITER const first, ITER const last)
 Insert the values in [ first, last ) into the array if they don't already exist. More...
 
bool remove (T const &value)
 Remove the given value from the array if it exists. More...
 
template<typename ITER >
INDEX_TYPE remove (ITER const first, ITER const last)
 Remove the values in [ first, last ) from the array if they exist. More...
 
Methods that modify the size or capacity
void clear ()
 Remove all the values from the array.
 
void reserve (INDEX_TYPE const nVals)
 Reserve space to store the given number of values without resizing. More...
 
Methods dealing with memory spaces
void move (MemorySpace const space, bool const touch=true) const
 Moves the SortedArrayView to the given execution space. More...
 

Additional Inherited Members

- Protected Types inherited from LvArray::SortedArrayView< T, INDEX_TYPE, BUFFER_TYPE >
using ValueType = T
 The type of the values contained in the SortedArrayView.
 
using IndexType = INDEX_TYPE
 The integer type used for indexing.
 
using value_type = T
 The type of the values contained in the SortedArrayView, here for stl compatability.
 
using size_type = INDEX_TYPE
 The integer type used for indexing, here for stl compatability.
 
- Protected Member Functions inherited from LvArray::SortedArrayView< T, INDEX_TYPE, BUFFER_TYPE >
 SortedArrayView ()
 Default constructor. More...
 
 SortedArrayView (SortedArrayView const &src)=default
 Default copy constructor. Performs a shallow copy and calls the chai::ManagedArray copy constructor. More...
 
constexpr SortedArrayView (SortedArrayView &&src)
 Default move constructor, performs a shallow copy. More...
 
constexpr SortedArrayView (INDEX_TYPE const size, BUFFER_TYPE< T > const &buffer)
 Construct a new SortedArrayView from the given buffer. More...
 
SortedArrayViewoperator= (SortedArrayView const &src)=default
 Default copy assignment operator, this does a shallow copy. More...
 
constexpr SortedArrayViewoperator= (SortedArrayView &&src)
 Default move assignment operator, this does a shallow copy. More...
 
constexpr SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > toView () const
 
constexpr SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > toViewConst () const
 
constexpr ArraySlice< T const, 1, 0, INDEX_TYPE > toSlice () const &
 
constexpr ArraySlice< T const, 1, 0, INDEX_TYPE > toSlice () const &&=delete
 Overload for rvalues that is deleted. More...
 
constexpr bool empty () const
 
constexpr INDEX_TYPE size () const
 
bool contains (T const &value) const
 
bool count (T const &value) const
 
constexpr T const & operator[] (INDEX_TYPE const i) const
 
constexpr T const & operator() (INDEX_TYPE const i) const
 
constexpr T const * data () const
 
constexpr T const * begin () const
 
constexpr T const * end () const
 
void move (MemorySpace const space, bool touch=true) const
 Moves the SortedArrayView to the given execution space. More...
 
- Protected Attributes inherited from LvArray::SortedArrayView< T, INDEX_TYPE, BUFFER_TYPE >
BUFFER_TYPE< T > m_values
 Holds the array of values.
 
INDEX_TYPE m_size = 0
 The number of values.
 

Detailed Description

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
class LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >

This class provides an interface similar to an std::set.

Template Parameters
Ttype of data that is contained by the array.
INDEX_TYPEthe integer to use for indexing the components of the array.

The difference between this class and std::set is that the values are stored contiguously in memory. It maintains O(log(N)) lookup time but insertion and removal are O(N).

The derivation from SortedArrayView is protected to control the conversion to SortedArrayView. Specifically only conversion to SortedArrayView<T const> is allowed.

Definition at line 35 of file SortedArray.hpp.

Member Typedef Documentation

◆ ViewTypeConst

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
using LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::ViewTypeConst = SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > const

The const view type.

Note
This is the same as the view type since SortedArrayView can't modify the data.

Definition at line 55 of file SortedArray.hpp.

Constructor & Destructor Documentation

◆ SortedArray() [1/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::SortedArray ( SortedArray< T, INDEX_TYPE, BUFFER_TYPE > const &  src)
inline

The copy constructor, performs a deep copy.

Parameters
srcThe SortedArray to copy.

Definition at line 77 of file SortedArray.hpp.

◆ SortedArray() [2/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::SortedArray ( SortedArray< T, INDEX_TYPE, BUFFER_TYPE > &&  src)
inlinedefault

Default move constructor, performs a shallow copy.

Parameters
srcthe SortedArray to be moved from.

Member Function Documentation

◆ data()

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
constexpr T const* LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::data ( ) const
inline

Returns
Return a pointer to the values.
Note
This is just a wrapper around the SortedArrayView method. The reason it isn't pulled in with a using statement is that it is detected using IS_VALID_EXPRESSION and this fails with NVCC.

Definition at line 209 of file SortedArray.hpp.

◆ insert() [1/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
bool LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::insert ( T const &  value)
inline

Insert the given value into the array if it doesn't already exist.

Parameters
valuethe value to insert.
Returns
True iff the value was actually inserted.

Definition at line 228 of file SortedArray.hpp.

◆ insert() [2/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
template<typename ITER >
INDEX_TYPE LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::insert ( ITER const  first,
ITER const  last 
)
inline

Insert the values in [ first, last ) into the array if they don't already exist.

Template Parameters
ITERThe type of the iterator to use.
Parameters
firstIterator to the first value to insert.
lastIterator to the end of the values to insert.
Returns
The number of values actually inserted.
Note
[ first, last ) must be sorted and unique.

Definition at line 247 of file SortedArray.hpp.

◆ move()

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
void LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::move ( MemorySpace const  space,
bool const  touch = true 
) const
inline

Moves the SortedArrayView to the given execution space.

Parameters
spacethe space to move to.
touchIf the values will be modified in the new space.
Note
Since the SortedArrayView can't be modified on device when moving to the GPU touch is set to false.
This is just a wrapper around the SortedArrayView method. The reason it isn't pulled in with a using statement is that it is detected using IS_VALID_EXPRESSION and this fails with NVCC.

Definition at line 333 of file SortedArray.hpp.

◆ operator=() [1/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
SortedArray& LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::operator= ( SortedArray< T, INDEX_TYPE, BUFFER_TYPE > const &  src)
inline

Copy assignment operator, performs a deep copy.

Parameters
srcthe SortedArray to copy.
Returns
*this.

Definition at line 101 of file SortedArray.hpp.

◆ operator=() [2/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
SortedArray& LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::operator= ( SortedArray< T, INDEX_TYPE, BUFFER_TYPE > &&  src)
inline

Default move assignment operator, performs a shallow copy.

Parameters
srcthe SortedArray to be moved from.
Returns
*this.

Definition at line 114 of file SortedArray.hpp.

◆ remove() [1/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
bool LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::remove ( T const &  value)
inline

Remove the given value from the array if it exists.

Parameters
valuethe value to remove.
Returns
True iff the value was actually removed.

Definition at line 264 of file SortedArray.hpp.

◆ remove() [2/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
template<typename ITER >
INDEX_TYPE LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::remove ( ITER const  first,
ITER const  last 
)
inline

Remove the values in [ first, last ) from the array if they exist.

Template Parameters
ITERThe type of the iterator to use.
Parameters
firstIterator to the first value to remove.
lastIterator to the end of the values to remove.
Returns
The number of values actually removed.
Note
[ first, last ) must be sorted and unique.

Definition at line 283 of file SortedArray.hpp.

◆ reserve()

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
void LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::reserve ( INDEX_TYPE const  nVals)
inline

Reserve space to store the given number of values without resizing.

Parameters
nValsthe number of values to reserve space for.

Definition at line 316 of file SortedArray.hpp.

◆ setName()

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
void LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::setName ( std::string const &  name)
inline

Set the name to be displayed whenever the underlying Buffer's user call back is called.

Parameters
nameThe name to associate with this SortedArray.

Definition at line 342 of file SortedArray.hpp.

◆ size()

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
constexpr INDEX_TYPE LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::size ( ) const
inline

Returns
Return the number of values in the array.
Note
This is just a wrapper around the SortedArrayView method. The reason it isn't pulled in with a using statement is that it is detected using IS_VALID_EXPRESSION and this fails with NVCC.

Definition at line 186 of file SortedArray.hpp.

◆ toView() [1/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::toView ( ) const &
inline

Returns
An immutable SortedArrayView.
Note
This is just a wrapper around the SortedArrayView method. The reason it isn't pulled in with a using statement is that it is detected using IS_VALID_EXPRESSION and this fails with NVCC.

Definition at line 135 of file SortedArray.hpp.

◆ toView() [2/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::toView ( ) const &&
inlinedelete

Overload for rvalues that is deleted.

Returns
A null SortedArrayView.
Note
This cannot be called on a rvalue since the SortedArrayView would contain the buffer of the current SortedArray that is about to be destroyed. This overload prevents that from happening.

◆ toViewConst() [1/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::toViewConst ( ) const &
inline

Returns
An immutable SortedArrayView.
Note
This is just a wrapper around the SortedArrayView method. The reason it isn't pulled in with a using statement is that it is detected using IS_VALID_EXPRESSION and this fails with NVCC.

Definition at line 155 of file SortedArray.hpp.

◆ toViewConst() [2/2]

template<typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE>
SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > LvArray::SortedArray< T, INDEX_TYPE, BUFFER_TYPE >::toViewConst ( ) const &&
inlinedelete

Overload for rvalues that is deleted.

Returns
A null SortedArrayView.
Note
This cannot be called on a rvalue since the SortedArrayView would contain the buffer of the current SortedArray that is about to be destroyed. This overload prevents that from happening.

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