ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::ObservedGraph< G, Policy > Class Template Reference

the graph \( g \), whose changes are sent through the subject policy Policy [see Modification.h] More...

#include <ADS/graph/Observable.h>

Public types

using Weight = typename G::Weight
 the type of the weights
using Event = GraphEvent< Weight >
 the type of the events
using modifications = GraphModifications< Weight >
 the events
using Subject = typename Policy::template bind< modifications , G >
 the subject
using Batch = ADS::Batch< ObservedGraph >
 the channel of a batch, open while it lives [see batch()]

Public member functions

template<class... O>
 ObservedGraph (G &g, O &... o)
 the wrapper of \( g \), the static observers o...; \( g \) must stay alive, and change only through the wrapper
 ObservedGraph (const ObservedGraph &)=delete
 not copied
ObservedGraph & operator= (const ObservedGraph &)=delete
 not assigned
const G & graph (void) const
 the graph
unsigned mask (void) const
 the union of the masks of the observers
bool listening (unsigned k=GraphEvents::ALL) const
 whether anyone listens to one of the kinds \( k \)
std::size_t built (void) const
 the events built so far, sent or collected (none when no one listens)
Subject & subject (void)
 the subject, for ADS::batch() and ADS::quiet()
const Subject & subject (void) const
 the subject
const G & observed (void) const
 what the audits of the observers read: the graph
bool directed (void) const
 whether the graph is oriented
int n (void) const
 the number of nodes
int bound (void) const
 a bound of the numbers of the nodes
bool hasNode (int u) const
 whether \( u \) is a node
std::vector< int > V (void) const
 the nodes
std::vector< int > adj (int u) const
 the nodes adjacent to \( u \)
template<class F>
void forEachAdj (int u, F &&f) const
 f( v ) for each node \( v \) adjacent to \( u \)
template<class F>
void forEachEdge (int u, F &&f) const
 f( v , w ) for each edge \( ( u , v ) \) of weight \( w \)
std::optional< Weight > weight (int u, int v) const
 the weight of \( ( u , v ) \), nothing if there is no such edge
int insertNode (void)
 insertNode() of the graph, and NodeInserted
void insertEdge (int u, int v, const Weight &w=Weight())
 insertEdge() of the graph, and EdgeInserted, or WeightChanged if the edge was there
void deleteEdge (int u, int v)
 deleteEdge() of the graph, and EdgeDeleted if the edge was there
void deleteNode (int u)
 EdgeDeleted for each edge of \( u \), deleteNode() of the graph, and NodeDeleted
bool setWeight (int u, int v, const Weight &w)
 the weight of the edge \( ( u , v ) \) set to \( w \), and WeightChanged; false, and nothing, if there is no such edge
void apply (const EdgeInserted< Weight > &e)
 the insertion of the edge of \( e \), for UndoLog
void apply (const EdgeDeleted< Weight > &e)
 the deletion of the edge of \( e \), for UndoLog
void apply (const WeightChanged< Weight > &e)
 the change of the weight of \( e \), for UndoLog
std::size_t checkpoint (void) const
 a checkpoint of the batches open, the number of their events so far: with rollback() it makes the wrapper undoable, so that a batch that exits by an exception leaves the graph and the observers as they were [see Batch]
bool revertible (std::size_t t) const
 whether the changes since the checkpoint \( t \) can be undone: all on edges, and every kind listened to, so that each is collected
void rollback (std::size_t t)
 back to the checkpoint \( t \) of the batches open: the changes collected since undone by their inverses, the last first (under the mute of the batch, which tells nobody); the graph is then the one at \( t \), up to the order of the edges in its lists
template<class D>
requires ( Subject::dynamic )
int attach (D &o)
 attaches the observer \( o \), of either form, its mask read now, and gives its number
void detach (int id)
 detaches the observer number \( \mathit{id} \)
Batch batch (void)
 opens a channel: the events are collected until it is closed
int depth (void) const
 the depth of the channels open, \( 0 \) if none

Static public member functions

template<forwarding_query_tag T>
static constexpr auto query (T) noexcept
 the answer to the forwarded query of the tag T [see Capabilities.h]: that of the graph, but for the events, which are those of the wrapper

Detailed description

template<Graph G, class Policy = NoObservers>
class ADS::ObservedGraph< G, Policy >

the graph \( g \), whose changes are sent through the subject policy Policy [see Modification.h]

Member typedef documentation

◆ Batch

template<Graph G, class Policy = NoObservers>
using ADS::ObservedGraph< G, Policy >::Batch = ADS::Batch< ObservedGraph >

the channel of a batch, open while it lives [see batch()]

◆ Event

template<Graph G, class Policy = NoObservers>
using ADS::ObservedGraph< G, Policy >::Event = GraphEvent< Weight >

the type of the events

◆ modifications

template<Graph G, class Policy = NoObservers>
using ADS::ObservedGraph< G, Policy >::modifications = GraphModifications< Weight >

the events

◆ Subject

