Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::datastructure::IndexTracker< IndexType > Class Template Reference

A class that uses a linked list to keep track of all the indices of a vector that are equal to a certain value. The values are expected to be lower than the size N of the vector (larger values grow the list heads). More...

#include <index_tracker.hpp>

Classes

class  Reference
 Proxy reference type for element access with automatic index tracking update. More...

Public Member Functions

template<typename U>
 IndexTracker (const std::vector< U > &vec)
 Constructor from any integral vector. Values are cast to IndexType.
Reference operator[] (IndexType i)
 Returns a proxy reference to an element at index i.
IndexType operator[] (IndexType i) const
 Const access to element at index i.
std::vector< IndexType > indicesOf (IndexType v, bool sorted=true) const
 Returns a vector of all indices whose value equals v.
template<typename F>
void forEachIndex (IndexType v, F f) const
 Applies a callback to each index that maps to the given value.
IndexType size () const
 Returns the number of tracked elements.
const std::vector< IndexType > & getValues () const
 Returns a const reference to the underlying data.

Static Public Attributes

static constexpr IndexType npos = static_cast<IndexType>(-1)
 Sentinel value used to indicate 'not found'.

Private Member Functions

void updateIndex (IndexType i, IndexType new_v)

Private Attributes

std::vector< IndexType > m_data
IndexType m_N {}
IndexType m_V {}
std::vector< IndexType > m_head
std::vector< IndexType > m_next
std::vector< IndexType > m_prev

Friends

class Reference

Detailed Description

template<typename IndexType>
class vulpes::datastructure::IndexTracker< IndexType >

A class that uses a linked list to keep track of all the indices of a vector that are equal to a certain value. The values are expected to be lower than the size N of the vector (larger values grow the list heads).

Constructor & Destructor Documentation

◆ IndexTracker()

template<typename IndexType>
template<typename U>
vulpes::datastructure::IndexTracker< IndexType >::IndexTracker ( const std::vector< U > & vec)
inlineexplicit

Constructor from any integral vector. Values are cast to IndexType.

Template Parameters
Uintegral type
Parameters
vecinput vector

Member Function Documentation

◆ forEachIndex()

template<typename IndexType>
template<typename F>
void vulpes::datastructure::IndexTracker< IndexType >::forEachIndex ( IndexType v,
F f ) const
inline

Applies a callback to each index that maps to the given value.

Template Parameters
FCallable object
Parameters
vvalue to iterate over
fcallback accepting index

◆ getValues()

template<typename IndexType>
const std::vector< IndexType > & vulpes::datastructure::IndexTracker< IndexType >::getValues ( ) const
inline

Returns a const reference to the underlying data.

◆ indicesOf()

template<typename IndexType>
std::vector< IndexType > vulpes::datastructure::IndexTracker< IndexType >::indicesOf ( IndexType v,
bool sorted = true ) const

Returns a vector of all indices whose value equals v.

Parameters
vthe value to search for
sortedwhether to sort the values in the output array.
Returns
vector of indices

◆ operator[]() [1/2]

template<typename IndexType>
IndexTracker< IndexType >::Reference vulpes::datastructure::IndexTracker< IndexType >::operator[] ( IndexType i)

Returns a proxy reference to an element at index i.

◆ operator[]() [2/2]

template<typename IndexType>
IndexType vulpes::datastructure::IndexTracker< IndexType >::operator[] ( IndexType i) const

Const access to element at index i.

◆ size()

template<typename IndexType>
IndexType vulpes::datastructure::IndexTracker< IndexType >::size ( ) const
inline

Returns the number of tracked elements.

◆ updateIndex()

template<typename IndexType>
void vulpes::datastructure::IndexTracker< IndexType >::updateIndex ( IndexType i,
IndexType new_v )
private

◆ Reference

template<typename IndexType>
friend class Reference
friend

Member Data Documentation

◆ m_data

template<typename IndexType>
std::vector<IndexType> vulpes::datastructure::IndexTracker< IndexType >::m_data
private

◆ m_head

template<typename IndexType>
std::vector<IndexType> vulpes::datastructure::IndexTracker< IndexType >::m_head
private

◆ m_N

template<typename IndexType>
IndexType vulpes::datastructure::IndexTracker< IndexType >::m_N {}
private

◆ m_next

template<typename IndexType>
std::vector<IndexType> vulpes::datastructure::IndexTracker< IndexType >::m_next
private

◆ m_prev

template<typename IndexType>
std::vector<IndexType> vulpes::datastructure::IndexTracker< IndexType >::m_prev
private

◆ m_V

template<typename IndexType>
IndexType vulpes::datastructure::IndexTracker< IndexType >::m_V {}
private

◆ npos

template<typename IndexType>
IndexType vulpes::datastructure::IndexTracker< IndexType >::npos = static_cast<IndexType>(-1)
staticconstexpr

Sentinel value used to indicate 'not found'.


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