|
ADS
Algorithms and Data Structures
|
an observer that records the invertible events of L, which carry the old values, and brings a structure back to a checkpoint by replaying their inverses through its apply(), in one batch: any structure with apply() becomes undoable, at one event per change More...
#include <ADS/Modification.h>
Public types | |
| using | Event = mod::variant_t< L > |
Public member functions | |
| template<class E> requires ( mod::contains_v< E , L > && mod::invertible< E > ) | |
| void | on (const E &e) noexcept(mod::must_not_throw< E >) |
| < an event recorded | |
| template<class E> requires ( mod::contains_v< E , L > && ! mod::invertible< E > ) | |
| void | on (const E &) noexcept |
| forgets the events recorded, which can no longer be undone: an event with no inverse (the deletion of a node of a graph) is a hole | |
| void | on (const mod::Cleared &) noexcept |
| forgets the events recorded, which can no longer be undone | |
| void | on (const mod::Rebuilt &) noexcept |
| forgets the events recorded | |
| template<class A> | |
| void | on (const mod::Replaced< A > &) noexcept |
| forgets the events recorded | |
| std::size_t | checkpoint (void) const |
| the checkpoint of now | |
| std::size_t | size (void) const |
| the events recorded since the oldest checkpoint still valid | |
| template<class S> | |
| void | rollback (S &s, std::size_t t) |
| \( s \) back to the checkpoint \( t \), by s.apply() of the inverses, in one batch, so that the other observers get their net effect | |
an observer that records the invertible events of L, which carry the old values, and brings a structure back to a checkpoint by replaying their inverses through its apply(), in one batch: any structure with apply() becomes undoable, at one event per change
In pseudocode (beyond the book), with \( R \) the events recorded:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{rollback}( s , t ) \cr 2 & \quad \text{open a batch on } s;\ \text{stop recording} \cr 3 & \quad \textbf{while}\ |R| > t\ \textbf{do} \cr 4 & \qquad e \gets \text{the last event of } R;\ \text{remove it}; \ s.\mathrm{apply}( e^{-1} ) \cr 5 & \quad \text{close the batch};\ \text{record again} \end{array}} \]
| using ADS::UndoLog< L >::Event = mod::variant_t< L > |
|
inlinenodiscard |
the checkpoint of now
|
inlinenoexcept |
forgets the events recorded, which can no longer be undone: an event with no inverse (the deletion of a node of a graph) is a hole
|
inlinenoexcept |
< an event recorded
records \( e \)
|
inlinenoexcept |
forgets the events recorded, which can no longer be undone
|
inlinenoexcept |
forgets the events recorded
|
inlinenoexcept |
forgets the events recorded
\( s \) back to the checkpoint \( t \), by s.apply() of the inverses, in one batch, so that the other observers get their net effect
|
inlinenodiscard |
the events recorded since the oldest checkpoint still valid