|
SpECTRE
v2025.08.19
|
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 | |
| FifoCache & | operator= (const FifoCache &rhs)=delete |
| FifoCache (FifoCache &&rhs)=delete | |
| FifoCache & | operator= (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... | |
A threadsafe parallel first-in-first-out cache.
| 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.
| 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().
| auto Parallel::FifoCache< T >::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.
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().