ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Modification.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File Modification.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
112/*--------------------------------------------------------------------------*/
113/*----------------------------- DEFINITIONS --------------------------------*/
114/*--------------------------------------------------------------------------*/
115
116#ifndef __ADS_Modification
117 #define __ADS_Modification
118/* self-identification: #endif constant */
119
120/*--------------------------------------------------------------------------*/
121/*------------------------------ INCLUDES ----------------------------------*/
122/*--------------------------------------------------------------------------*/
123
124#include "ADS/Capabilities.h"
125#include "ADS/Contract.h"
126#include "ADS/Portable.h"
127
128#include <array>
129#include <concepts>
130#include <cstddef>
131#include <cstdint>
132#include <exception>
133#include <functional>
134#include <memory>
135#include <span>
136#include <stdexcept>
137#include <tuple>
138#include <type_traits>
139#include <utility>
140#include <variant>
141#include <vector>
142
143/*--------------------------------------------------------------------------*/
144/*--------------------------- NAMESPACE ------------------------------------*/
145/*--------------------------------------------------------------------------*/
146
147namespace ADS
148{
149
150/*--------------------------------------------------------------------------*/
151/*------------------------------ THE ANSWERS -------------------------------*/
152/*--------------------------------------------------------------------------*/
153
156enum class Keep { Yes , Detach };
157
160class Refused : public std::runtime_error
161{
162 public:
163 using std::runtime_error::runtime_error;
164 };
165
168{
169 explicit constexpr no_rebuild_t( void ) = default;
170 };
171
173inline constexpr no_rebuild_t no_rebuild{};
174
175/*--------------------------------------------------------------------------*/
176/*---------------------------- THE RECOMPUTE POLICY ------------------------*/
177/*--------------------------------------------------------------------------*/
178
182struct Reopt
183{
184 static constexpr int SCRATCH = 0;
185 static constexpr int WARM = 1;
186 static constexpr int CERTIFIED = 2;
187 static constexpr int SCRATCH_BY_SIZE = 3;
189 static constexpr int SCRATCH_BY_ABORT = 4;
191 static constexpr int SCRATCH_BY_EVENT = 5;
194 static constexpr int PARTIAL = 6;
196 static constexpr int CAUSES = 7;
197
199 [[nodiscard]] static constexpr int outcomeOf( int c ) {
200 return( c < SCRATCH_BY_SIZE ? c : ( c == PARTIAL ? WARM : SCRATCH ) );
201 }
202 };
203
208{
209 std::size_t events = 0;
210 std::size_t size = 0;
211 double work = 0;
212 double lastScratch = 0;
213 std::size_t reinsertions = 0;
215 bool closing = false;
217 };
218
222template< class P >
223concept ReoptPolicy =
224 requires( P & p , const ReoptStats & s , int outcome , double w )
225{
226 { p.scratch( s ) } -> std::convertible_to< bool >;
227 { p.abandon( s , w ) } -> std::convertible_to< bool >;
228 p.record( outcome , w );
229 };
230
239{
240 double rho = 0.25;
241 double alpha = 0.5;
242 int beta = 0;
243 bool early = false;
245 double period = 1;
247 bool compensated = false;
248
252 [[nodiscard]] bool scratch( const ReoptStats & s ) const {
253 if( s.closing && ! early )
254 return( false );
255 const std::size_t n = s.size > 1 ? s.size : 1;
256 return( double( s.events ) > rho * double( n ) );
257 }
258
262 [[nodiscard]] bool abandon( const ReoptStats & s , double w ) const {
263 return( ( w > alpha * s.lastScratch ) ||
264 ( ( beta > 0 ) && ( s.reinsertions > std::size_t( beta ) ) ) );
265 }
266
268 void record( int , double ) const { }
269
273 [[nodiscard]] bool refresh( std::size_t c , std::size_t n ) const {
274 const std::size_t m = n > 1 ? n : 1;
275 return( ( period > 0 ) && ( double( c ) >= period * double( m ) ) );
276 }
277 };
278
296template< class T >
298{
299 public:
301 explicit NeumaierSum( bool compensated = false ) : f_on( compensated ) { }
302
304 void add( const T & x ) {
305 if constexpr( std::is_floating_point_v< T > )
306 if( f_on ) {
307 const T t = f_s + x;
308 const T as = f_s < T() ? -f_s : f_s;
309 const T ax = x < T() ? -x : x;
310 f_c += as >= ax ? ( f_s - t ) + x : ( x - t ) + f_s;
311 f_s = t;
312 return;
313 }
314 f_s = f_s + x;
315 }
316
318 void sub( const T & x ) {
319 if constexpr( std::is_floating_point_v< T > )
320 if( f_on ) {
321 add( -x );
322 return;
323 }
324 f_s = f_s - x;
325 }
326
328 [[nodiscard]] T value( void ) const {
329 if constexpr( std::is_floating_point_v< T > )
330 return( f_s + f_c );
331 else
332 return( f_s );
333 }
334
336 void reset( const T & x = T() ) {
337 f_s = x;
338 f_c = T();
339 }
340
342 void compensate( bool on ) { f_on = on; }
343
345 [[nodiscard]] bool compensated( void ) const { return( f_on ); }
346
347 private:
348 T f_s = T();
349 T f_c = T();
350 bool f_on;
351
352 }; // end( class NeumaierSum )
353
354namespace mod
355{
356
357/*--------------------------------------------------------------------------*/
358/*------------------------------- THE EFFECTS ------------------------------*/
359/*--------------------------------------------------------------------------*/
360
362struct effect
363{
364 static constexpr unsigned grows = 1u;
365 static constexpr unsigned shrinks = 2u;
366 static constexpr unsigned up = 4u;
367 static constexpr unsigned down = 8u;
368 static constexpr unsigned all = 15u;
369 };
370
386
388namespace detail
389{
390
391template< class E >
392constexpr Role declared_role( void )
393{
394 if constexpr( requires { E::role; } )
395 return( E::role );
396 else
397 return( Role::Other );
398 }
399
400template< class E >
401constexpr unsigned declared_effects( void )
402{
403 if constexpr( requires { E::effects; } )
404 return( unsigned( E::effects ) );
405 else
406 return( effect::all );
407 }
408
409} // end( namespace detail )
411
413template< class E >
414inline constexpr Role role_of = detail::declared_role< E >();
415
417template< class E >
418inline constexpr unsigned effects_of = detail::declared_effects< E >();
419
423template< class E >
424inline constexpr bool must_not_throw =
428
429/*--------------------------------------------------------------------------*/
430/*------------------------- THE ATTRIBUTES AND LISTS -----------------------*/
431/*--------------------------------------------------------------------------*/
432
433struct Value
434{ };
435struct Key
436{ };
437struct Cost
438{ };
439struct Upper
440{ };
441struct Lower
442{ };
443struct Supply
444{ };
445struct Parent
446{ };
447
451namespace reduce
452{
453struct last
454{ };
455struct min
456{ };
457struct max
458{ };
459struct sum
460{ };
461} // end( namespace reduce )
462
465template< class A >
467{
469 };
470
472template< class A >
473 requires requires { typename A::reduction; }
474struct reduction_of< A >
475{
476 using type = typename A::reduction;
477 };
478
480template< class... E >
481struct list
482{
483 static constexpr std::size_t size = sizeof...( E );
484 };
485
487namespace detail
488{
489
490template< class E , class L >
491struct index_in;
492
493template< class E , class... T >
494struct index_in< E , list< T... > >
495{
496 static constexpr std::size_t value = [] {
497 constexpr bool same[] = { std::is_same_v< E , T >... , false };
498 std::size_t i = 0;
499 while( ( i < sizeof...( T ) ) && ! same[ i ] )
500 ++i;
501 return( i );
502 }();
503 };
504
505template< class L >
506struct variant_of;
507
508template< class... T >
509struct variant_of< list< T... > >
510{
511 using type = std::variant< T... >;
512 };
513
514} // end( namespace detail )
516
518template< class E , class L >
519inline constexpr std::size_t index_v = detail::index_in< E , L >::value;
520
522template< class E , class L >
523inline constexpr bool contains_v = index_v< E , L > < L::size;
524
526template< class L >
527using variant_t = typename detail::variant_of< L >::type;
528
529/*--------------------------------------------------------------------------*/
530/*------------------------------- THE EVENTS -------------------------------*/
531/*--------------------------------------------------------------------------*/
532
534template< class H , class K , class V = void >
536{
537 static constexpr unsigned effects = effect::grows;
538 static constexpr Role role = Role::Insert;
539 using handle_type = H;
540 using key_type = K;
541 using value_type = V;
542 H h;
543 K key;
546 bool operator==( const Inserted & ) const = default;
547 };
548
550template< class H , class K >
551struct Inserted< H , K , void >
552{
553 static constexpr unsigned effects = effect::grows;
554 static constexpr Role role = Role::Insert;
555 using handle_type = H;
556 using key_type = K;
557 using value_type = void;
558 H h;
559 K key;
561 bool operator==( const Inserted & ) const = default;
562 };
563
566template< class H , class K , class V = void >
567struct Erased
568{
569 static constexpr unsigned effects = effect::shrinks;
570 static constexpr Role role = Role::Erase;
571 using handle_type = H;
572 using key_type = K;
573 using value_type = V;
574 H h;
575 K key;
578 bool operator==( const Erased & ) const = default;
579 };
580
582template< class H , class K >
583struct Erased< H , K , void >
584{
585 static constexpr unsigned effects = effect::shrinks;
586 static constexpr Role role = Role::Erase;
587 using handle_type = H;
588 using key_type = K;
589 using value_type = void;
590 H h;
591 K key;
593 bool operator==( const Erased & ) const = default;
594 };
595
598template< class A , class H , class V >
600{
601 static constexpr unsigned effects = effect::up | effect::down;
602 static constexpr Role role = Role::Change;
603 using attribute = A;
604 using handle_type = H;
605 using value_type = V;
606 H h;
608 V to;
611 [[nodiscard]] constexpr unsigned direction( void ) const {
612 if constexpr( std::totally_ordered< V > )
613 return( to < from ? effect::down : from < to ? effect::up : 0u );
614 else
615 return( effects );
616 }
617
618 bool operator==( const Changed & ) const = default;
619 };
620
622template< class H , class V >
624
626template< class H , class K >
628
631template< class H >
633{
634 static constexpr unsigned effects = 0u;
635 static constexpr Role role = Role::Relocate;
636 using handle_type = H;
638 H to;
640 bool operator==( const Relocated & ) const = default;
641 };
642
644template< class H >
646{
647 static constexpr unsigned effects = 0u;
648 static constexpr Role role = Role::Permute;
649 std::span< const H > old_of_new;
650 };
651
653template< class H >
655{
656 static constexpr unsigned effects = effect::grows;
657 static constexpr Role role = Role::BulkInsert;
658 std::span< const H > hs;
659 };
660
662template< class H >
664{
665 static constexpr unsigned effects = effect::shrinks;
666 static constexpr Role role = Role::BulkErase;
667 std::span< const H > hs;
668 };
669
671template< class A , class D >
673{
674 static constexpr unsigned effects = effect::up | effect::down;
675 static constexpr Role role = Role::Shift;
676 using attribute = A;
679 [[nodiscard]] constexpr unsigned direction( void ) const {
680 return( D() < delta ? effect::up : delta < D() ? effect::down : 0u );
681 }
682
683 bool operator==( const Shifted & ) const = default;
684 };
685
687template< class A >
689{
690 static constexpr unsigned effects = effect::all;
691 static constexpr Role role = Role::Replace;
692 using attribute = A;
694 bool operator==( const Replaced & ) const = default;
695 };
696
699{
700 static constexpr unsigned effects = effect::all;
701 static constexpr Role role = Role::Clear;
703 bool operator==( const Cleared & ) const = default;
704 };
705
708{
709 static constexpr unsigned effects = effect::all;
710 static constexpr Role role = Role::Rebuild;
712 bool operator==( const Rebuilt & ) const = default;
713 };
714
715/*--------------------------------------------------------------------------*/
716/*------------------------------ THE INVERSES ------------------------------*/
717/*--------------------------------------------------------------------------*/
718
720template< class H , class K , class V >
721[[nodiscard]] constexpr Erased< H , K , V >
723{
724 if constexpr( std::is_void_v< V > )
725 return( Erased< H , K , V >{ e.h , e.key } );
726 else
727 return( Erased< H , K , V >{ e.h , e.key , e.value } );
728 }
729
731template< class H , class K , class V >
732[[nodiscard]] constexpr Inserted< H , K , V >
734{
735 if constexpr( std::is_void_v< V > )
736 return( Inserted< H , K , V >{ e.h , e.key } );
737 else
738 return( Inserted< H , K , V >{ e.h , e.key , e.value } );
739 }
740
742template< class A , class H , class V >
743[[nodiscard]] constexpr Changed< A , H , V >
745{
746 return( Changed< A , H , V >{ e.h , e.to , e.from } );
747 }
748
750template< class H >
751[[nodiscard]] constexpr Relocated< H > inverse( const Relocated< H > & e )
752{
753 return( Relocated< H >{ e.to , e.from } );
754 }
755
757template< class A , class D >
758[[nodiscard]] constexpr Shifted< A , D > inverse( const Shifted< A , D > & e )
759{
760 return( Shifted< A , D >{ D() - e.delta } );
761 }
762
764template< class E >
765concept invertible = requires( const E & e )
766{ inverse( e ); };
767
768/*--------------------------------------------------------------------------*/
769/*------------------------------- THE GROUPS -------------------------------*/
770/*--------------------------------------------------------------------------*/
771
774struct Group
775{
776 std::uint64_t from = 0;
777 std::uint64_t to = 0;
778 std::size_t size = 0;
779 };
780
782struct Counts
783{
784 std::uint64_t events = 0;
785 std::uint64_t groups = 0;
786 std::uint64_t rebuilds = 0;
787 };
788
789/*--------------------------------------------------------------------------*/
790/*------------------------------ THE OBSERVERS -----------------------------*/
791/*--------------------------------------------------------------------------*/
792
794template< class O , class E >
795concept observes = requires( O & o , const E & e )
796{ o.on( e ); };
797
799template< class O , class E >
801 requires( O & o , std::span< const E > s )
802{ o.on( s ); };
803
805template< class O >
806concept groups = requires( O & o , const Group & g )
807{
808 o.group_begin( g );
809 o.group_end();
810 } || requires( O & o )
811{
812 o.group_begin();
813 o.group_end();
814 };
815
817template< class O , class E >
818concept refuses = requires( const O & o , const E & e )
819{
820 { o.prepare( e ) } -> std::same_as< bool >;
821 };
822
824template< class O , class S >
825concept auditable = requires( const O & o , const S & s )
826{
827 { o.audit( s ) } -> std::convertible_to< bool >;
828 };
829
831template< class O >
832concept lazy = requires( O & o )
833{ o.flush(); };
834
836template< class O >
837concept counted = requires( const O & o )
838{ o.counts(); };
839
844template< class O >
845concept with_policy = requires( O & o , std::size_t k )
846{
847 { o.policy() } -> ReoptPolicy;
848 { o.reoptStats( k ) } -> std::convertible_to< ReoptStats >;
849 };
850
853template< class O >
854concept masked = requires( const O & o )
855{
856 { o.mask() } -> std::convertible_to< std::uint64_t >;
857 };
858
860namespace detail
861{
862
863template< class O , class L >
864struct any_observed;
865
866template< class O , class... E >
867struct any_observed< O , list< E... > >
868{
869 static constexpr bool value = ( observes< O , E > || ... );
870 };
871
872} // end( namespace detail )
874
876template< class O , class L >
877concept observer_of = detail::any_observed< O , L >::value;
878
879/*--------------------------------------------------------------------------*/
880/*------------------------------ THE ADAPTERS ------------------------------*/
881/*--------------------------------------------------------------------------*/
882
886struct Direct
887{
889 template< class O , class E >
890 requires observes< O , E >
891 static decltype( auto ) one( O & o ,
892 const E & e ) noexcept( noexcept( o.on( e ) ) ) {
893 return( o.on( e ) );
894 }
895
896 template< class O , class E >
898 static void many( O & o , std::span< const E > s ) {
899 o.on( s );
900 }
901
902 template< class O >
903 requires groups< O >
904 static void begin( O & o , const Group & g ) {
905 if constexpr( requires { o.group_begin( g ); } )
906 o.group_begin( g );
907 else
908 o.group_begin();
909 }
910
911 template< class O >
912 requires groups< O >
913 static void end( O & o ) {
914 o.group_end();
915 }
916
917 template< class O , class E >
918 requires refuses< O , E >
919 static bool prepare( const O & o , const E & e ) {
920 return( o.prepare( e ) );
921 }
922
923 template< class O , class S >
924 requires auditable< O , S >
925 static bool audit( const O & o , const S & s ) {
926 return( bool( o.audit( s ) ) );
927 }
928
929 template< class O >
930 requires masked< O >
931 static std::uint64_t mask( const O & o ) {
932 return( std::uint64_t( o.mask() ) );
933 }
934
936 template< class O >
938 static bool early( O & o , std::size_t k ) {
939 ReoptStats s = o.reoptStats( k );
940 s.closing = true;
941 return( bool( o.policy().scratch( s ) ) );
942 }
943
944 template< class O >
946 static void rebuilt( O & o ) noexcept {
947 o.on( Rebuilt{} );
948 }
949 };
950
952template< class O , class A = Direct >
953struct Via
954{ };
955
956/*--------------------------------------------------------------------------*/
957/*------------------------------ THE COALESCING ----------------------------*/
958/*--------------------------------------------------------------------------*/
959
966template< class L >
968{
971 static std::vector< variant_t< L > >
972 coalesce( std::span< const variant_t< L > > B );
973 };
974
975/*--------------------------------------------------------------------------*/
976/*---------------------------- THE SUBJECT PARTS ---------------------------*/
977/*--------------------------------------------------------------------------*/
978
980namespace detail
981{
982
984template< class X >
985struct held
986{
987 using object = X;
988 using adapter = Direct;
989 };
990
991template< class O , class A >
992struct held< Via< O , A > >
993{
994 using object = O;
995 using adapter = A;
996 };
997
999template< class A , class O , class E >
1000concept calls = requires( O & o , const E & e )
1001{ A::one( o , e ); };
1002
1004template< class A , class O , class E >
1005inline constexpr bool calls_keep = [] {
1006 if constexpr( calls< A , O , E > )
1007 return( std::same_as< decltype( A::one( std::declval< O & >() ,
1008 std::declval< const E & >() ) ) ,
1009 Keep > );
1010 else
1011 return( false );
1012 }();
1013
1015template< class A , class O , class E >
1016inline constexpr bool calls_nothrow = [] {
1017 if constexpr( calls< A , O , E > )
1018 return(
1019 noexcept( A::one( std::declval< O & >() ,
1020 std::declval< const E & >() ) ) );
1021 else
1022 return( true );
1023 }();
1024
1026template< class A , class O , class E >
1027concept calls_span =
1028 requires( O & o , std::span< const E > s )
1029{ A::many( o , s ); };
1030
1032template< class A , class O >
1033concept calls_group = requires( O & o , const Group & g )
1034{
1035 A::begin( o , g );
1036 A::end( o );
1037 };
1038
1040template< class A , class O , class E >
1041concept calls_prepare = requires( const O & o , const E & e )
1042{
1043 { A::prepare( o , e ) } -> std::same_as< bool >;
1044 };
1045
1047template< class A , class O , class S >
1048concept calls_audit = requires( const O & o , const S & s )
1049{
1050 { A::audit( o , s ) } -> std::convertible_to< bool >;
1051 };
1052
1054template< class A , class O >
1055concept calls_mask = requires( const O & o )
1056{
1057 { A::mask( o ) } -> std::convertible_to< std::uint64_t >;
1058 };
1059
1061template< class A , class O >
1062concept calls_policy = requires( O & o , std::size_t k )
1063{
1064 { A::early( o , k ) } -> std::same_as< bool >;
1065 A::rebuilt( o );
1066 };
1067
1069template< class Var >
1070std::size_t eventsFor( std::span< const Var > C , std::uint64_t m , bool all )
1071{
1072 if( all )
1073 return( C.size() );
1074 std::size_t k = 0;
1075 for( const auto & e : C )
1076 k += std::size_t( ( m >> e.index() ) & 1u );
1077 return( k );
1078 }
1079
1081template< class A , class O , class L >
1082struct kinds_of;
1083
1084template< class A , class O , class... E >
1085struct kinds_of< A , O , list< E... > >
1086{
1087 static constexpr std::uint64_t value = [] {
1088 std::uint64_t m = 0;
1089 std::size_t i = 0;
1090 ( ( m |= ( calls< A , O , E > ? ( std::uint64_t( 1 ) << i ) : 0 ) , ++i ) ,
1091 ... );
1092 return( m );
1093 }();
1094 static constexpr bool keep = ( calls_keep< A , O , E > || ... );
1095 static constexpr bool nothrow_ok =
1096 ( ( ! must_not_throw< E > || calls_nothrow< A , O , E > ) && ... );
1097 };
1098
1100template< class R , class L >
1101struct all_in;
1102
1103template< class... R , class L >
1104struct all_in< list< R... > , L >
1105{
1106 static constexpr bool value = ( contains_v< R , L > && ... );
1107 };
1108
1110template< class O >
1111struct required
1112{
1113 using type = list<>;
1114 };
1115
1116template< class O >
1117 requires requires { typename O::requires_modifications; }
1118struct required< O >
1119{
1120 using type = typename O::requires_modifications;
1121 };
1122
1125template< class A , class O , class L >
1126constexpr void check( void )
1127{
1128 static_assert( kinds_of< A , O , L >::value != 0 ,
1129 "ADS: the observer has an on() for none of the events of "
1130 "the structure" );
1131 static_assert( all_in< typename required< O >::type , L >::value ,
1132 "ADS: the observer requires an event that the structure "
1133 "never emits" );
1134 static_assert( kinds_of< A , O , L >::nothrow_ok ,
1135 "ADS: on() of Erased, BulkErased, Cleared, Rebuilt and "
1136 "Replaced must be noexcept" );
1137 }
1138
1140template< class L , class F >
1141void visitKind( std::size_t k , F && f );
1142
1145template< class A , class O , class E , class Var >
1146bool giveRun( O & o , std::span< const Var > R );
1147
1149template< bool B >
1150struct OffBits
1151{
1152 [[nodiscard]] constexpr bool off( std::size_t ) const { return( false ); }
1153 constexpr void set( std::size_t ) { }
1154 };
1155
1156template<>
1157struct OffBits< true >
1158{
1159 std::uint64_t bits = 0;
1160 [[nodiscard]] bool off( std::size_t i ) const {
1161 return( ( bits >> i ) & 1u );
1162 }
1163 void set( std::size_t i ) { bits |= std::uint64_t( 1 ) << i; }
1164 };
1165
1168template< std::size_t N , bool B = ( ADS_CONTRACTS >= 3 ) >
1169struct StaticCounts
1170{
1171 [[nodiscard]] static Counts at( std::size_t ) { return( Counts() ); }
1172 static void event( std::size_t ) { }
1173 static void group( std::size_t ) { }
1174 static void rebuild( std::size_t ) { }
1175 };
1176
1177template< std::size_t N >
1178struct StaticCounts< N , true >
1179{
1180 std::array< Counts , N > c{};
1181 [[nodiscard]] Counts at( std::size_t i ) const { return( c[ i ] ); }
1182 void event( std::size_t i ) { ++c[ i ].events; }
1183 void group( std::size_t i ) { ++c[ i ].groups; }
1184 void rebuild( std::size_t i ) { ++c[ i ].rebuilds; }
1185 };
1186
1189struct Trail
1190{
1191 std::uint64_t st = 0;
1192 std::size_t dy = 0;
1193 };
1194
1196template< class L >
1197struct NoStatic
1198{
1199 template< class E >
1200 static constexpr bool listened = false;
1201 template< class... A >
1202 constexpr explicit NoStatic( A &... ) {
1203 static_assert( sizeof...( A ) == 0 ,
1204 "ADS: observers given to a subject with no static part" );
1205 }
1206 template< class E >
1207 [[nodiscard]] constexpr bool live( void ) const {
1208 return( false );
1209 }
1210 [[nodiscard]] constexpr std::uint64_t wanted( void ) const { return( 0 ); }
1211 template< class E , bool T >
1212 constexpr void deliver( const E & , Trail & ) { }
1213 template< class E , class Inv >
1214 constexpr void undo( const Inv & , const Trail & ) noexcept { }
1215 template< class E >
1216 [[nodiscard]] constexpr bool prepare( const E & ) const {
1217 return( true );
1218 }
1219 template< class S >
1220 [[nodiscard]] constexpr bool audit( const S & ) const {
1221 return( true );
1222 }
1223 template< class Var >
1224 constexpr void deliverGroup( std::span< const Var > , std::uint64_t ,
1225 const Group & , std::vector< Var > & ) { }
1226 };
1227
1230template< class L , class Obs , class... X >
1231class StaticSet
1232{
1233
1234 static constexpr std::size_t N = sizeof...( X );
1235 using Objects = std::tuple< typename held< X >::object &... >;
1236 template< std::size_t I >
1237 using Xi = std::tuple_element_t< I , std::tuple< X... > >;
1238 template< std::size_t I >
1239 using Oi = typename held< Xi< I > >::object;
1240 template< std::size_t I >
1241 using Ai = typename held< Xi< I > >::adapter;
1242
1243 static constexpr bool may_leave =
1244 ( kinds_of< typename held< X >::adapter , typename held< X >::object ,
1245 L >::keep ||
1246 ... );
1247
1248 public:
1249 template< class E >
1250 static constexpr bool listened =
1251 ( calls< typename held< X >::adapter , typename held< X >::object , E > ||
1252 ... );
1253
1254 template< class... A >
1255 explicit StaticSet( A &... a ) : f_o( a... ) {
1256 static_assert( N <= 64 , "ADS: at most 64 static observers" );
1257 ( check< typename held< X >::adapter , typename held< X >::object , L >() ,
1258 ... );
1259 checkOrder( std::make_index_sequence< N >() );
1260 }
1261
1263 template< std::size_t I , class E >
1264 [[nodiscard]] bool wants( void ) const {
1265 if constexpr( ! calls< Ai< I > , Oi< I > , E > )
1266 return( false );
1267 else {
1268 bool w = true;
1269 if constexpr( calls_mask< Ai< I > , Oi< I > > )
1270 w = ( Ai< I >::mask( std::get< I >( f_o ) ) >> index_v< E , L > )&1u;
1271 if constexpr( may_leave )
1272 w = w && ! f_off.off( I );
1273 return( w );
1274 }
1275 }
1276
1277 template< class E >
1278 [[nodiscard]] bool live( void ) const {
1279 return( [ & ]< std::size_t... I >( std::index_sequence< I... > ) {
1280 return( ( wants< I , E >() || ... ) );
1281 }( std::make_index_sequence< N >() ) );
1282 }
1283
1285 [[nodiscard]] std::uint64_t wanted( void ) const {
1286 return( [ & ]< std::size_t... I >( std::index_sequence< I... > ) {
1287 return( ( wantedBy< I >() | ... | std::uint64_t( 0 ) ) );
1288 }( std::make_index_sequence< N >() ) );
1289 }
1290
1291 template< class E , bool T >
1292 void deliver( const E & e , Trail & t ) {
1293 [ & ]< std::size_t... I >( std::index_sequence< I... > ) {
1294 ( step< I , T >( e , t ) , ... );
1295 }( std::make_index_sequence< N >() );
1296 }
1297
1298 template< class E , class Inv >
1299 void undo( const Inv & e , const Trail & t ) noexcept {
1300 std::uint64_t leave = 0;
1301 [ & ]< std::size_t... I >( std::index_sequence< I... > ) {
1302 ( back< N - 1 - I , E >( e , t , leave ) , ... );
1303 }( std::make_index_sequence< N >() );
1304 if constexpr( may_leave )
1305 for( std::size_t i = 0 ; i < N ; ++i )
1306 if( ( leave >> i ) & 1u )
1307 f_off.set( i );
1308 }
1309
1310 template< class E >
1311 [[nodiscard]] bool prepare( const E & e ) const {
1312 return( [ & ]< std::size_t... I >( std::index_sequence< I... > ) {
1313 return( ( prepareOne< I >( e ) && ... ) );
1314 }( std::make_index_sequence< N >() ) );
1315 }
1316
1317 template< class S >
1318 [[nodiscard]] bool audit( const S & s ) const {
1319 return( [ & ]< std::size_t... I >( std::index_sequence< I... > ) {
1320 return( ( auditOne< I >( s ) && ... ) );
1321 }( std::make_index_sequence< N >() ) );
1322 }
1323
1324 template< class Var >
1325 void deliverGroup( std::span< const Var > C , std::uint64_t kinds ,
1326 const Group & g , std::vector< Var > & tmp ) {
1327 [ & ]< std::size_t... I >( std::index_sequence< I... > ) {
1328 ( groupOne< I >( C , kinds , g , tmp ) , ... );
1329 }( std::make_index_sequence< N >() );
1330 }
1331
1332 [[nodiscard]] Counts counts( std::size_t i ) const {
1333 return( f_counts.at( i ) );
1334 }
1335
1336 private:
1337 template< std::size_t I >
1338 [[nodiscard]] std::uint64_t wantedBy( void ) const {
1339 std::uint64_t m = kinds_of< Ai< I > , Oi< I > , L >::value;
1340 if constexpr( calls_mask< Ai< I > , Oi< I > > )
1341 m &= Ai< I >::mask( std::get< I >( f_o ) );
1342 if constexpr( may_leave )
1343 if( f_off.off( I ) )
1344 m = 0;
1345 return( m );
1346 }
1347
1348 template< std::size_t I , bool T , class E >
1349 void step( const E & e , Trail & t ) {
1350 if constexpr( calls< Ai< I > , Oi< I > , E > ) {
1351 if( ! wants< I , E >() )
1352 return;
1353 f_counts.event( I );
1354 if constexpr( std::is_same_v< E , Rebuilt > )
1355 f_counts.rebuild( I );
1356 if constexpr( calls_keep< Ai< I > , Oi< I > , E > ) {
1357 if( Ai< I >::one( std::get< I >( f_o ) , e ) == Keep::Detach )
1358 f_off.set( I );
1359 }
1360 else
1361 Ai< I >::one( std::get< I >( f_o ) , e );
1362 if constexpr( T )
1363 t.st |= std::uint64_t( 1 ) << I;
1364 }
1365 }
1366
1367 template< std::size_t I , class E , class Inv >
1368 void back( const Inv & e , const Trail & t ,
1369 std::uint64_t & leave ) noexcept {
1370 if constexpr( calls< Ai< I > , Oi< I > , Inv > ) {
1371 if( ( ( t.st >> I ) & 1u ) == 0 )
1372 return;
1373 try {
1374 if constexpr( calls_keep< Ai< I > , Oi< I > , Inv > ) {
1375 if( Ai< I >::one( std::get< I >( f_o ) , e ) == Keep::Detach )
1376 leave |= std::uint64_t( 1 ) << I;
1377 }
1378 else
1379 Ai< I >::one( std::get< I >( f_o ) , e );
1380 }
1381 catch( ... ) {
1382 } // the first exception wins
1383 }
1384 }
1385
1386 template< std::size_t I , class E >
1387 [[nodiscard]] bool prepareOne( const E & e ) const {
1388 if constexpr( calls_prepare< Ai< I > , Oi< I > , E > ) {
1389 if( ! wants< I , E >() )
1390 return( true );
1391 return( Ai< I >::prepare( std::get< I >( f_o ) , e ) );
1392 }
1393 else
1394 return( true );
1395 }
1396
1397 template< std::size_t I , class S >
1398 [[nodiscard]] bool auditOne( const S & s ) const {
1399 if constexpr( calls_audit< Ai< I > , Oi< I > , S > )
1400 return( Ai< I >::audit( std::get< I >( f_o ) , s ) );
1401 else
1402 return( true );
1403 }
1404
1405 template< std::size_t I , class Var >
1406 void groupOne( std::span< const Var > C , std::uint64_t kinds ,
1407 const Group & g ,
1408 std::vector< Var > & tmp ) {
1409 const std::uint64_t m = wantedBy< I >();
1410 if( ( m & kinds ) == 0 )
1411 return;
1412 auto & o = std::get< I >( f_o );
1413 f_counts.group( I );
1414 if constexpr( calls_policy< Ai< I > , Oi< I > > )
1415 if( Ai< I >::early( o , eventsFor( C , m , ( kinds & ~m ) == 0 ) ) ) {
1416 rebuiltOne< I >( g ); // Rebuilt instead of the events
1417 return;
1418 }
1419 if constexpr( calls_group< Ai< I > , Oi< I > > )
1420 Ai< I >::begin( o , g );
1421 bool leave = false;
1422 if constexpr( calls_span< Ai< I > , Oi< I > , Var > ) {
1423 if( ( kinds & ~m ) == 0 )
1424 Ai< I >::many( o , C );
1425 else {
1426 tmp.clear();
1427 for( const auto & e : C )
1428 if( ( m >> e.index() ) & 1u )
1429 tmp.push_back( e );
1430 Ai< I >::many( o , std::span< const Var >( tmp ) );
1431 }
1432 }
1433 else {
1434 std::size_t i = 0;
1435 while( i < C.size() ) {
1436 const std::size_t k = C[ i ].index();
1437 std::size_t j = i + 1;
1438 while( ( j < C.size() ) && ( C[ j ].index() == k ) )
1439 ++j;
1440 if( ( m >> k ) & 1u )
1441 visitKind< L >( k , [ & ]< class E >() {
1442 if constexpr( calls< Ai< I > , Oi< I > , E > )
1443 leave =
1444 giveRun< Ai< I > , Oi< I > , E >( o ,
1445 C.subspan( i , j - i ) ) || leave;
1446 } );
1447 i = j;
1448 }
1449 }
1450 if constexpr( calls_group< Ai< I > , Oi< I > > )
1451 Ai< I >::end( o );
1452 if constexpr( may_leave )
1453 if( leave )
1454 f_off.set( I );
1455 }
1456
1457 template< std::size_t I >
1458 ADS_COLD_PATH void rebuiltOne( const Group & g ) {
1459 auto & o = std::get< I >( f_o );
1460 f_counts.rebuild( I );
1461 if constexpr( calls_group< Ai< I > , Oi< I > > )
1462 Ai< I >::begin( o , g );
1463 Ai< I >::rebuilt( o );
1464 if constexpr( calls_group< Ai< I > , Oi< I > > )
1465 Ai< I >::end( o );
1466 }
1467
1468 template< std::size_t... I >
1469 static constexpr void checkOrder( std::index_sequence< I... > ) {
1470 ( checkDeps< I >() , ... );
1471 }
1472
1473 template< std::size_t I >
1474 static constexpr void checkDeps( void ) {
1475 if constexpr( requires { typename Oi< I >::depends_on; } )
1476 static_assert( precede< I >( typename Oi< I >::depends_on() ) ,
1477 "ADS: a static observer precedes one it depends on" );
1478 }
1479
1480 template< std::size_t I , class... D >
1481 static constexpr bool precede( list< D... > ) {
1482 return( ( before< I , D >() && ... ) );
1483 }
1484
1485 template< std::size_t I , class D >
1486 static constexpr bool before( void ) {
1487 return( []< std::size_t... J >( std::index_sequence< J... > ) {
1488 return( ( std::is_same_v< Oi< J > , D > || ... ) );
1489 }( std::make_index_sequence< I >() ) );
1490 }
1491
1492 Objects f_o;
1493 ADS_NO_UNIQUE_ADDRESS OffBits< may_leave > f_off;
1494 ADS_NO_UNIQUE_ADDRESS StaticCounts< N > f_counts;
1495
1496 }; // end( class StaticSet )
1497
1499template< class L >
1500struct NoSlots
1501{
1502 static constexpr bool slots = false;
1503 template< class E >
1504 static constexpr bool listened = false;
1505 template< class E >
1506 [[nodiscard]] constexpr bool live( void ) const {
1507 return( false );
1508 }
1509 [[nodiscard]] constexpr std::uint64_t wanted( void ) const { return( 0 ); }
1510 template< class E , bool T >
1511 constexpr void deliver( const E & , Trail & ) { }
1512 template< class E , class Inv >
1513 constexpr void undo( const Inv & , const Trail & ) noexcept { }
1514 template< class E >
1515 [[nodiscard]] constexpr bool prepare( const E & ) const {
1516 return( true );
1517 }
1518 template< class S >
1519 [[nodiscard]] constexpr bool audit( const S & ) const {
1520 return( true );
1521 }
1522 template< class Var >
1523 constexpr void deliverGroup( std::span< const Var > , std::uint64_t ,
1524 const Group & , std::vector< Var > & ) { }
1525 };
1526
1530template< class L , class Obs >
1531class Slots
1532{
1533
1534 static constexpr std::size_t K = L::size;
1535 using Var = variant_t< L >;
1536
1538 struct Slot
1539 {
1540 void * o = nullptr;
1541 std::uint64_t mask = 0;
1543 std::array< Keep ( * )( void * , const void * ) , K > one{};
1545 std::array< bool ( * )( const void * , const void * ) , K > prep{};
1547 std::array< bool ( * )( void * , std::span< const Var > ) , K > run{};
1549 void ( *all )( void * , std::span< const Var > ) = nullptr;
1551 void ( *begin )( void * , const Group & ) = nullptr;
1552 void ( *end )( void * ) = nullptr;
1554 bool ( *audit )( const void * , const void * ) = nullptr;
1556 bool ( *early )( void * , std::size_t ) = nullptr;
1557 void ( *rebuilt )( void * ) = nullptr;
1558 Counts counts;
1559 };
1560
1561 public:
1562 static constexpr bool slots = true;
1563
1564 template< class E >
1565 static constexpr bool listened = contains_v< E , L >;
1566
1567 template< class E >
1568 [[nodiscard]] bool live( void ) const {
1569 return( ( f_mask >> index_v< E , L > )&1u );
1570 }
1571
1572 [[nodiscard]] std::uint64_t wanted( void ) const { return( f_mask ); }
1573
1574 template< class A , class D >
1575 int attach( D & o );
1576
1577 void detach( int id );
1578
1579 [[nodiscard]] bool attached( int id ) const {
1580 return( ( id >= 0 ) && ( id < int( f_s.size() ) ) &&
1581 ( f_s[ std::size_t( id ) ].o != nullptr ) );
1582 }
1583
1584 template< class E , bool T >
1585 void deliver( const E & e , Trail & t );
1586
1587 template< class E , class Inv >
1588 void undo( const Inv & inv , const Trail & t ) noexcept;
1589
1590 template< class E >
1591 [[nodiscard]] bool prepare( const E & e ) const;
1592
1593 template< class S >
1594 [[nodiscard]] bool audit( const S & s ) const;
1595
1596 void deliverGroup( std::span< const Var > C , std::uint64_t kinds ,
1597 const Group & g , std::vector< Var > & tmp );
1598
1599 [[nodiscard]] Counts counts( int id ) const {
1600 return( f_s[ std::size_t( id ) ].counts );
1601 }
1602
1605 bool f_busy = false;
1606
1607 private:
1609 template< class A , class D , std::size_t I >
1610 static void fill( Slot & s );
1611
1613 void remask( void );
1614
1615 std::vector< Slot > f_s;
1616 std::uint64_t f_mask = 0;
1617
1618 }; // end( class Slots )
1619
1620/*--------------------------------------------------------------------------*/
1621/*------------------------------- THE SUBJECTS -----------------------------*/
1622/*--------------------------------------------------------------------------*/
1623
1625template< class L >
1626struct NoSubject
1627{
1628 static constexpr bool none = true;
1629 static constexpr bool dynamic = false;
1630 using modifications = L;
1631 template< class E >
1632 static constexpr bool listened = false;
1633 constexpr NoSubject( void ) = default;
1634 template< class E >
1635 [[nodiscard]] constexpr bool live( void ) const {
1636 return( false );
1637 }
1638 template< class E >
1639 constexpr void emit( const E & ) { }
1640 template< class E , class U >
1641 constexpr void emit( const E & , U && ) { }
1642 template< class E >
1643 constexpr void prepare( const E & ) const { }
1644 template< class S >
1645 constexpr void audit( const S & ) const { }
1646 constexpr void open( void ) { }
1647 template< class S >
1648 constexpr void close( const S & ) { }
1649 [[nodiscard]] constexpr std::size_t buffered( void ) const { return( 0 ); }
1650 constexpr void discard( std::size_t ) { }
1651 constexpr void spoil( void ) { }
1652 constexpr void mute( bool ) { }
1653 template< class S >
1654 constexpr void unmute( const S & ) { }
1655 [[nodiscard]] constexpr int depth( void ) const { return( 0 ); }
1656 [[nodiscard]] constexpr bool muted( void ) const { return( false ); }
1657 [[nodiscard]] constexpr std::size_t built( void ) const { return( 0 ); }
1658 [[nodiscard]] constexpr std::uint64_t mask( void ) const { return( 0 ); }
1659 template< class E >
1660 [[nodiscard]] constexpr std::uint64_t revision( void ) const {
1661 return( 0 );
1662 }
1663 [[nodiscard]] constexpr std::uint64_t version( void ) const { return( 0 ); }
1664 };
1665
1669template< class L , class Obs , class St , class Dy >
1670class Subject
1671{
1672
1673 static constexpr std::size_t K = L::size;
1674 static_assert( K <= 64 , "ADS: at most 64 kinds of event" );
1675
1676 public:
1677 static constexpr bool none = false;
1678 static constexpr bool dynamic = Dy::slots;
1679 using modifications = L;
1680 using Event = variant_t< L >;
1681
1683 template< class E >
1684 static constexpr bool listened =
1685 St::template listened< E > || Dy::template listened< E >;
1686
1688 template< class... A >
1689 explicit Subject( A &... a ) : f_st( a... ) { }
1690
1692 Subject( const Subject & ) = delete;
1694 Subject & operator=( const Subject & ) = delete;
1695
1697 template< class E >
1698 [[nodiscard]] bool live( void ) const {
1699 return( f_st.template live< E >() || f_dy.template live< E >() );
1700 }
1701
1703 template< class E >
1704 void emit( const E & e ) {
1705 static_assert( contains_v< E , L > ,
1706 "ADS: an event that the structure does not declare" );
1707 ++f_built;
1708 if( ( f_depth | f_quiet ) != 0 ) [[unlikely]] {
1709 defer( e );
1710 return;
1711 }
1712 if( ! live< E >() )
1713 return;
1714 ++f_rev[ index_v< E , L > ];
1715 Trail t;
1716 if constexpr( dynamic ) {
1717 f_st.template deliver< E , false >( e , t );
1718 f_dy.f_busy = true;
1719 struct Done
1720 {
1721 bool & b;
1722 ~Done() { b = false; }
1723 } done{ f_dy.f_busy };
1724 f_dy.template deliver< E , false >( e , t );
1725 }
1726 else
1727 f_st.template deliver< E , false >( e , t );
1728 }
1729
1734 template< class E , class U >
1735 void emit( const E & e , U && undo );
1736
1739 template< class E >
1740 void prepare( const E & e ) const {
1741 if constexpr( listened< E > )
1742 if( ! ( f_st.prepare( e ) && f_dy.prepare( e ) ) )
1743 throw( Refused( "ADS: a change refused by an observer" ) );
1744 }
1745
1748 template< class S >
1749 void audit( [[maybe_unused]] const S & s ) const {
1750 if constexpr( ADS_CONTRACTS >= 3 ) {
1751 if( ( f_depth | f_quiet ) != 0 )
1752 return;
1753 const bool ok = f_st.audit( s ) && f_dy.audit( s );
1754 ADS_AUDIT( ok );
1755 }
1756 }
1757
1758/*-------------------------------- BATCHES ---------------------------------*/
1759
1761 void open( void ) { ++f_depth; }
1762
1765 template< class S >
1766 void close( const S & s );
1767
1769 [[nodiscard]] std::size_t buffered( void ) const { return( f_buf.size() ); }
1770
1772 [[nodiscard]] std::span< const Event > collected( void ) const {
1773 return( std::span< const Event >( f_buf ) );
1774 }
1775
1778 void discard( std::size_t m );
1779
1781 void spoil( void ) {
1782 f_buf.clear();
1783 f_keep.clear();
1784 if constexpr( contains_v< Rebuilt , L > )
1785 f_buf.emplace_back( Rebuilt{} );
1786 }
1787
1789 [[nodiscard]] int depth( void ) const { return( f_depth ); }
1790
1791/*--------------------------------- MUTES ----------------------------------*/
1792
1794 void mute( bool rebuild );
1795
1798 template< class S >
1799 void unmute( const S & s );
1800
1802 [[nodiscard]] bool muted( void ) const { return( f_quiet > 0 ); }
1803
1804/*------------------------------- THE COUNTS -------------------------------*/
1805
1807 [[nodiscard]] std::size_t built( void ) const { return( f_built ); }
1808
1810 [[nodiscard]] std::uint64_t mask( void ) const {
1811 return( f_st.wanted() | f_dy.wanted() );
1812 }
1813
1816 template< class E >
1817 [[nodiscard]] std::uint64_t revision( void ) const {
1818 return( f_rev[ index_v< E , L > ] );
1819 }
1820
1822 [[nodiscard]] std::uint64_t revision( std::size_t k ) const {
1823 return( f_rev[ k ] );
1824 }
1825
1827 [[nodiscard]] std::uint64_t version( void ) const {
1828 std::uint64_t v = 0;
1829 for( const auto r : f_rev )
1830 v += r;
1831 return( v );
1832 }
1833
1836 [[nodiscard]] Counts staticCounts( std::size_t i ) const
1837 requires( ! std::is_same_v< St , NoStatic< L > > )
1838 {
1839 return( f_st.counts( i ) );
1840 }
1841
1842/*--------------------------- THE DYNAMIC OBSERVERS ------------------------*/
1843
1846 template< class D >
1847 int attach( D & o )
1848 requires dynamic
1849 {
1850 ADS_PRE( ( f_depth == 0 ) && ! f_dy.f_busy );
1851 return( f_dy.template attach< Direct >( o ) );
1852 }
1853
1855 template< class A , class D >
1856 int attachVia( D & o )
1857 requires dynamic
1858 {
1859 ADS_PRE( ( f_depth == 0 ) && ! f_dy.f_busy );
1860 return( f_dy.template attach< A >( o ) );
1861 }
1862
1865 void detach( int id )
1866 requires dynamic
1867 {
1868 ADS_PRE( ( f_depth == 0 ) && ! f_dy.f_busy && f_dy.attached( id ) );
1869 f_dy.detach( id );
1870 }
1871
1873 [[nodiscard]] bool attached( int id ) const
1874 requires dynamic
1875 {
1876 return( f_dy.attached( id ) );
1877 }
1878
1880 [[nodiscard]] Counts slotCounts( int id ) const
1881 requires dynamic
1882 {
1883 return( f_dy.counts( id ) );
1884 }
1885
1886/*--------------------------------------------------------------------------*/
1887 private:
1889 template< class E >
1890 ADS_COLD_PATH void defer( const E & e );
1891
1893 void flush( void );
1894
1896 void rebuilt( void );
1897
1898 ADS_NO_UNIQUE_ADDRESS St f_st;
1899 ADS_NO_UNIQUE_ADDRESS Dy f_dy;
1900 int f_depth = 0;
1901 int f_quiet = 0;
1902 bool f_rebuild = false;
1903 std::size_t f_built = 0;
1904 std::vector< Event > f_buf;
1906 std::vector< std::shared_ptr< const void > > f_keep;
1907 std::array< std::uint64_t , K > f_rev{};
1908
1909 }; // end( class Subject )
1910
1913template< class L , class M >
1914struct events_of
1915{
1916 static_assert( std::is_void_v< L > || std::is_same_v< L , M > ,
1917 "ADS: Dynamic< L > on a structure whose events are not L" );
1918 using type = M;
1919 };
1920
1922template< class S >
1923struct checkpoint_of
1924{
1925 using type = int;
1926 };
1927
1928template< class S >
1929 requires ADS::undoable< S >
1930struct checkpoint_of< S >
1931{
1932 using type = decltype( std::declval< S & >().checkpoint() );
1933 };
1934
1937template< class S >
1938decltype( auto ) observed( S & s )
1939{
1940 if constexpr( requires { s.observed(); } )
1941 return( s.observed() );
1942 else
1943 return( std::as_const( s ) );
1944 }
1945
1946} // end( namespace detail )
1948
1949} // end( namespace mod )
1950
1951/*--------------------------------------------------------------------------*/
1952/*------------------------------ THE POLICIES ------------------------------*/
1953/*--------------------------------------------------------------------------*/
1954
1958{
1960 template< class L , class Obs = void >
1961 using bind = mod::detail::NoSubject< L >;
1962 };
1963
1966template< class... O >
1968{
1970 template< class L , class Obs = void >
1971 using bind =
1972 mod::detail::Subject< L , Obs , mod::detail::StaticSet< L , Obs , O... > ,
1973 mod::detail::NoSlots< L > >;
1974 };
1975
1978template< class L = void >
1980{
1982 template< class M , class Obs = void >
1983 using bind =
1984 mod::detail::Subject< typename mod::detail::events_of< L , M >::type , Obs ,
1985 mod::detail::NoStatic< M > ,
1986 mod::detail::Slots< M , Obs > >;
1987 };
1988
1990template< class St , class Dy = Dynamic<> >
1991struct Both;
1992
1994template< class... O , class L >
1995struct Both< Static< O... > , Dynamic< L > >
1996{
1998 template< class M , class Obs = void >
1999 using bind =
2000 mod::detail::Subject< typename mod::detail::events_of< L , M >::type , Obs ,
2001 mod::detail::StaticSet< M , Obs , O... > ,
2002 mod::detail::Slots< M , Obs > >;
2003 };
2004
2005/*--------------------------------------------------------------------------*/
2006/*----------------------------- BATCHES AND MUTES --------------------------*/
2007/*--------------------------------------------------------------------------*/
2008
2010template< class S >
2012{
2013
2014 using T = typename mod::detail::checkpoint_of< S >::type;
2015
2016 public:
2018 explicit Batch( S & s )
2019 : f_s( &s ) , f_ex( std::uncaught_exceptions() ) ,
2020 f_mark( s.subject().buffered() ) {
2021 if constexpr( undoable< S > )
2022 f_t = s.checkpoint();
2023 s.subject().open();
2024 }
2025
2027 Batch( Batch && b ) noexcept
2028 : f_s( std::exchange( b.f_s , nullptr ) ) , f_ex( b.f_ex ) ,
2029 f_mark( b.f_mark ) , f_t( b.f_t ) { }
2030
2032 Batch( const Batch & ) = delete;
2034 Batch & operator=( const Batch & ) = delete;
2036 Batch & operator=( Batch && ) = delete;
2037
2042 ~Batch() noexcept( false ) {
2043 if( ! f_s )
2044 return;
2045 if( std::uncaught_exceptions() > f_ex )
2046 abandon();
2047 else
2048 close();
2049 }
2050
2076 void close( void ) {
2077 if( f_s ) {
2078 S * s = std::exchange( f_s , nullptr );
2079 s->subject().close( mod::detail::observed( *s ) );
2080 }
2081 }
2082
2087 void rollback( void )
2088 requires undoable< S >
2089 {
2090 if( f_s ) {
2091 ADS_PRE( revertible( *f_s ) );
2092 undo( *std::exchange( f_s , nullptr ) );
2093 }
2094 }
2095
2096 private:
2099 bool revertible( const S & s ) const {
2100 if constexpr( requires { s.revertible( f_t ); } )
2101 return( s.revertible( f_t ) );
2102 else
2103 return( true );
2104 }
2105
2106 void abandon( void ) noexcept {
2107 S * s = std::exchange( f_s , nullptr );
2108 using L =
2109 typename std::remove_cvref_t< decltype( s->subject() ) >::modifications;
2110 if constexpr( undoable< S > )
2111 if( revertible( *s ) ) {
2112 undo( *s );
2113 return;
2114 }
2116 s->subject().spoil();
2117 try {
2118 s->subject().close( mod::detail::observed( *s ) );
2119 }
2120 catch( ... ) {
2121 } // the first exception wins
2122 }
2123
2124 void undo( S & s ) noexcept {
2125 auto & sub = s.subject();
2126 sub.mute( false ); // the undo tells nobody
2127 try {
2128 s.rollback( f_t );
2129 }
2130 catch( ... ) {
2131 }
2132 try {
2133 sub.unmute( mod::detail::observed( s ) ); // in the batch: silent
2134 }
2135 catch( ... ) {
2136 }
2137 sub.discard( f_mark );
2138 }
2139
2140 S * f_s;
2141 int f_ex;
2142 std::size_t f_mark;
2143 T f_t{};
2144
2145 }; // end( class Batch )
2146
2149template< class S >
2150[[nodiscard]] Batch< S > batch( S & s )
2151{
2152 return( Batch< S >( s ) );
2153 }
2154
2156template< class S >
2158{
2159 public:
2161 Quiet( S & s , bool rebuild ) : f_s( &s ) { s.subject().mute( rebuild ); }
2162
2164 Quiet( const Quiet & ) = delete;
2166 Quiet & operator=( const Quiet & ) = delete;
2167
2169 ~Quiet() noexcept( false ) { end(); }
2170
2172 void end( void ) {
2173 if( f_s ) {
2174 S * s = std::exchange( f_s , nullptr );
2175 s->subject().unmute( mod::detail::observed( *s ) );
2176 }
2177 }
2178
2179 private:
2180 S * f_s;
2181
2182 }; // end( class Quiet )
2183
2188template< class S >
2189[[nodiscard]] Quiet< S > quiet( S & s )
2190{
2191 using L =
2192 typename std::remove_cvref_t< decltype( s.subject() ) >::modifications;
2194 "ADS: quiet( s ) sends Rebuilt, which the structure does not "
2195 "emit; quiet( s , no_rebuild ) promises that nobody needs to "
2196 "know" );
2197 return( Quiet< S >( s , true ) );
2198 }
2199
2202template< class S >
2203[[nodiscard]] Quiet< S > quiet( S & s , no_rebuild_t )
2204{
2205 return( Quiet< S >( s , false ) );
2206 }
2207
2208/*--------------------------------------------------------------------------*/
2209/*------------------------------ CLASS UndoLog -----------------------------*/
2210/*--------------------------------------------------------------------------*/
2211
2228template< class L >
2230{
2231 public:
2233
2235 template< class E >
2237 void on( const E & e ) noexcept( mod::must_not_throw< E > ) {
2238 if( f_replay )
2239 return;
2240 if constexpr( mod::must_not_throw< E > ) {
2241 try {
2242 f_log.push_back( Event( e ) );
2243 }
2244 catch( ... ) { // a hole: no rollback before it
2245 forget();
2246 ++f_base;
2247 f_floor = f_base;
2248 }
2249 }
2250 else
2251 f_log.push_back( Event( e ) );
2252 }
2253
2256 template< class E >
2258 void on( const E & ) noexcept {
2259 if( ! f_replay )
2260 forget();
2261 }
2262
2264 void on( const mod::Cleared & ) noexcept { forget(); }
2266 void on( const mod::Rebuilt & ) noexcept { forget(); }
2268 template< class A >
2269 void on( const mod::Replaced< A > & ) noexcept {
2270 forget();
2271 }
2272
2274 [[nodiscard]] std::size_t checkpoint( void ) const {
2275 return( f_base + f_log.size() );
2276 }
2277
2279 [[nodiscard]] std::size_t size( void ) const { return( f_log.size() ); }
2280
2286 template< class S >
2287 void rollback( S & s , std::size_t t );
2288
2289 private:
2290 void forget( void ) noexcept {
2291 f_base += f_log.size();
2292 f_log.clear();
2293 f_floor = f_base;
2294 }
2295
2296 std::vector< Event > f_log;
2297 std::size_t f_base = 0;
2298 std::size_t f_floor = 0;
2299 bool f_replay = false;
2300
2301 }; // end( class UndoLog )
2302
2303/*--------------------------------------------------------------------------*/
2304/*------------------------------ CLASS Shadow ------------------------------*/
2305/*--------------------------------------------------------------------------*/
2306
2311template< class Inc , class Scratch , class Eq = std::equal_to<> >
2313{
2314
2315 template< class E >
2316 static constexpr bool forwarded =
2318
2319 template< class E >
2320 static constexpr bool nothrow_for =
2322 noexcept( std::declval< Inc & >().on( std::declval< const E & >() ) ) ) &&
2323 ( ! mod::observes< Scratch ,
2324 E > || noexcept( std::declval< Scratch & >().on(
2325 std::declval< const E & >() ) ) );
2326
2327 public:
2329 struct Counts
2330 {
2331 std::uint64_t events = 0;
2332 std::uint64_t queries = 0;
2333 std::uint64_t mismatches = 0;
2334 };
2335
2337 Shadow( Inc & i , Scratch & s , Eq eq = Eq() )
2338 : f_inc( i ) , f_scr( s ) , f_eq( std::move( eq ) ) { }
2339
2341 template< class E >
2342 requires( forwarded< E > )
2343 void on( const E & e ) noexcept( nothrow_for< E > ) {
2344 ++f_counts.events;
2345 if constexpr( mod::observes< Inc , E > )
2346 f_inc.on( e );
2347 if constexpr( mod::observes< Scratch , E > )
2348 f_scr.on( e );
2349 }
2350
2352 void group_begin( const mod::Group & g ) {
2353 begin( f_inc , g );
2354 begin( f_scr , g );
2355 }
2356
2358 void group_end( void ) {
2359 if constexpr( mod::groups< Inc > )
2360 f_inc.group_end();
2361 if constexpr( mod::groups< Scratch > )
2362 f_scr.group_end();
2363 }
2364
2366 void flush( void ) {
2367 if constexpr( mod::lazy< Inc > )
2368 f_inc.flush();
2369 if constexpr( mod::lazy< Scratch > )
2370 f_scr.flush();
2371 }
2372
2376 template< class F >
2378 auto query( F && f ) {
2379 auto a = f( f_inc );
2380 const bool same = agreeOn( a , f( f_scr ) );
2381 ADS_AUDIT( same );
2382 return( a );
2383 }
2384
2387 template< meetable_query T >
2388 [[nodiscard]] static constexpr auto query( T ) noexcept {
2390 }
2391
2393 template< class F >
2394 [[nodiscard]] bool agree( F && f ) {
2395 return( agreeOn( f( f_inc ) , f( f_scr ) ) );
2396 }
2397
2399 template< class S >
2400 [[nodiscard]] bool audit( const S & s ) const {
2401 bool ok = true;
2402 if constexpr( mod::auditable< Inc , S > )
2403 ok = ok && bool( f_inc.audit( s ) );
2404 if constexpr( mod::auditable< Scratch , S > )
2405 ok = ok && bool( f_scr.audit( s ) );
2406 return( ok );
2407 }
2408
2410 [[nodiscard]] const Counts & counts( void ) const { return( f_counts ); }
2411
2413 [[nodiscard]] Inc & incremental( void ) { return( f_inc ); }
2415 [[nodiscard]] Scratch & scratch( void ) { return( f_scr ); }
2416
2417 private:
2418 template< class O >
2419 static void begin( O & o , const mod::Group & g ) {
2420 if constexpr( mod::groups< O > )
2421 mod::Direct::begin( o , g );
2422 }
2423
2424 template< class A , class B >
2425 bool agreeOn( const A & a , const B & b ) {
2426 ++f_counts.queries;
2427 const bool same = f_eq( a , b );
2428 if( ! same )
2429 ++f_counts.mismatches;
2430 return( same );
2431 }
2432
2433 Inc & f_inc;
2434 Scratch & f_scr;
2435 Eq f_eq;
2436 Counts f_counts;
2437
2438 }; // end( class Shadow )
2439
2440/*--------------------------------------------------------------------------*/
2441
2442} // end( namespace ADS )
2443
2444/*--------------------------------------------------------------------------*/
2445/*-------------------------- IMPLEMENTATION --------------------------------*/
2446/*--------------------------------------------------------------------------*/
2447
2448#include "ADS/impl/Modification.tpp"
2449
2450/*--------------------------------------------------------------------------*/
2451
2452#endif /* Modification.h included */
2453
2454/*--------------------------------------------------------------------------*/
2455/*------------------------ End File Modification.h -------------------------*/
2456/*--------------------------------------------------------------------------*/
The capabilities of the structures, beyond the book: what an algorithm may ask of its argument to cho...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
a batch of RAII on the structure [see batch()]
Definition Modification.h:2012
void close(void)
closes the batch: the outermost one sends the events, coalesced; idempotent
Definition Modification.h:2076
Batch & operator=(const Batch &)=delete
not assigned
Batch & operator=(Batch &&)=delete
not assigned
void rollback(void)
brings the structure back to where it was when the batch opened, and drops its events: the observers ...
Definition Modification.h:2087
Batch(Batch &&b) noexcept
the batch of , which no longer has it
Definition Modification.h:2027
Batch(S &s)
opens a batch on
Definition Modification.h:2018
~Batch() noexcept(false)
closes the batch, if still open; if its scope exits by an exception, the structure goes back to the c...
Definition Modification.h:2042
Batch(const Batch &)=delete
not copied
void compensate(bool on)
compensated or not from now on
Definition Modification.h:342
bool compensated(void) const
whether the sum is compensated
Definition Modification.h:345
void sub(const T &x)
subtracts
Definition Modification.h:318
T value(void) const
the sum
Definition Modification.h:328
void add(const T &x)
adds
Definition Modification.h:304
void reset(const T &x=T())
the sum set to , with no compensation
Definition Modification.h:336
NeumaierSum(bool compensated=false)
the sum , compensated if compensated
Definition Modification.h:301
a mute of RAII on the structure [see quiet()]
Definition Modification.h:2158
Quiet & operator=(const Quiet &)=delete
not assigned
~Quiet() noexcept(false)
ends the mute, if not yet ended
Definition Modification.h:2169
void end(void)
ends the mute: Rebuilt, or the audit; idempotent
Definition Modification.h:2172
Quiet(S &s, bool rebuild)
suspends the events of
Definition Modification.h:2161
Quiet(const Quiet &)=delete
not copied
a change refused by the prepare() of an observer, before anything changed
Definition Modification.h:161
auto query(F &&f)
the answer of the incremental observer to , compared with that of the other one (a violation at the l...
Definition Modification.h:2378
bool audit(const S &s) const
the audits of both, where they have them
Definition Modification.h:2400
const Counts & counts(void) const
the counts
Definition Modification.h:2410
Scratch & scratch(void)
the observer from scratch
Definition Modification.h:2415
void group_end(void)
the end of a group for both
Definition Modification.h:2358
bool agree(F &&f)
whether the two observers give the same answer to
Definition Modification.h:2394
void group_begin(const mod::Group &g)
the group hooks of both, where they have them
Definition Modification.h:2352
Shadow(Inc &i, Scratch &s, Eq eq=Eq())
the shadow of by , compared by
Definition Modification.h:2337
void on(const E &e) noexcept(nothrow_for< E >)
forwards to both, to those that want it
Definition Modification.h:2343
Inc & incremental(void)
the incremental observer
Definition Modification.h:2413
void flush(void)
flush() of both, where they have it
Definition Modification.h:2366
static constexpr auto query(T) noexcept
the answer of the composition of the two observers to the forwarded query of the tag T [see Capabilit...
Definition Modification.h:2388
an observer that records the invertible events of L, which carry the old values, and brings a structu...
Definition Modification.h:2230
std::size_t size(void) const
the events recorded since the oldest checkpoint still valid
Definition Modification.h:2279
void on(const E &) noexcept
forgets the events recorded, which can no longer be undone: an event with no inverse (the deletion of...
Definition Modification.h:2258
void on(const mod::Cleared &) noexcept
forgets the events recorded, which can no longer be undone
Definition Modification.h:2264
void on(const mod::Replaced< A > &) noexcept
forgets the events recorded
Definition Modification.h:2269
void rollback(S &s, std::size_t t)
back to the checkpoint , by s.apply() of the inverses, in one batch, so that the other observers get ...
void on(const E &e) noexcept(mod::must_not_throw< E >)
< an event recorded
Definition Modification.h:2237
mod::variant_t< L > Event
Definition Modification.h:2232
void on(const mod::Rebuilt &) noexcept
forgets the events recorded
Definition Modification.h:2266
std::size_t checkpoint(void) const
the checkpoint of now
Definition Modification.h:2274
a monoid with the inverse G::inverse( a ), i.e., combine( inverse( a) , a ) and combine( a ,...
Definition Algebra.h:130
a recompute policy: whether to compute from scratch before a repair, whether to abandon a repair whil...
Definition Modification.h:223
a tag of a forwarded query
Definition Capabilities.h:249
an observer that can check itself against the structure
Definition Modification.h:825
an observer that reports counts of its own
Definition Modification.h:837
an observer told of the start and of the end of each batch
Definition Modification.h:806
an event that has an inverse
Definition Modification.h:765
an observer that queues the events and works at its next query
Definition Modification.h:832
an observer with a filter of the kinds at run time: the bit of mask() for the -th event of the struc...
Definition Modification.h:854
an observer of at least one of the events of the list L
Definition Modification.h:877
an observer of the spans of E, an event or the variant of the events
Definition Modification.h:800
an observer of the event E
Definition Modification.h:795
an observer that may refuse the change E before it is made
Definition Modification.h:818
an observer with a recompute policy [see ReoptPolicy], and the statistics of a query after more even...
Definition Modification.h:845
checkpoint() and rollback( t ) back to a checkpoint (a speculative change, a batch that exits by an e...
Definition Capabilities.h:688
constexpr auto query_meet_v
the answer of the composition of A and B to the query T
Definition Capabilities.h:347
@ none
Definition Capabilities.h:553
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
#define ADS_AUDIT(cond)
a precondition or a postcondition dearer than the operation, checked from level 3
Definition Contract.h:131
#define ADS_CONTRACTS
the level of the contracts checked: 0 none, 1 preconditions, 2 postconditions, 3 invariants and audit...
Definition Contract.h:71
constexpr Erased< H, K, V > inverse(const Inserted< H, K, V > &e)
the erasure that undoes an insertion
Definition Modification.h:722
Batch< S > batch(S &s)
a batch on the structure , open while it lives: its events are collected, and the outermost batch sen...
Definition Modification.h:2150
Quiet< S > quiet(S &s)
a mute on the structure : no event while it lives, Rebuilt to every observer at its end (inside a bat...
Definition Modification.h:2189
Changed< Key, H, K > KeyChanged
the key of an item changed
Definition Modification.h:627
constexpr no_rebuild_t no_rebuild
the promise of quiet( s , no_rebuild )
Definition Modification.h:173
constexpr unsigned effects_of
the effects of the event E, all of them if it declares none
Definition Modification.h:418
Changed< Value, H, V > Assigned
the value of an item changed
Definition Modification.h:623
Role
the role of an event in the coalescing of a batch
Definition Modification.h:372
constexpr bool contains_v
whether E is in the list L
Definition Modification.h:523
constexpr Role role_of
the role of the event E, Role::Other if it declares none
Definition Modification.h:414
typename detail::variant_of< L >::type variant_t
the variant of the events of the list L, the type of a buffer
Definition Modification.h:527
Keep
what an on() that returns it asks: to stay, or to be detached after the event, with no exception
Definition Modification.h:156
constexpr std::size_t index_v
the position of E in the list L, its size if absent
Definition Modification.h:519
constexpr bool must_not_throw
whether on() of the event E must not throw: the erasures, the clearing, the rebuilding and the replac...
Definition Modification.h:424
@ Replace
Definition Modification.h:381
@ BulkInsert
Definition Modification.h:378
@ Rebuild
Definition Modification.h:383
@ Other
Definition Modification.h:384
@ Shift
Definition Modification.h:380
@ BulkErase
Definition Modification.h:379
@ Insert
Definition Modification.h:373
@ Relocate
Definition Modification.h:376
@ Clear
Definition Modification.h:382
@ Erase
Definition Modification.h:374
@ Change
Definition Modification.h:375
@ Permute
Definition Modification.h:377
@ Yes
Definition Modification.h:156
@ Detach
Definition Modification.h:156
#define ADS_COLD_PATH
a function of a rare path: never inlined, laid out away from the hot code
Definition Portable.h:107
#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
bool check(const Grid &S, std::size_t x, std::size_t y, int c)
whether can be written in the square of , i.e., it is not on its row, its column or its block
GrB_Type type(void)
the type of GraphBLAS of the numbers T: GrB_BOOL, the integers of 8 to 64 bits with or without sign,...
Definition GraphBLAS.h:128
how two changes of one attribute of one item compose in a batch: the last value (last),...
Definition Modification.h:452
Definition ADT.h:96
mod::detail::Subject< typename mod::detail::events_of< L, M >::type, Obs, mod::detail::StaticSet< M, Obs, O... >, mod::detail::Slots< M, Obs > > bind
the subject of a structure of the events M
Definition Modification.h:1999
the static observers of St, then those attached at run time
Definition Modification.h:1991
observers attached at run time, the events those of the structure (or the list L, which must be them)
Definition Modification.h:1980
mod::detail::Subject< typename mod::detail::events_of< L, M >::type, Obs, mod::detail::NoStatic< M >, mod::detail::Slots< M, Obs > > bind
the subject of a structure of the events M
Definition Modification.h:1983
nobody listens: the subject is empty and every test is false at compile time, so that the structure c...
Definition Modification.h:1958
mod::detail::NoSubject< L > bind
the subject of a structure of the events L
Definition Modification.h:1961
the default recompute policy: from scratch when the net events exceed times the size,...
Definition Modification.h:239
bool scratch(const ReoptStats &s) const
whether to compute from scratch: , with and the events and the size of , and at the close of a batc...
Definition Modification.h:252
double alpha
the ratio of the work to a scratch
Definition Modification.h:241
bool refresh(std::size_t c, std::size_t n) const
whether the values that are not exact are to be summed again after changes of an instance of size :
Definition Modification.h:273
bool early
whether scratch() acts at the close of
Definition Modification.h:243
bool compensated
whether the sums are compensated
Definition Modification.h:247
void record(int, double) const
nothing: this policy keeps no history
Definition Modification.h:268
double rho
the ratio of the events to the size
Definition Modification.h:240
double period
the changes between two sums, in units
Definition Modification.h:245
bool abandon(const ReoptStats &s, double w) const
whether to abandon the repair after the work : times the work of a scratch, or more than reinsertio...
Definition Modification.h:262
int beta
the reinsertions of one element, 0 off
Definition Modification.h:242
what a recompute policy reads: the work is a count of elementary operations of the observer (nodes,...
Definition Modification.h:208
double work
the work of the repair so far
Definition Modification.h:211
std::size_t reinsertions
the extractions of one element beyond
Definition Modification.h:213
double lastScratch
the work of a computation from scratch
Definition Modification.h:212
bool closing
whether asked at the close of a batch,
Definition Modification.h:215
std::size_t events
the net events to apply
Definition Modification.h:209
std::size_t size
the size of the instance
Definition Modification.h:210
how a query of an observer brought its solution up to date (the outcomes, to ), and why (the causes,...
Definition Modification.h:183
static constexpr int SCRATCH_BY_SIZE
from scratch, too many
Definition Modification.h:187
static constexpr int PARTIAL
a repair stopped by a
Definition Modification.h:194
static constexpr int SCRATCH_BY_ABORT
from scratch, a repair
Definition Modification.h:189
static constexpr int outcomeOf(int c)
the outcome of the cause
Definition Modification.h:199
static constexpr int SCRATCH_BY_EVENT
from scratch, Rebuilt,
Definition Modification.h:191
static constexpr int WARM
by a repair
Definition Modification.h:185
static constexpr int SCRATCH
from scratch
Definition Modification.h:184
static constexpr int CAUSES
the number of the causes
Definition Modification.h:196
static constexpr int CERTIFIED
by the certificate
Definition Modification.h:186
what a shadow counts
Definition Modification.h:2330
std::uint64_t events
the events forwarded
Definition Modification.h:2331
std::uint64_t mismatches
the queries whose answers differ
Definition Modification.h:2333
std::uint64_t queries
the queries compared
Definition Modification.h:2332
the static observers O... (or mod::Via< O , A >), references called directly in the order of the argu...
Definition Modification.h:1968
mod::detail::Subject< L, Obs, mod::detail::StaticSet< L, Obs, O... >, mod::detail::NoSlots< L > > bind
the subject of a structure of the events L
Definition Modification.h:1971
the items of the handles hs erased by one bulk operation
Definition Modification.h:664
static constexpr unsigned effects
it shrinks
Definition Modification.h:665
static constexpr Role role
a bulk erasure
Definition Modification.h:666
std::span< const H > hs
the handles
Definition Modification.h:667
the items of the handles hs inserted by one bulk operation
Definition Modification.h:655
std::span< const H > hs
the handles
Definition Modification.h:658
static constexpr unsigned effects
it grows
Definition Modification.h:656
static constexpr Role role
a bulk insertion
Definition Modification.h:657
the attribute A of the item of handle changed from from to to
Definition Modification.h:600
C value_type
Definition Modification.h:605
C from
Definition Modification.h:607
static constexpr Role role
Definition Modification.h:602
constexpr unsigned direction(void) const
effect::up or effect::down by the order of from and to, 0 if they are equivalent, both if V has no or...
Definition Modification.h:611
bool operator==(const Changed &) const =default
whether the two events are the same
static constexpr unsigned effects
Definition Modification.h:601
C to
Definition Modification.h:608
mod::Value attribute
Definition Modification.h:603
int handle_type
Definition Modification.h:604
int h
Definition Modification.h:606
the structure emptied
Definition Modification.h:699
bool operator==(const Cleared &) const =default
whether the two events are the same
static constexpr unsigned effects
anything
Definition Modification.h:700
static constexpr Role role
a clearing
Definition Modification.h:701
the cost of an arc
Definition Modification.h:438
the counts of an observer kept by the subject at the level of the audits
Definition Modification.h:783
std::uint64_t rebuilds
the Rebuilt received
Definition Modification.h:786
std::uint64_t events
the events received
Definition Modification.h:784
how a subject calls an observer: Direct calls on() and the optional parts by their names; an adapter ...
Definition Modification.h:887
static bool audit(const O &o, const S &s)
o.audit( s )
Definition Modification.h:925
static bool early(O &o, std::size_t k)
whether the policy of wants Rebuilt instead of the events of a batch [see with_policy]
Definition Modification.h:938
static decltype(auto) one(O &o, const E &e) noexcept(noexcept(o.on(e)))
o.on( e )
Definition Modification.h:891
static bool prepare(const O &o, const E &e)
o.prepare( e )
Definition Modification.h:919
static void many(O &o, std::span< const E > s)
o.on( s )
Definition Modification.h:898
static void rebuilt(O &o) noexcept
o.on( Rebuilt{} )
Definition Modification.h:946
static void begin(O &o, const Group &g)
o.group_begin( g ), or o.group_begin()
Definition Modification.h:904
static void end(O &o)
o.group_end()
Definition Modification.h:913
static std::uint64_t mask(const O &o)
o.mask()
Definition Modification.h:931
static constexpr Role role
an erasure
Definition Modification.h:586
K key
the key
Definition Modification.h:591
H handle_type
Definition Modification.h:587
bool operator==(const Erased &) const =default
whether the two events are the same
H h
< no value
Definition Modification.h:590
void value_type
< the key
Definition Modification.h:589
K key_type
< the handle
Definition Modification.h:588
static constexpr unsigned effects
it shrinks
Definition Modification.h:585
the item of handle , key and value erased, told before the removal outside a batch
Definition Modification.h:568
K handle_type
Definition Modification.h:571
static constexpr Role role
Definition Modification.h:570
V value
Definition Modification.h:576
bool operator==(const Erased &) const =default
whether the two events are the same
K key
Definition Modification.h:575
K h
Definition Modification.h:574
V value_type
Definition Modification.h:573
K key_type
Definition Modification.h:572
static constexpr unsigned effects
Definition Modification.h:569
what a batch tells group_begin(): the versions of the subject before and after it,...
Definition Modification.h:775
std::size_t size
its events
Definition Modification.h:778
std::uint64_t from
the version before the batch
Definition Modification.h:776
std::uint64_t to
the version after it
Definition Modification.h:777
void value_type
< the key
Definition Modification.h:557
H handle_type
Definition Modification.h:555
static constexpr Role role
an insertion
Definition Modification.h:554
static constexpr unsigned effects
it grows
Definition Modification.h:553
bool operator==(const Inserted &) const =default
whether the two events are the same
H h
< no value
Definition Modification.h:558
K key_type
< the handle
Definition Modification.h:556
K key
the key
Definition Modification.h:559
the item of handle , key and value inserted
Definition Modification.h:536
static constexpr unsigned effects
Definition Modification.h:537
K key
Definition Modification.h:543
V value
Definition Modification.h:544
V value_type
Definition Modification.h:541
static constexpr Role role
Definition Modification.h:538
K handle_type
Definition Modification.h:539
K h
Definition Modification.h:542
bool operator==(const Inserted &) const =default
whether the two events are the same
K key_type
Definition Modification.h:540
the attribute of a key that orders the items
Definition Modification.h:436
the lower bound of an arc
Definition Modification.h:442
the parent of a node in a forest, -1 at a root
Definition Modification.h:446
the items permuted: the handle before of each handle after
Definition Modification.h:646
std::span< const H > old_of_new
the old handle of each
Definition Modification.h:649
static constexpr unsigned effects
no value changes
Definition Modification.h:647
static constexpr Role role
a permutation
Definition Modification.h:648
anything may have changed: forget and recompute
Definition Modification.h:708
static constexpr Role role
a rebuilding
Definition Modification.h:710
static constexpr unsigned effects
anything
Definition Modification.h:709
bool operator==(const Rebuilt &) const =default
whether the two events are the same
the item of handle from moved to the handle to, for the structures whose handles are not stable
Definition Modification.h:633
bool operator==(const Relocated &) const =default
whether the two events are the same
std::size_t to
Definition Modification.h:638
std::size_t from
Definition Modification.h:637
static constexpr unsigned effects
Definition Modification.h:634
H handle_type
Definition Modification.h:636
static constexpr Role role
Definition Modification.h:635
every value of the attribute A replaced
Definition Modification.h:689
static constexpr unsigned effects
anything
Definition Modification.h:690
static constexpr Role role
a replacement
Definition Modification.h:691
bool operator==(const Replaced &) const =default
< the attribute
A attribute
Definition Modification.h:692
every value of the attribute A moved by delta
Definition Modification.h:673
D delta
< the attribute
Definition Modification.h:677
static constexpr Role role
a shift of all
Definition Modification.h:675
constexpr unsigned direction(void) const
effect::up or effect::down by the sign of delta
Definition Modification.h:679
bool operator==(const Shifted &) const =default
whether the two events are the same
static constexpr unsigned effects
both
Definition Modification.h:674
A attribute
Definition Modification.h:676
the supply of a node
Definition Modification.h:444
the upper bound of an arc
Definition Modification.h:440
the attribute of the value of an item
Definition Modification.h:434
the observer O called through the adapter A, an argument of Static
Definition Modification.h:954
the net effect of the events of a batch of the structures whose events are the list L: by default the...
Definition Modification.h:968
static std::vector< variant_t< L > > coalesce(std::span< const variant_t< L > > B)
the net effect of the events , in expected time
the effects of an event, as bits: a bit not set is a guarantee
Definition Modification.h:363
static constexpr unsigned grows
the structure may grow
Definition Modification.h:364
static constexpr unsigned down
a value may decrease
Definition Modification.h:367
static constexpr unsigned all
all of them
Definition Modification.h:368
static constexpr unsigned shrinks
it may shrink
Definition Modification.h:365
static constexpr unsigned up
a value may increase
Definition Modification.h:366
a list of types, the events of a structure [see Modification.h]
Definition Modification.h:482
static constexpr std::size_t size
Definition Modification.h:483
the value after the second change
Definition Modification.h:454
the largest of the two values after
Definition Modification.h:458
the least of the two values after
Definition Modification.h:456
the first value after plus the second difference
Definition Modification.h:460
typename A::reduction type
Definition Modification.h:476
the reduction of the attribute A: A::reduction if it has one, reduce::last otherwise
Definition Modification.h:467
reduce::last type
Definition Modification.h:468
the promise of quiet( s , no_rebuild ): nobody needs to know
Definition Modification.h:168
constexpr no_rebuild_t(void)=default