122#ifndef __ADS_JoinTree
123 #define __ADS_JoinTree
145#include <type_traits>
173template<
class G ,
class K ,
class V >
175 requires(
const K & k ,
const V & v ,
const typename G::Value & a )
177 { G::identity() } -> std::convertible_to< typename G::Value >;
178 { G::from( k , v ) } -> std::convertible_to< typename G::Value >;
179 { G::combine( a , a ) } -> std::convertible_to< typename G::Value >;
189inline constexpr bool unbound_v = std::is_same_v< P , NoObservers >;
192inline constexpr bool unbound_v< Dynamic< L > > =
true;
209 template<
class K ,
class V >
234 requires requires { -a; }
251 if constexpr( std::numeric_limits< V >::has_infinity )
252 return( -std::numeric_limits< V >::infinity() );
254 return( std::numeric_limits< V >::lowest() );
263 return( a < b ? b : a );
274template< std::totally_ordered K ,
class V ,
class B = AVLBalance ,
275 class G = NoAugmentation ,
class Policy = NoObservers ,
276 class A = std::allocator< std::pair< const K , V > > >
277 requires Augmentation< G , K , V >
281template< std::totally_ordered K ,
class V ,
class B ,
class G ,
class Policy ,
285template< std::totally_ordered K ,
class V ,
class B ,
class G ,
class Policy ,
289 :
public Joinable< JoinTree< K , V , B , G , Policy , A > ,
290 JoinTreeNodes< K , V , B , G , Policy , A > , K , V >
320 using Subject =
typename Policy::template bind< modifications , JoinTree >;
338 requires detail::unbound_v< Policy >;
342 template< class... O >
343 requires( sizeof...( O ) > 0 )
354 requires detail::unbound_v< Policy >;
358 requires detail::unbound_v< Policy >;
378 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
394 void insert(
const K & k ,
const V & v );
444 bool assign(
const K & k ,
const V & v );
451 [[nodiscard]] std::optional< std::pair< K , V > >
457 [[nodiscard]]
const K *
findKey(
const K & k )
const;
465 [[nodiscard]] std::size_t
size(
void )
const;
468 [[nodiscard]]
bool empty(
void )
const;
540 void augVisit(
const K & lo ,
const K & hi , F && f )
const;
568 [[nodiscard]] std::optional< std::pair< K , V > >
augSelect( P && p )
const;
593 template<
class Q ,
class F >
601 [[nodiscard]]
const Node *
root(
void )
const {
return( f_root ); }
609 static auto root(
const auto & o ) {
return( o.f_root ); }
611 static auto left(
const auto * n ) {
return( n->left ); }
613 static auto right(
const auto * n ) {
return( n->right ); }
615 static auto read(
const auto * n ) {
651 [[nodiscard]]
bool valid(
void )
const;
655 [[nodiscard]] Node * findNode(
const K & k )
const;
663 void insertPlain(
const K & k ,
const V & v );
665 void removePlain(
const K & k );
667 bool assignPlain(
const K & k ,
const V & v );
672 void insertTold(
const K & k ,
const V & v );
678 void removeTold(
const K & k );
680 ADS_COLD_PATH void removeCold(
const K & k ) { removeTold( k ); }
682 bool assignTold(
const K & k ,
const V & v );
685 return( assignTold( k , v ) );
690 void tellCleared(
void )
noexcept;
692 void tellRebuilt(
void )
noexcept;
694 Node * f_root =
nullptr;
703template< std::totally_ordered K ,
class V ,
class G =
NoAugmentation ,
705 class A = std::allocator< std::pair< const K , V > > >
709template< std::totally_ordered K ,
class V ,
class G =
NoAugmentation ,
711 class A = std::allocator< std::pair< const K , V > > >
715template< std::totally_ordered K ,
class V ,
class G =
NoAugmentation ,
717 class A = std::allocator< std::pair< const K , V > > >
721template< std::totally_ordered K ,
class V ,
class G =
NoAugmentation ,
723 class A = std::allocator< std::pair< const K , V > > >
727template< std::totally_ordered K ,
class V ,
class G ,
729 class A = std::allocator< std::pair< const K , V > > >
740#include "ADS/tree/impl/JoinTree.tpp"
The algebra of the aggregates, beyond the book: the concepts by which a structure that keeps a combin...
The rules of the allocator-aware containers of the standard ([container.reqmts], [allocator....
The classic problems on binary trees and on binary search trees, written once for any representation ...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The iterators that the containers of the library have in common, beyond the book: they give a contain...
The balanced binary search trees whose only balancing operation is join, beyond the book,...
The typed modifications, beyond the book: the vocabulary by which a structure tells the observers att...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
Hashing with random tables, beyond the book:
a DICTIONARY on a binary search tree balanced by the join of B alone, augmented by G,...
Definition JoinTree.h:291
bool contains(const K &k) const
true if is there
K key_type
Definition JoinTree.h:623
AugValue augPrefix(const K &k) const
the augmented value of the pairs with keys , in calls of combine()
const_iterator end(void) const
the iterator past the largest key
Definition JoinTree.h:639
std::size_t size_type
Definition JoinTree.h:626
std::size_t size(void) const
the number of keys
typename Policy::template bind< modifications, JoinTree > Subject
Definition JoinTree.h:320
std::optional< std::pair< K, V > > augSelect(P &&p) const
the first pair, by increasing keys, whose prefix (the augmented value of the pairs up to it) satisfie...
std::size_t Value
Definition JoinTree.h:299
bool empty(void) const
true if there is no key
void insert(const K &k, const V &v)
associates to , in time; tells Inserted, or Assigned if was there (by one more descent,...
PathIterator< JoinTree, Shape > const_iterator
Definition JoinTree.h:631
const K * lowerBoundKey(const K &k) const
the address of the smallest key not smaller than , nil if none, in time: the find( x ) of an SSet of...
void clear(void)
removes all the pairs; tells Cleared if there was one
mod::list< Inserted, Erased, Assigned, mod::Cleared, mod::Rebuilt > modifications
Definition JoinTree.h:317
bool assign(const K &k, const V &v)
the value of set to , and true, if is there, nothing and false otherwise, in time; the shape stays...
std::size_t mapped_type
Definition JoinTree.h:625
reference const_reference
Definition JoinTree.h:629
PairRef< const K &, const std::size_t & > reference
Definition JoinTree.h:628
void remove(const K &k)
removes , if it is there, in time; tells Erased (by one more descent, only when someone listens)
std::ptrdiff_t difference_type
Definition JoinTree.h:627
AugValue augRange(const K &lo, const K &hi) const
the augmented value of the pairs with keys in , in calls of combine(), the combination of the pieces...
const_iterator begin(void) const
the iterator on the smallest key
Definition JoinTree.h:635
const_iterator cend(void) const
as end()
Definition JoinTree.h:645
std::pair< K, std::size_t > value_type
Definition JoinTree.h:621
mod::Assigned< K, std::size_t > Assigned
Definition JoinTree.h:314
const_iterator iterator
Definition JoinTree.h:632
MaxEnd Augmented
Definition JoinTree.h:301
const Node * root(void) const
the root, nullptr if empty; the nodes must not be changed
Definition JoinTree.h:601
std::optional< V > lookup(const K &k) const
the value of , or nothing, by the descent of a binary search tree, in time
Subject & subject(void)
Definition JoinTree.h:367
allocator_type get_allocator(void) const
the allocator of the nodes, stateless
Definition JoinTree.h:305
K Key
Definition JoinTree.h:298
int height(void) const
the height of the tree, -1 if empty, in time
void augFilter(Q &&q, F &&f) const
f( k , v ) on the pairs with , by increasing keys, entering only the subtrees whose augmented value ...
A allocator_type
Definition JoinTree.h:302
typename MaxEnd::Value AugValue
Definition JoinTree.h:300
std::optional< std::pair< K, V > > lowerBound(const K &k) const
the smallest key not smaller than and its value, or nothing (the find( x ) of an SSet of Morin),...
JoinTree(std::uint64_t seed=1)
an empty tree; the seed of the priorities, for a treap
const Subject & subject(void) const
the subject
Definition JoinTree.h:370
AugValue augValue(void) const
the augmented value of the whole map, in time
mod::Inserted< K, K, std::size_t > Inserted
Definition JoinTree.h:310
void augVisit(const K &lo, const K &hi, F &&f) const
f( a ) on the augmented values of the pieces (whole subtrees and single pairs) whose union is the s...
mod::Erased< K, K, std::size_t > Erased
Definition JoinTree.h:312
const K * findKey(const K &k) const
the address of the key , nil if absent, in time: the find( x ) of a USet of Morin [see DictionarySet...
void forEach(F &&f) const
f( k , v ) on the pairs by increasing keys
void swap(JoinTree &o) noexcept
const_iterator cbegin(void) const
as begin()
Definition JoinTree.h:643
the operations based on join of the tree T of keys Key and values Value, whose nodes A adapts [see Jo...
Definition JoinAlgorithms.h:860
a bidirectional iterator on the nodes of a binary tree of the owner O in symmetric order,...
Definition Iterators.h:867
a group whose operation commutes
Definition Algebra.h:137
an augmentation of a map from K to V: a monoid on G::Value, of identity G::identity() and associative...
Definition JoinTree.h:174
constexpr bool exact_v
whether the values of G are exact, false for the floating point types, whose groups drift by rounding...
Definition Algebra.h:161
std::conditional_t< detail::plainPair< A, B, VA, VB >, std::pair< A, B >, detail::PairProxy< A, B, VA, VB > > PairRef
the pair that an iterator reads by value, in general two references into the container,...
Definition Iterators.h:648
Changed< Value, H, V > Assigned
the value of an item changed
Definition Modification.h:623
#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
JoinTree< K, V, WeightBalance, G, Policy, A > AugmentedMap
the map augmented by G, balanced by weight as in PAM
Definition JoinTree.h:730
JoinTree< K, V, AVLBalance, G, Policy, A > JoinAVLTree
the AVL tree whose balance is in join alone
Definition JoinTree.h:706
JoinTree< K, V, TreapBalance, G, Policy, A > JoinTreap
the treap whose balance is in join alone
Definition JoinTree.h:724
JoinTree< K, V, RedBlackBalance, G, Policy, A > JoinRedBlackTree
the Red-Black tree whose balance is in join alone
Definition JoinTree.h:712
JoinTree< K, V, WeightBalance, G, Policy, A > WeightBalancedTree
the tree balanced by weight, in join alone
Definition JoinTree.h:718
the AVL trees [see AVLJoin]
Definition JoinTree.h:160
the adaptor of the nodes of a JoinTree [see JoinAdaptor]
Definition JoinTree.h:283
a node: what the navigation below reads
Definition JoinTree.h:324
std::size_t size
the nodes of the subtree
Definition JoinTree.h:327
K key
the key
Definition JoinTree.h:332
Node * left
the left child
Definition JoinTree.h:325
V value
the value
Definition JoinTree.h:333
std::uint64_t meta
the height plus 1 (AVL), the black height times 2 plus 1 if red (Red-Black), the priority (treap)
Definition JoinTree.h:330
AugValue aug
the augmented value
Definition JoinTree.h:331
Node * right
the right child
Definition JoinTree.h:326
the shape of the tree, for PathIterator
Definition JoinTree.h:607
static auto root(const auto &o)
the root of the tree o
Definition JoinTree.h:609
static auto right(const auto *n)
the right child of the node n
Definition JoinTree.h:613
static auto left(const auto *n)
the left child of the node n
Definition JoinTree.h:611
static auto read(const auto *n)
the pair of the node n
Definition JoinTree.h:615
the largest of the values, whose identity is if V has it, its smallest value otherwise: a commutativ...
Definition JoinTree.h:245
static constexpr bool commutative
the order does not count
Definition JoinTree.h:247
static Value combine(const Value &a, const Value &b)
Definition JoinTree.h:262
static constexpr bool selective
the maximum is one of two
Definition JoinTree.h:248
V Value
the maxima, of the type of the values
Definition JoinTree.h:246
static Value identity(void)
the smallest value of the type
Definition JoinTree.h:250
static Value from(const K &, const V &v)
the value of the pair
Definition JoinTree.h:258
the empty value
Definition JoinTree.h:202
bool operator==(const Value &) const =default
all equal
no augmentation: nothing is kept, nothing computed
Definition JoinTree.h:199
static Value combine(const Value &, const Value &)
the empty value
Definition JoinTree.h:214
static Value identity(void)
the empty value
Definition JoinTree.h:207
static Value from(const K &, const V &)
the empty value
Definition JoinTree.h:210
nobody listens: the subject is empty and every test is false at compile time, so that the structure c...
Definition Modification.h:1958
the Red-Black trees [see RedBlackJoin]
Definition JoinTree.h:162
the sum of the values, an abelian group when V has the opposites
Definition JoinTree.h:220
static Value from(const K &, const V &v)
the value of the pair
Definition JoinTree.h:227
static Value inverse(const Value &a)
Definition JoinTree.h:233
static Value identity(void)
0, the value made by V()
Definition JoinTree.h:224
static Value combine(const Value &a, const Value &b)
Definition JoinTree.h:231
static constexpr bool commutative
Definition JoinTree.h:222
V Value
the sums, of the type of the values
Definition JoinTree.h:221
the treaps [see TreapJoin]
Definition JoinTree.h:166
the weight-balanced trees
Definition JoinTree.h:164
the item of handle , key and value erased, told before the removal outside a batch
Definition Modification.h:568
the item of handle , key and value inserted
Definition Modification.h:536
a list of types, the events of a structure [see Modification.h]
Definition Modification.h:482