SpECTRE
v2025.03.17
|
A list of time intervals that allows safe access to existing elements even during modification. More...
#include <ThreadsafeList.hpp>
Classes | |
struct | IntervalInfo |
class | iterator |
Public Member Functions | |
ThreadsafeList () | |
No operations are valid on a default-initialized object except for assignment and deserialization. | |
ThreadsafeList (ThreadsafeList &&other) | |
ThreadsafeList (const ThreadsafeList &other) | |
ThreadsafeList & | operator= (ThreadsafeList &&other) |
ThreadsafeList & | operator= (const ThreadsafeList &other) |
ThreadsafeList (double initial_time) | |
void | insert (double update_time, T data, double expiration_time) |
Insert data valid over the interval from update_time to expiration_time . More... | |
IntervalInfo | operator() (double time) const |
Obtain the start time, data, and expiration time for the time interval containing time . More... | |
double | initial_time () const |
double | expiration_time () const |
The expiration time of the last data interval. | |
double | expiration_after (double time) const |
The first interval boundary after time . If time is an interval boundary, the one after it is returned. | |
void | truncate_to_length (size_t length) |
Remove the oldest data in the list, leaving at least length entries. More... | |
void | truncate_at_time (double time) |
Remove the oldest data in the list, retaining access to data back to at least the interval containing time . More... | |
void | clear () |
Empty the list. Equivalent to truncate_to_length(0) . See that method for details. | |
void | pup (PUP::er &p) |
iterator | begin () const |
Iterate over all the intervals in the list, in reverse order (i.e., most recent first). | |
iterator | end () const |
Iterate over all the intervals in the list, in reverse order (i.e., most recent first). | |
A list of time intervals that allows safe access to existing elements even during modification.
Concurrent modification is not supported. All non-modifying operations except for serialization can be safely performed in parallel with each other and with insert
and will return a consistent state.
void domain::FunctionsOfTime::FunctionOfTimeHelpers::ThreadsafeList< T >::insert | ( | double | update_time, |
T | data, | ||
double | expiration_time | ||
) |
Insert data valid over the interval from update_time
to expiration_time
.
The update_time
must be the same as the old expiration time. It is passed as a check that the calling code is computing the other arguments with the correct value.
IntervalInfo domain::FunctionsOfTime::FunctionOfTimeHelpers::ThreadsafeList< T >::operator() | ( | double | time | ) | const |
Obtain the start time, data, and expiration time for the time interval containing time
.
If time
is at an interval boundary, the earlier interval is returned, except for the initial time, which returns the first interval.
void domain::FunctionsOfTime::FunctionOfTimeHelpers::ThreadsafeList< T >::truncate_at_time | ( | double | time | ) |
Remove the oldest data in the list, retaining access to data back to at least the interval containing time
.
If time
is before initial_time()
, the list is not modified. If time
is after expiration_time()
, the amount of removed data is unspecified.
The amount of removed data is approximate. There may be slightly more data remaining after a call than requested.
It is the caller's responsibility to ensure that there are no concurrent truncations. Concurrent insertions are safe.
void domain::FunctionsOfTime::FunctionOfTimeHelpers::ThreadsafeList< T >::truncate_to_length | ( | size_t | length | ) |
Remove the oldest data in the list, leaving at least length
entries.
If the list is truncated to zero length, the caller must ensure that no concurrent access or modification is performed. The list is guaranteed to be empty afterwards.
Otherwise, it is the caller's responsibility to ensure that there are no concurrent truncations and that, during this call, no reader attempts to look up what will become the new oldest interval. Storing references to that interval's data is safe, and lookups of that interval are safe if they are sequenced after this call. Concurrent insertions are safe.
If the list is initially shorter than length
, it is left unchanged. Otherwise, if concurrent insertions occur, the amount of removed data is approximate, but will not leave the list shorter than the requested value. In the absence of concurrent modifications, the list will be left with exactly the requested length.