template<Graph G, class Policy = NoObservers>
using ADS::ObservedGraph< G, Policy >::Subject = typename Policy::template bind< modifications , G >

the subject

◆ Weight

template<Graph G, class Policy = NoObservers>
using ADS::ObservedGraph< G, Policy >::Weight = typename G::Weight

the type of the weights

Constructor and destructor documentation

◆ ObservedGraph() [1/2]

template<Graph G, class Policy = NoObservers>
template<class... O>
ADS::ObservedGraph< G, Policy >::ObservedGraph ( G & g,
O &... o )
inlineexplicit

the wrapper of \( g \), the static observers o...; \( g \) must stay alive, and change only through the wrapper

◆ ObservedGraph() [2/2]

template<Graph G, class Policy = NoObservers>
ADS::ObservedGraph< G, Policy >::ObservedGraph ( const ObservedGraph< G, Policy > & )
delete

not copied

Member function documentation

◆ adj()

template<Graph G, class Policy = NoObservers>
std::vector< int > ADS::ObservedGraph< G, Policy >::adj ( int u) const
inlinenodiscard

the nodes adjacent to \( u \)

◆ apply() [1/3]

template<Graph G, class Policy = NoObservers>
void ADS::ObservedGraph< G, Policy >::apply ( const EdgeDeleted< Weight > & e)
inline

the deletion of the edge of \( e \), for UndoLog

◆ apply() [2/3]

template<Graph G, class Policy = NoObservers>
void ADS::ObservedGraph< G, Policy >::apply ( const EdgeInserted< Weight > & e)
inline

the insertion of the edge of \( e \), for UndoLog

◆ apply() [3/3]

template<Graph G, class Policy = NoObservers>
void ADS::ObservedGraph< G, Policy >::apply ( const WeightChanged< Weight > & e)
inline

the change of the weight of \( e \), for UndoLog

◆ attach()

template<Graph G, class Policy = NoObservers>
template<class D>
requires ( Subject::dynamic )
int ADS::ObservedGraph< G, Policy >::attach ( D & o)
inline

attaches the observer \( o \), of either form, its mask read now, and gives its number

Precondition
no channel is open

◆ batch()

template<Graph G, class Policy = NoObservers>
Batch ADS::ObservedGraph< G, Policy >::batch ( void )
inlinenodiscard

opens a channel: the events are collected until it is closed

◆ bound()

template<Graph G, class Policy = NoObservers>
int ADS::ObservedGraph< G, Policy >::bound ( void ) const
inlinenodiscard

a bound of the numbers of the nodes

◆ built()

template<Graph G, class Policy = NoObservers>
std::size_t ADS::ObservedGraph< G, Policy >::built ( void ) const
inlinenodiscard

the events built so far, sent or collected (none when no one listens)

◆ checkpoint()

template<Graph G, class Policy = NoObservers>
std::size_t ADS::ObservedGraph< G, Policy >::checkpoint ( void ) const
inlinenodiscard

a checkpoint of the batches open, the number of their events so far: with rollback() it makes the wrapper undoable, so that a batch that exits by an exception leaves the graph and the observers as they were [see Batch]

◆ deleteEdge()

template<Graph G, class Policy = NoObservers>
void ADS::ObservedGraph< G, Policy >::deleteEdge ( int u,
int v )
inline

deleteEdge() of the graph, and EdgeDeleted if the edge was there

Precondition
\( u \) and \( v \) are distinct nodes

◆ deleteNode()

template<Graph G, class Policy = NoObservers>
void ADS::ObservedGraph< G, Policy >::deleteNode ( int u)

EdgeDeleted for each edge of \( u \), deleteNode() of the graph, and NodeDeleted

Precondition
\( u \) is a node

◆ depth()

template<Graph G, class Policy = NoObservers>
int ADS::ObservedGraph< G, Policy >::depth ( void ) const
inlinenodiscard

the depth of the channels open, \( 0 \) if none

◆ detach()

template<Graph G, class Policy = NoObservers>
void ADS::ObservedGraph< G, Policy >::detach ( int id)
inline

detaches the observer number \( \mathit{id} \)

Precondition
\( \mathit{id} \) was given by attach() and not yet detached, no channel is open

◆ directed()

template<Graph G, class Policy = NoObservers>
bool ADS::ObservedGraph< G, Policy >::directed ( void ) const
inlinenodiscard

whether the graph is oriented

◆ forEachAdj()

template<Graph G, class Policy = NoObservers>
template<class F>
void ADS::ObservedGraph< G, Policy >::forEachAdj ( int u,
F && f ) const
inline

f( v ) for each node \( v \) adjacent to \( u \)

◆ forEachEdge()

template<Graph G, class Policy = NoObservers>
template<class F>
void ADS::ObservedGraph< G, Policy >::forEachEdge ( int u,
F && f ) const
inline

f( v , w ) for each edge \( ( u , v ) \) of weight \( w \)

◆ graph()

template<Graph G, class Policy = NoObservers>
const G & ADS::ObservedGraph< G, Policy >::graph ( void ) const
inlinenodiscard

the graph

