|
ADS
Algorithms and Data Structures
|
The typed modifications, beyond the book: the vocabulary by which a structure tells the observers attached to it what changed, by small values that carry the old and the new state, and the policies that decide, in the type of the structure, who listens and at what cost (see Typed modifications). More...
#include "ADS/Capabilities.h"#include "ADS/Contract.h"#include "ADS/Portable.h"#include <array>#include <concepts>#include <cstddef>#include <cstdint>#include <exception>#include <functional>#include <memory>#include <span>#include <stdexcept>#include <tuple>#include <type_traits>#include <utility>#include <variant>#include <vector>#include "ADS/impl/Modification.tpp"Go to the source code of this file.
Classes | |
| class | ADS::Refused |
| a change refused by the prepare() of an observer, before anything changed More... | |
| struct | ADS::no_rebuild_t |
| the promise of quiet( s , no_rebuild ): nobody needs to know More... | |
| struct | ADS::Reopt |
| how a query of an observer brought its solution up to date (the outcomes, \( 0 \) to \( 2 \)), and why (the causes, which refine the outcome from scratch and the repair) More... | |
| struct | ADS::ReoptStats |
| what a recompute policy reads: the work is a count of elementary operations of the observer (nodes, edges, extractions), never a time, so that a policy decides the same on every machine More... | |
| struct | ADS::RatioPolicy |
| the default recompute policy: from scratch when the net events exceed \( \rho \) times the size, a repair abandoned when its work exceeds \( \alpha \) times that of a computation from scratch or when an element is extracted again more than \( \beta \) times; the values that are not exact (floating point) summed again after \( \mathit{period} \) times the size of changes, by the compensated sum of Neumaier when asked More... | |
| class | ADS::NeumaierSum< T > |
| a sum of values of T that follows additions and subtractions, with the compensation of Neumaier when T is floating and it is asked: the error after \( k \) terms is then of the order of \( \varepsilon \) times the sum of their absolute values, instead of \( k \varepsilon \) times More... | |
| struct | ADS::mod::effect |
| the effects of an event, as bits: a bit not set is a guarantee More... | |
| struct | ADS::mod::Value |
| the attribute of the value of an item More... | |
| struct | ADS::mod::Key |
| the attribute of a key that orders the items More... | |
| struct | ADS::mod::Cost |
| the cost of an arc More... | |
| struct | ADS::mod::Upper |
| the upper bound of an arc More... | |
| struct | ADS::mod::Lower |
| the lower bound of an arc More... | |
| struct | ADS::mod::Supply |
| the supply of a node More... | |
| struct | ADS::mod::Parent |
| the parent of a node in a forest, -1 at a root More... | |
| struct | ADS::mod::reduce::last |
| the value after the second change More... | |
| struct | ADS::mod::reduce::min |
| the least of the two values after More... | |
| struct | ADS::mod::reduce::max |
| the largest of the two values after More... | |
| struct | ADS::mod::reduce::sum |
| the first value after plus the second difference More... | |
| struct | ADS::mod::reduction_of< A > |
| the reduction of the attribute A: A::reduction if it has one, reduce::last otherwise More... | |
| struct | ADS::mod::reduction_of< A > |
| the reduction of an attribute that declares one More... | |
| struct | ADS::mod::list< E > |
| a list of types, the events of a structure [see Modification.h] More... | |
| struct | ADS::mod::Inserted< H, K, V > |
| the item of handle \( h \), key \( k \) and value \( v \) inserted More... | |
| struct | ADS::mod::Inserted< H, K, void > |
| the item of handle \( h \) and key \( k \) inserted, with no value More... | |
| struct | ADS::mod::Erased< H, K, V > |
| the item of handle \( h \), key \( k \) and value \( v \) erased, told before the removal outside a batch More... | |
| struct | ADS::mod::Erased< H, K, void > |
| the item of handle \( h \) and key \( k \) erased, with no value More... | |
| struct | ADS::mod::Changed< A, H, V > |
| the attribute A of the item of handle \( h \) changed from from to to More... | |
| struct | ADS::mod::Relocated< H > |
| the item of handle from moved to the handle to, for the structures whose handles are not stable More... | |
| struct | ADS::mod::Permuted< H > |
| the items permuted: the handle before of each handle after More... | |
| struct | ADS::mod::BulkInserted< H > |
| the items of the handles hs inserted by one bulk operation More... | |
| struct | ADS::mod::BulkErased< H > |
| the items of the handles hs erased by one bulk operation More... | |
| struct | ADS::mod::Shifted< A, D > |
| every value of the attribute A moved by delta More... | |
| struct | ADS::mod::Replaced< A > |
| every value of the attribute A replaced More... | |
| struct | ADS::mod::Cleared |
| the structure emptied More... | |
| struct | ADS::mod::Rebuilt |
| anything may have changed: forget and recompute More... | |
| struct | ADS::mod::Group |
| what a batch tells group_begin(): the versions of the subject before and after it, and the number of its events after the coalescing More... | |
| struct | ADS::mod::Counts |
| the counts of an observer kept by the subject at the level of the audits More... | |
| struct | ADS::mod::Direct |
| how a subject calls an observer: Direct calls on() and the optional parts by their names; an adapter with the same static functions lets an object with another interface be an observer [see Via] More... | |
| struct | ADS::mod::Via< O, A > |
| the observer O called through the adapter A, an argument of Static More... | |
| struct | ADS::mod::coalesce_traits< L > |
| the net effect of the events of a batch of the structures whose events are the list L: by default the rule of Typed modifications (an insertion and an erasure of one handle cancel, an erasure and an insertion become changes, consecutive changes of one attribute compose, everything before the last Cleared or Rebuilt is dropped, the shifts add up); a structure with a rule of its own specializes it More... | |
| struct | ADS::NoObservers |
| nobody listens: the subject is empty and every test is false at compile time, so that the structure compiles to its plain code More... | |
| struct | ADS::Static< O > |
| the static observers O... (or mod::Via< O , A >), references called directly in the order of the arguments More... | |
| struct | ADS::Dynamic< L > |
| observers attached at run time, the events those of the structure (or the list L, which must be them) More... | |
| struct | ADS::Both< Static< O... >, Dynamic< L > > |
| the static observers O..., then those attached at run time More... | |
| class | ADS::Batch< S > |
| a batch of RAII on the structure \( s \) [see batch()] More... | |
| class | ADS::Quiet< S > |
| a mute of RAII on the structure \( s \) [see quiet()] More... | |
| class | ADS::UndoLog< L > |
| 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... | |
| class | ADS::Shadow< Inc, Scratch, Eq > |
| an observer that forwards every event to an incremental observer and to one that computes from scratch, and compares their answers at each query by Eq: an audit of the incremental one by recomputation, at a cost of about twice the work More... | |
| struct | ADS::Shadow< Inc, Scratch, Eq >::Counts |
| what a shadow counts More... | |
Namespaces | |
| namespace | ADS |
| namespace | ADS::mod |
| namespace | ADS::mod::reduce |
| how two changes of one attribute of one item compose in a batch: the last value (last), the least or the largest of the two (min, max), or the sum of the differences (sum) | |
Concepts | |
| concept | ADS::ReoptPolicy |
| a recompute policy: whether to compute from scratch before a repair, whether to abandon a repair while it runs (polled by the observer with its work \( w \) so far), and the record of the outcome after it | |
| concept | ADS::mod::invertible |
| an event that has an inverse | |
| concept | ADS::mod::observes |
| an observer of the event E | |
| concept | ADS::mod::observes_span |
| an observer of the spans of E, an event or the variant of the events | |
| concept | ADS::mod::groups |
| an observer told of the start and of the end of each batch | |
| concept | ADS::mod::refuses |
| an observer that may refuse the change E before it is made | |
| concept | ADS::mod::auditable |
| an observer that can check itself against the structure \( s \) | |
| concept | ADS::mod::lazy |
| an observer that queues the events and works at its next query | |
| concept | ADS::mod::counted |
| an observer that reports counts of its own | |
| concept | ADS::mod::with_policy |
| an observer with a recompute policy [see ReoptPolicy], and the statistics of a query after \( k \) more events: at the close of a batch the subject asks its scratch(), and sends Rebuilt instead of the events when it answers yes | |
| concept | ADS::mod::masked |
| an observer with a filter of the kinds at run time: the bit \( i \) of mask() for the \( i \)-th event of the structure | |
| concept | ADS::mod::observer_of |
| an observer of at least one of the events of the list L | |
Typedefs | |
| template<class L> | |
| using | ADS::mod::variant_t = typename detail::variant_of< L >::type |
| the variant of the events of the list L, the type of a buffer | |
| template<class H, class V> | |
| using | ADS::mod::Assigned = Changed< Value , H , V > |
| the value of an item changed | |
| template<class H, class K> | |
| using | ADS::mod::KeyChanged = Changed< Key , H , K > |
| the key of an item changed | |
Enumerations | |
| enum class | ADS::Keep { ADS::Keep::Yes , ADS::Keep::Detach } |
| what an on() that returns it asks: to stay, or to be detached after the event, with no exception More... | |
| enum class | ADS::mod::Role { ADS::mod::Role::Insert , ADS::mod::Role::Erase , ADS::mod::Role::Change , ADS::mod::Role::Relocate , ADS::mod::Role::Permute , ADS::mod::Role::BulkInsert , ADS::mod::Role::BulkErase , ADS::mod::Role::Shift , ADS::mod::Role::Replace , ADS::mod::Role::Clear , ADS::mod::Role::Rebuild , ADS::mod::Role::Other } |
| the role of an event in the coalescing of a batch More... | |
Functions | |
| template<class H, class K, class V> | |
| constexpr Erased< H, K, V > | ADS::mod::inverse (const Inserted< H, K, V > &e) |
| the erasure that undoes an insertion | |
| template<class H, class K, class V> | |
| constexpr Inserted< H, K, V > | ADS::mod::inverse (const Erased< H, K, V > &e) |
| the insertion that undoes an erasure | |
| template<class A, class H, class V> | |
| constexpr Changed< A, H, V > | ADS::mod::inverse (const Changed< A, H, V > &e) |
| the change back | |
| template<class H> | |
| constexpr Relocated< H > | ADS::mod::inverse (const Relocated< H > &e) |
| the move back | |
| template<class A, class D> | |
| constexpr Shifted< A, D > | ADS::mod::inverse (const Shifted< A, D > &e) |
| the shift back | |
| template<class S> | |
| Batch< S > | ADS::batch (S &s) |
| a batch on the structure \( s \), open while it lives: its events are collected, and the outermost batch sends their net effect at its end | |
| template<class S> | |
| Quiet< S > | ADS::quiet (S &s) |
| a mute on the structure \( s \): no event while it lives, Rebuilt to every observer at its end (inside a batch, the events collected before are dropped, and the batch sends Rebuilt and the events after the mute) | |
| template<class S> | |
| Quiet< S > | ADS::quiet (S &s, no_rebuild_t) |
| a mute on the structure \( s \) that nobody needs to know: no event, and at the level of the audits the observers audited at its end | |
Variables | |
| constexpr no_rebuild_t | ADS::no_rebuild {} |
| the promise of quiet( s , no_rebuild ) | |
| template<class E> | |
| constexpr Role | ADS::mod::role_of = detail::declared_role< E >() |
| the role of the event E, Role::Other if it declares none | |
| template<class E> | |
| constexpr unsigned | ADS::mod::effects_of = detail::declared_effects< E >() |
| the effects of the event E, all of them if it declares none | |
| template<class E> | |
| constexpr bool | ADS::mod::must_not_throw |
| whether on() of the event E must not throw: the erasures, the clearing, the rebuilding and the replacement, after which an observer left half updated could not be repaired | |
| template<class E, class L> | |
| constexpr std::size_t | ADS::mod::index_v = detail::index_in< E , L >::value |
| the position of E in the list L, its size if absent | |
| template<class E, class L> | |
| constexpr bool | ADS::mod::contains_v = index_v< E , L > < L::size |
| whether E is in the list L | |
The typed modifications, beyond the book: the vocabulary by which a structure tells the observers attached to it what changed, by small values that carry the old and the new state, and the policies that decide, in the type of the structure, who listens and at what cost (see Typed modifications).
The events are the templates of the namespace ADS::mod, each an aggregate with a static mask effects (a subset of effect::grows, shrinks, up, down) and a static role: Inserted< H , K , V > and Erased< H , K , V > of the item of handle \( h \), key \( k \) and value \( v \) (no value when V is void), Changed< A , H , V > of the attribute A of an item from from to to (Assigned and KeyChanged for the attributes Value and Key), Relocated, Permuted, BulkInserted, BulkErased, Shifted< A , D > (every value of A moved by delta), Replaced< A >, Cleared and Rebuilt (anything may have changed). A structure declares the events it emits as a type list, using modifications = mod::list< ... >.
An observer of a structure is any object with an on( e ) for at least one of its events; the other parts are optional and found at compile time: on( s ) for a std::span of one kind or of the variant of the events, group_begin() and group_end() around a batch, prepare( e ), which may refuse a change, audit( s ), mask(), a filter of the kinds at run time, using requires_modifications = mod::list< ... > and using depends_on = mod::list< ... >; an on() may return Keep to leave. The subject policy is a parameter of the structure: NoObservers (no member and no code), Static< O... > (references called directly, in the order of the arguments), Dynamic<> (observers attached at run time, a slot of erased type each and a union of their masks) and Both< Static< O... > , Dynamic<> >, the static ones first. A mutator tests listened< E > at compile time and live< E >() at run time before it builds an event, so that with NoObservers it compiles to the code of the plain structure. batch( s ) opens a group of RAII, nested groups only count, and the outermost one sends the events coalesced into their net effect per handle (by coalesce_traits), as one span per observer; quiet( s ) suspends the events and sends Rebuilt at its end (nothing with no_rebuild); emit( e , undo ) gives the strong guarantee against an observer that throws, by the inverse events and the undo of the structure; each kind has a revision counter. UndoLog makes any structure with apply() undoable, and Shadow checks an incremental observer against one that computes from scratch, and answers the queries of Capabilities.h by the meet of those of the two observers.
An observer that keeps a solution decides between a repair and a computation from scratch by a recompute policy (the concept ReoptPolicy, whose scratch() is asked before the repair, abandon() while it runs and record() after it, on counts of elementary operations and never on times, so that it decides the same on every machine), and counts its outcomes by their causes (Reopt); the default RatioPolicy computes from scratch above \( \rho \) times the size of net events, abandons a repair whose work exceeds \( \alpha \) times that of a scratch or that extracts an element more than \( \beta \) times again, and bounds the drift of the floating values by summing them again periodically or by NeumaierSum. When an observer models with_policy and its policy asks it at the close of a batch, the subject sends it Rebuilt instead of the events.
The contracts [see Contract.h]: on() of Erased, BulkErased, Cleared, Rebuilt and Replaced is noexcept (checked at compile time); an observer neither changes its subject nor attaches or detaches from within on(); nobody attaches or detaches while a batch is open; at the level of the audits the subject calls audit() of its observers after each event outside a batch and after each batch, and counts the events of each observer. The operations are defined in Modification.tpp.