https://mooseframework.inl.gov
Public Types | Public Member Functions | Private Attributes | List of all members
MooseUtils::StaticallyAllocatedSet< T, N > Class Template Reference

Optimized set with static allocation. More...

#include <StaticallyAllocatedSet.h>

Public Types

typedef std::array< T, N >::iterator iterator
 
typedef std::array< T, N >::const_iterator const_iterator
 

Public Member Functions

 StaticallyAllocatedSet ()
 Create a set. More...
 
std::size_t size () const
 Number of entries. More...
 
bool empty () const
 Whether or not the set is empty. More...
 
void insert (const T &value)
 Add a new entry to the set. More...
 
void clear ()
 Remove all entries. More...
 
iterator begin ()
 Iterator for the first entry. More...
 
const_iterator begin () const
 Const iterator for the first entry. More...
 
iterator end ()
 Iterator for the last entry. More...
 
const_iterator end () const
 Const iterator for the last entry. More...
 
bool contains (const T &value) const
 Whether or not the set contains the given item. More...
 
void swap (StaticallyAllocatedSet< T, N > &other)
 Swap the contents of this set with another. More...
 
std::size_t dataEndPos () const
 Expert interface: the current ending position. More...
 

Private Attributes

std::array< T, N > _data
 The data. More...
 
std::size_t _end_pos
 Save the ending as positions internally. More...
 

Detailed Description

template<typename T, std::size_t N>
class MooseUtils::StaticallyAllocatedSet< T, N >

Optimized set with static allocation.

Useful when you a set that is small and doesn't do any allocation. Small in this context is the size at which you are not concerned with the linear search that involves a comparison of T.

It is templated on the type the set will hold and the maximum size of the set (N)

Definition at line 29 of file StaticallyAllocatedSet.h.

Member Typedef Documentation

◆ const_iterator

template<typename T, std::size_t N>
typedef std::array<T, N>::const_iterator MooseUtils::StaticallyAllocatedSet< T, N >::const_iterator

Definition at line 33 of file StaticallyAllocatedSet.h.

◆ iterator

template<typename T, std::size_t N>
typedef std::array<T, N>::iterator MooseUtils::StaticallyAllocatedSet< T, N >::iterator

Definition at line 32 of file StaticallyAllocatedSet.h.

Constructor & Destructor Documentation

◆ StaticallyAllocatedSet()

template<typename T, std::size_t N>
MooseUtils::StaticallyAllocatedSet< T, N >::StaticallyAllocatedSet ( )
inline

Create a set.

Definition at line 38 of file StaticallyAllocatedSet.h.

38 : _end_pos(0) {}
std::size_t _end_pos
Save the ending as positions internally.

Member Function Documentation

◆ begin() [1/2]

template<typename T, std::size_t N>
iterator MooseUtils::StaticallyAllocatedSet< T, N >::begin ( )
inline

Iterator for the first entry.

Definition at line 75 of file StaticallyAllocatedSet.h.

75 { return _data.begin(); }
std::array< T, N > _data
The data.

◆ begin() [2/2]

template<typename T, std::size_t N>
const_iterator MooseUtils::StaticallyAllocatedSet< T, N >::begin ( ) const
inline

Const iterator for the first entry.

Definition at line 79 of file StaticallyAllocatedSet.h.

79 { return _data.begin(); }
std::array< T, N > _data
The data.

◆ clear()

template<typename T, std::size_t N>
void MooseUtils::StaticallyAllocatedSet< T, N >::clear ( )
inline

Remove all entries.

Note: this does NOT at all free any entries

Definition at line 70 of file StaticallyAllocatedSet.h.

70 { _end_pos = 0; }
std::size_t _end_pos
Save the ending as positions internally.

◆ contains()

template<typename T, std::size_t N>
bool MooseUtils::StaticallyAllocatedSet< T, N >::contains ( const T &  value) const
inline

Whether or not the set contains the given item.

