Wildmeshing Toolkit
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
wmtk::threading::indexed_collector< T > Class Template Reference

#include <indexed_collector.hpp>

Public Member Functions

 indexed_collector (std::size_t n)
 Construct an indexed_collector with n slots.
 
void set (std::size_t i, const T &v)
 Set the value at index i to v. This function can be called concurrently as long as callers pass distinct i.
 
std::vector< T > compact () const
 Get a compacted vector of all filled slots. This function is not thread-safe and should only be called after all writes are complete.
 

Private Attributes

std::vector< T > m_slots
 
std::vector< char > m_filled
 

Detailed Description

template<typename T>
class wmtk::threading::indexed_collector< T >

A collector that is not thread-safe for concurrent writes to the same index, but is thread-safe for concurrent writes to distinct indices. This is useful when each thread knows a unique slot for its result, allowing for lock-free writes.

Constructor & Destructor Documentation

◆ indexed_collector()

template<typename T >
wmtk::threading::indexed_collector< T >::indexed_collector ( std::size_t  n)
inlineexplicit

Construct an indexed_collector with n slots.

Parameters
nThe number of slots to allocate.

Member Function Documentation

◆ compact()

template<typename T >
std::vector< T > wmtk::threading::indexed_collector< T >::compact ( ) const
inline

Get a compacted vector of all filled slots. This function is not thread-safe and should only be called after all writes are complete.

Returns
A vector containing all values that have been set, in the order of their indices.

◆ set()

template<typename T >
void wmtk::threading::indexed_collector< T >::set ( std::size_t  i,
const T &  v 
)
inline

Set the value at index i to v. This function can be called concurrently as long as callers pass distinct i.

Parameters
iThe index to set.
vThe value to set.

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