SpECTRE  v2025.08.19
Parallel::FifoCache< T > Class Template Reference

A threadsafe parallel first-in-first-out cache. More...

#include <FifoCache.hpp>

Classes

struct  Cached
 Wrapper type used as the result from find to ensure correct thread safety. More...
 

Public Member Functions

 FifoCache (std::unsigned_integral auto capacity)
 Create a FifoCache that has capacity.
 
 FifoCache (const FifoCache &rhs)=delete
 
FifoCacheoperator= (const FifoCache &rhs)=delete
 
 FifoCache (FifoCache &&rhs)=delete
 
FifoCacheoperator= (FifoCache &&rhs)=delete
 
template<class ComputeValue , class UnaryPredicate >
auto push (ComputeValue &&compute_value, const UnaryPredicate &predicate) -> Cached
 Pushes the entry computed by compute_value() to the front of the queue, ejecting the last entry if the capacity is reached. The inserted entry is returned. More...
 
template<class UnaryPredicate >
auto push (T t, const UnaryPredicate &predicate) -> Cached
 Pushes the entry t to the front of the queue, ejecting the last entry if the capacity is reached. The inserted entry is returned. More...
 
template<class UnaryPredicate >
auto find (const UnaryPredicate &predicate) const -> Cached
 Get the first element that matches predicate. More...
 

Detailed Description

template<class T>
class Parallel::FifoCache< T >

A threadsafe parallel first-in-first-out cache.

Member Function Documentation

◆ find()

template<class T >
template<class UnaryPredicate >
auto Parallel::FifoCache< T >::find ( const UnaryPredicate &  predicate) const -> Cached

Get the first element that matches predicate.

If no value in the cache matches the predicate then result.has_value() is false and result.value() will throw.

The return type is designed to handle the locking and unlocking of the data to ensure thread safety.

◆ push() [1/2]

template<class T >
template<class ComputeValue , class UnaryPredicate >
auto Parallel::FifoCache< T >::push ( ComputeValue &&  compute_value,
const UnaryPredicate &  predicate 
) -> Cached

Pushes the entry computed by compute_value() to the front of the queue, ejecting the last entry if the capacity is reached. The inserted entry is returned.

This function allows lazy computation of the value, which means the computation is elided if another thread pushes the new cache entry before this one.

The predicate must satisfy predicate(t) == true to avoid inserting duplicates. This is best guaranteed by passing the same predicate that would be passed to calls to find().

◆ push() [2/2]

template<class T >
template<class UnaryPredicate >
auto Parallel::FifoCache< T >::push ( t,
const UnaryPredicate &  predicate 
) -> Cached

Pushes the entry t to the front of the queue, ejecting the last entry if the capacity is reached. The inserted entry is returned.

The predicate must satisfy predicate(t) == true to avoid inserting duplicates. This is best guaranteed by passing the same predicate that would be passed to calls to find().


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