Definition at line 93 of file StaticallyAllocatedSet.h.

Referenced by MooseUtils::StaticallyAllocatedSet< T, N >::insert().

94  {
95  for (std::size_t i = 0; i < _end_pos; i++)
96  if (_data[i] == value)
97  return true;
98 
99  return false;
100  }
std::array< T, N > _data
The data.
std::size_t _end_pos
Save the ending as positions internally.

◆ dataEndPos()

template<typename T, std::size_t N>
std::size_t MooseUtils::StaticallyAllocatedSet< T, N >::dataEndPos ( ) const
inline

Expert interface: the current ending position.

Definition at line 114 of file StaticallyAllocatedSet.h.

114 { return _end_pos; }
std::size_t _end_pos
Save the ending as positions internally.

◆ empty()

template<typename T, std::size_t N>
bool MooseUtils::StaticallyAllocatedSet< T, N >::empty ( ) const
inline

Whether or not the set is empty.

Definition at line 48 of file StaticallyAllocatedSet.h.

48 { return !_end_pos; }
std::size_t _end_pos
Save the ending as positions internally.

◆ end() [1/2]

template<typename T, std::size_t N>
iterator MooseUtils::StaticallyAllocatedSet< T, N >::end ( )
inline

Iterator for the last entry.

Definition at line 84 of file StaticallyAllocatedSet.h.

84 { return _data.begin() + _end_pos; }
std::array< T, N > _data
The data.
std::size_t _end_pos
Save the ending as positions internally.

◆ end() [2/2]

template<typename T, std::size_t N>
const_iterator MooseUtils::StaticallyAllocatedSet< T, N >::end ( ) const
inline

Const iterator for the last entry.

Definition at line 88 of file StaticallyAllocatedSet.h.

88 { return _data.begin() + _end_pos; }
std::array< T, N > _data
The data.
std::size_t _end_pos
Save the ending as positions internally.

◆ insert()

template<typename T, std::size_t N>
void MooseUtils::StaticallyAllocatedSet< T, N >::insert ( const T &  value)
inline

Add a new entry to the set.

Definition at line 53 of file StaticallyAllocatedSet.h.

54  {
55  if (contains(value))
56  return;
57 
58  if (_end_pos == N)
59  mooseError("Out of space in StaticallyAllocatedSet (size = ", N, ")");
60 
61  _data[_end_pos] = value;
62  ++_end_pos;
63  }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::array< T, N > _data
The data.
std::size_t _end_pos
Save the ending as positions internally.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
bool contains(const T &value) const
Whether or not the set contains the given item.

◆ size()

template<typename T, std::size_t N>
std::size_t MooseUtils::StaticallyAllocatedSet< T, N >::size ( ) const
inline

Number of entries.

Definition at line 43 of file StaticallyAllocatedSet.h.

43 { return _end_pos; }
std::size_t _end_pos
Save the ending as positions internally.

◆ swap()

template<typename T, std::size_t N>
void MooseUtils::StaticallyAllocatedSet< T, N >::swap ( StaticallyAllocatedSet< T, N > &  other)
inline

Swap the contents of this set with another.

Definition at line 105 of file StaticallyAllocatedSet.h.

106  {
107  _data.swap(other._data);
108  std::swap(_end_pos, other._end_pos);
109  }
void swap(std::vector< T > &data, const std::size_t idx0, const std::size_t idx1, const libMesh::Parallel::Communicator &comm)
Swap function for serial or distributed vector of data.
Definition: Shuffle.h:494
std::array< T, N > _data
The data.
std::size_t _end_pos
Save the ending as positions internally.

Member Data Documentation

◆ _data

template<typename T, std::size_t N>
std::array<T, N> MooseUtils::StaticallyAllocatedSet< T, N >::_data
private

◆ _end_pos

template<typename T, std::size_t N>
std::size_t MooseUtils::StaticallyAllocatedSet< T, N >::_end_pos
private

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