ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Observers.h File Reference

The changes of a graph of LEMON told to the observers of ADS, and a graph of LEMON kept in step with one of ADS, beyond the book (see Interoperation with LEMON): More...

#include "ADS/Contract.h"
#include "ADS/Modification.h"
#include "ADS/graph/Graph.h"
#include "ADS/graph/Observable.h"
#include <lemon/bits/alteration_notifier.h>
#include <lemon/bits/traits.h>
#include <lemon/core.h>
#include <lemon/list_graph.h>
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <unordered_map>
#include <vector>

Go to the source code of this file.

Classes

struct  ADS::lemon_interop::Ends
 the ends of an arc, the key of its events More...
class  ADS::lemon_interop::LemonTap< GR, Item, CostMap, Policy >
 the alteration notifier of LEMON for the items Item of GR told as events of ADS, through Policy More...
class  ADS::lemon_interop::LemonMirror< G >
 a lemon::ListDigraph and its weights kept in step with a graph of ADS, as an observer of its ObservedGraph More...
struct  ADS::lemon_interop::LemonMirror< G >::Kinds
 what the events since the last clearKinds() changed More...

Namespaces

namespace  ADS
namespace  ADS::lemon_interop

Detailed description

The changes of a graph of LEMON told to the observers of ADS, and a graph of LEMON kept in step with one of ADS, beyond the book (see Interoperation with LEMON):

  • LemonTap< GR , Item , CostMap , Policy >, an observer of the alteration notifier of LEMON for the nodes or for the arcs of GR (an ObserverBase of GR::NodeNotifier or of GR::ArcNotifier) that tells each change through the subject policy Policy of ADS [see Modification.h]: Inserted after add(), Erased before the item leaves (erase()), Rebuilt after build() and Cleared before clear(), the handle being the id of the item, so that the parallel arcs of LEMON stay distinct, and the key of an arc its ends ( u , v ), read at both times since LEMON tells an insertion after it and an erasure before it. With a CostMap the erasure of an arc carries its cost, read before LEMON removes it, and the insertion the cost that the map holds at add(), which in the idiom of LEMON, a = g.addArc( u , v ); cost[ a ] = c;, is still the default, so that a write that must be seen goes through an ObservedMap [see Maps.h]. An insertion is told with the strong guarantee of ADS [see Modification.h]: if an observer of ADS throws, those already told receive its erasure, and the exception reaches LEMON, which removes the item again (abLEMON; LEMON 1.3 leaves it in the graph). The vector forms of add() and erase() open a batch of ADS [see ADS::batch()], whose events are coalesced into their net effect per id. LEMON calls its observers in an order that its header does not state, and that we read in the code of the notifier: the oldest first on add() and build(), the newest first on erase() and clear(); a tap that reads a map must therefore be constructed after that map, so that at add() the map has grown and at erase() the value is still there. The erase() and clear() of LEMON must not throw, and an exception of an observer of ADS within them is caught and marks the tap spoiled(). The operations of LEMON that the notifier does not tell (changeTarget(), changeSource(), reverseArc(), the moves of contract() and split()), the writes of the maps that bypass ObservedMap, and the changes through an adaptor of LEMON are not seen. Its cost is that of one more map of LEMON, a virtual call per item inserted or erased, and one test of the subject when nobody of ADS listens;
  • LemonMirror< G >, an observer of an ObservedGraph of ADS [see Observable.h] that keeps a lemon::ListDigraph and its map of the weights in step with the graph \( g \) of ADS, in \( O( 1 ) \) expected time per event (a vector from the names of ADS to the nodes of LEMON, a hash table from the pairs ( u , v ) to the arcs; an unoriented edge is mirrored by its two arcs), and that records the kinds of the events since the last clearKinds() (nodes, arcs, weights, and whether a weight fell or an arc left), so that the caller knows whether an algorithm of LEMON that keeps a state must be built again. The events of ADS name an edge by its ends, and the graphs of ADS have no parallel edges, so that the mirror has none either.

The contracts [see Contract.h]: the graph observed outlives the tap and the mirror; the mirror sees the graph as it is at its construction and then every change through the wrapper. The classes are defined in this file.

See also
B. Dezső, A. Jüttner, P. Kovács, LEMON - an open source C++ graph template library, Electronic Notes in Theoretical Computer Science 264(5), 23-45, 2011, doi:10.1016/j.entcs.2011.06.003
E. Gamma, R. Helm, R. Johnson, J. Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley, 1994, ISBN 0-201-63361-2, the pattern Observer
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa