58#ifndef __ADS_interop_lemon_Maps
59 #define __ADS_interop_lemon_Maps
66#if ! __has_include( <lemon/core.h> )
67 #error "the interoperation with LEMON needs the headers of LEMON"
73#include <lemon/core.h>
94template<
class GR ,
class T ,
class Item =
typename GR::Node >
108 explicit DenseMap(
const GR & g ,
const T & t = T() )
109 : f_g( &g ) , f_n( std::size_t( g.maxId( Item() ) + 1 ) ) ,
110 f_v( new T[ f_n ] ) {
111 std::fill_n( f_v.get() , f_n , t );
116 return( f_v[ at( k ) ] );
120 return( f_v[ at( k ) ] );
124 void set(
const Key & k ,
const T & t ) { f_v[ at( k ) ] = t; }
127 [[nodiscard]] std::size_t
size(
void )
const {
return( f_n ); }
132 [[nodiscard]] std::size_t at(
const Key & k )
const {
133 const auto i = std::size_t( f_g->id( k ) );
140 std::unique_ptr< T[] > f_v;
153decltype( auto ) readAt(
const S & s , std::size_t i )
155 if constexpr(
requires { s.get( i ); } )
156 return( s.get( i ) );
165template<
class GR ,
class S ,
class Item =
typename GR::Node >
173 using Value = std::remove_cvref_t<
decltype( detail::readAt(
174 std::declval< const S & >() , std::size_t() ) ) >;
178 IndexMap(
const GR & g , S & s ) : f_g( &g ) , f_s( &s ) {
179 ADS_PRE( std::size_t( g.maxId( Item() ) + 1 ) <= s.size() );
184 return( detail::readAt( *f_s , at( k ) ) );
188 void set(
const Key & k ,
const Value & v ) { f_s->set( at( k ) , v ); }
193 requires requires(
const S & s ) { s.prefix( std::size_t() ); }
195 return( f_s->prefix( at( k ) + 1 ) );
199 [[nodiscard]] S &
structure(
void )
const {
return( *f_s ); }
204 [[nodiscard]] std::size_t at(
const Key & k )
const {
205 const auto i = std::size_t( f_g->id( k ) );
221template<
class GR ,
class Map ,
class A = mod::Cost ,
222 class Policy = Dynamic<> >
228 using Key =
typename Map::Key;
233 using Subject =
typename Policy::template bind< modifications , ObservedMap >;
237 template<
class... O >
239 : f_g( g ) , f_m( m ) , f_sub( o... ) { }
246 if constexpr( Subject::template listened< Event > )
247 if( f_sub.template live< Event >() ) [[unlikely]] {
248 const Value old = f_m[ k ];
250 f_sub.emit(
Event{ f_g.id( k ) , old , v } );
257 [[nodiscard]]
const Map &
map(
void )
const {
return( f_m ); }
266 requires( Subject::dynamic )
268 return( f_sub.attach( o ) );
274 requires( Subject::dynamic )
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The typed modifications, beyond the book: the vocabulary by which a structure tells the observers att...
const T & ConstReference
a reference to a value read
Definition Maps.h:103
::lemon::True ReferenceMapTag
a ReferenceMap
Definition Maps.h:104
void set(const Key &k, const T &t)
the value of set to
Definition Maps.h:124
std::size_t size(void) const
the number of values, maxId( Item() ) + 1 at the construction
Definition Maps.h:127
T & Reference
a reference to a value
Definition Maps.h:102
T Value
the values
Definition Maps.h:101
ConstReference operator[](const Key &k) const
the value of , read
Definition Maps.h:119
DenseMap(const GR &g, const T &t=T())
the map of the items of , all ; must stay alive and keep its items
Definition Maps.h:108
Item Key
the items
Definition Maps.h:100
Reference operator[](const Key &k)
the value of
Definition Maps.h:115
S & structure(void) const
the structure
Definition Maps.h:199
Item Key
the items
Definition Maps.h:171
std::remove_cvref_t< decltype(detail::readAt( std::declval< const S & >(), std::size_t())) > Value
the values, those that the structure reads
Definition Maps.h:173
Value operator[](const Key &k) const
the value of
Definition Maps.h:183
void set(const Key &k, const Value &v)
the value of set to , by set() of the structure
Definition Maps.h:188
IndexMap(const GR &g, S &s)
the map of the items of on ; both must stay alive
Definition Maps.h:178
Value prefix(const Key &k) const
the aggregate of the values of the ids up to that of , by prefix() of the structure (e....
Definition Maps.h:192
ObservedMap(const GR &g, Map &m, O &... o)
the map of the items of , the static observers o...; both must stay alive
Definition Maps.h:238
Value operator[](const Key &k) const
the value of
Definition Maps.h:242
typename Policy::template bind< modifications, ObservedMap > Subject
the subject
Definition Maps.h:233
Subject & subject(void)
the subject, for ADS::batch() and ADS::quiet()
Definition Maps.h:260
void set(const Key &k, const Value &v)
the value of set to , and Changed
Definition Maps.h:245
typename Map::Value Value
the values
Definition Maps.h:229
int attach(O &o)
attaches the observer and gives its number
Definition Maps.h:265
mod::Changed< A, int, Value > Event
a write
Definition Maps.h:230
typename Map::Key Key
the items
Definition Maps.h:228
void detach(int id)
detaches the observer number
Definition Maps.h:273
const Map & map(void) const
the map below
Definition Maps.h:257
mod::list< Event > modifications
the events
Definition Maps.h:231
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
the attribute A of the item of handle changed from from to to
Definition Modification.h:600