◆ hasNode()

template<Graph G, class Policy = NoObservers>
bool ADS::ObservedGraph< G, Policy >::hasNode ( int u) const
inlinenodiscard

whether \( u \) is a node

◆ insertEdge()

template<Graph G, class Policy = NoObservers>
void ADS::ObservedGraph< G, Policy >::insertEdge ( int u,
int v,
const Weight & w = Weight() )
inline

insertEdge() of the graph, and EdgeInserted, or WeightChanged if the edge was there

Precondition
\( u \) and \( v \) are distinct nodes

◆ insertNode()

template<Graph G, class Policy = NoObservers>
int ADS::ObservedGraph< G, Policy >::insertNode ( void )
inline

insertNode() of the graph, and NodeInserted

◆ listening()

template<Graph G, class Policy = NoObservers>
bool ADS::ObservedGraph< G, Policy >::listening ( unsigned k = GraphEvents::ALL) const
inlinenodiscard

whether anyone listens to one of the kinds \( k \)

◆ mask()

template<Graph G, class Policy = NoObservers>
unsigned ADS::ObservedGraph< G, Policy >::mask ( void ) const
inlinenodiscard

the union of the masks of the observers

◆ n()

template<Graph G, class Policy = NoObservers>
int ADS::ObservedGraph< G, Policy >::n ( void ) const
inlinenodiscard

the number of nodes

◆ observed()

template<Graph G, class Policy = NoObservers>
const G & ADS::ObservedGraph< G, Policy >::observed ( void ) const
inlinenodiscard

what the audits of the observers read: the graph

◆ operator=()

template<Graph G, class Policy = NoObservers>
ObservedGraph & ADS::ObservedGraph< G, Policy >::operator= ( const ObservedGraph< G, Policy > & )
delete

not assigned

◆ query()

template<Graph G, class Policy = NoObservers>
template<forwarding_query_tag T>
constexpr auto ADS::ObservedGraph< G, Policy >::query ( T )
inlinestaticnodiscardconstexprnoexcept

the answer to the forwarded query of the tag T [see Capabilities.h]: that of the graph, but for the events, which are those of the wrapper

◆ revertible()

template<Graph G, class Policy = NoObservers>
bool ADS::ObservedGraph< G, Policy >::revertible ( std::size_t t) const
nodiscard

whether the changes since the checkpoint \( t \) can be undone: all on edges, and every kind listened to, so that each is collected

◆ rollback()

template<Graph G, class Policy = NoObservers>
void ADS::ObservedGraph< G, Policy >::rollback ( std::size_t t)

back to the checkpoint \( t \) of the batches open: the changes collected since undone by their inverses, the last first (under the mute of the batch, which tells nobody); the graph is then the one at \( t \), up to the order of the edges in its lists

Precondition
revertible( t )

◆ setWeight()

template<Graph G, class Policy = NoObservers>
bool ADS::ObservedGraph< G, Policy >::setWeight ( int u,
int v,
const Weight & w )
inline

the weight of the edge \( ( u , v ) \) set to \( w \), and WeightChanged; false, and nothing, if there is no such edge

In pseudocode (beyond the book), the pattern of every change, with \( k \) the kind of its event, \( M \) the union of the masks, \( d \) the depth of the channels and \( B \) the events collected:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{setWeight}( u , v , w ) \cr 2 & \quad \textbf{if}\ k \notin M\ \textbf{then}\ \text{change } g; \ \textbf{return} \cr 3 & \quad w_0 \gets \text{the weight of } ( u , v ) \text{ in } g; \ \text{change } g \cr 4 & \quad e \gets \mathrm{WeightChanged}( u , v , w_0 , w ) \cr 5 & \quad \textbf{if}\ d > 0\ \textbf{then}\ \text{append } e \text{ to } B \cr 6 & \quad \textbf{else foreach}\ \text{observer } o\ \textbf{with} \ k \in M_o\ \textbf{do}\ o.\mathrm{notify}( e ) \end{array}} \]

The test of line 2 is false at compile time when nobody may listen (NoObservers, or static observers that do not want \( k \)), and the change is then the code of the graph.

Precondition
\( u \) and \( v \) are nodes

◆ subject() [1/2]

template<Graph G, class Policy = NoObservers>
Subject & ADS::ObservedGraph< G, Policy >::subject ( void )
inlinenodiscard

the subject, for ADS::batch() and ADS::quiet()

◆ subject() [2/2]

template<Graph G, class Policy = NoObservers>
const Subject & ADS::ObservedGraph< G, Policy >::subject ( void ) const
inlinenodiscard

the subject

◆ V()

template<Graph G, class Policy = NoObservers>
std::vector< int > ADS::ObservedGraph< G, Policy >::V ( void ) const
inlinenodiscard

the nodes

◆ weight()

template<Graph G, class Policy = NoObservers>
std::optional< Weight > ADS::ObservedGraph< G, Policy >::weight ( int u,
int v ) const
inlinenodiscard

the weight of \( ( u , v ) \), nothing if there is no such edge


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