165#ifndef __ADS_JoinAlgorithms
166 #define __ADS_JoinAlgorithms
183#include <type_traits>
217 requires(
typename A::Node * t ,
typename A::Node *& l ,
218 const typename A::Key & k ,
typename A::Rank r )
220 { A::nil() } -> std::same_as< typename A::Node * >;
221 { A::left( t ) } -> std::same_as< typename A::Node * >;
222 { A::right( t ) } -> std::same_as< typename A::Node * >;
223 { A::key( t ) } -> std::same_as< const typename A::Key & >;
224 { A::value( t ) } -> std::same_as< typename A::Value & >;
225 { A::size( t ) } -> std::convertible_to< std::size_t >;
226 A::expose( t , l , l );
227 { A::connect( t , t , t ) } -> std::same_as< typename A::Node * >;
229 { A::rank( t ) } -> std::same_as< typename A::Rank >;
230 { A::childRank( t , r , t ) } -> std::same_as< typename A::Rank >;
232 A::join( t , r , t , t , r )
233 } -> std::same_as< std::pair< typename A::Node * , typename A::Rank > >;
234 { k < k } -> std::convertible_to< bool >;
401 static bool like( std::size_t a , std::size_t b );
443template< JoinAdaptor A >
448 using Key =
typename A::Key;
598 template< Executor E ,
class F >
623 template< Executor E ,
class F >
654 template< Executor E >
672 template< Executor E >
673 [[nodiscard]]
static Tree build( E & ex ,
Node *
const * N , std::size_t n );
703 template< Executor E ,
class F >
705 std::size_t n ,
const F & f );
733 template< Executor E >
735 std::size_t n , std::size_t & gone );
754 template< Executor E ,
class P >
775 template< Executor E ,
class M ,
class R ,
class U >
777 const R & reduce ,
const U &
id );
810 template< Executor E ,
class G ,
class H >
811 static void fork( E & ex , G && g , H && h );
814 template<
class G ,
class H >
815 static void fork(
Sequential & ex , G && g , H && h );
818 template< Executor E >
819 [[nodiscard]]
static bool small( E & ex , std::size_t n );
858template<
class T ,
class A ,
class Key ,
class Value >
871 [[nodiscard]] std::tuple< T , std::optional< Value > , T >
879 [[nodiscard]]
static T
join( T && l ,
const Key & k ,
const Value & v ,
885 [[nodiscard]]
static T
join2( T && l , T && r );
899 template<
class F = TakeSecond >
906 template< Executor E ,
class F = TakeSecond >
913 template<
class F = TakeFirst >
920 template< Executor E ,
class F = TakeFirst >
932 template< Executor E >
939 template<
class F = TakeSecond >
947 template< Executor E ,
class F = TakeSecond >
948 void multiInsert( E & ex , std::span<
const std::pair< Key , Value > > B ,
960 template< Executor E >
972 template< Executor E ,
class P >
979 template<
class M ,
class R ,
class U >
980 [[nodiscard]] U
mapReduce( M map , R reduce , U
id )
const {
982 return(
mapReduce( seq , map , reduce , std::move(
id ) ) );
986 template< Executor E ,
class M ,
class R ,
class U >
987 [[nodiscard]] U
mapReduce( E & ex , M map , R reduce , U
id )
const;
999#include "ADS/tree/impl/JoinAlgorithms.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The layer of execution of the parallel algorithms of ADS, beyond the book: an executor runs the calls...
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
void intersectWith(T &&o, F f=F())
the intersection with o, which is consumed, by JoinAlgorithms::intersect(); the value f( mine ,...
Definition JoinAlgorithms.h:914
void multiRemove(E &ex, std::span< const Key > B)
multiRemove( B ) on the threads of ex
void unionWith(T &&o, F f=F())
the union with o, which is consumed, by JoinAlgorithms::unite(); on a key of both,...
Definition JoinAlgorithms.h:900
void multiInsert(E &ex, std::span< const std::pair< Key, Value > > B, F f=F())
multiInsert( B , f ) on the threads of ex
void multiInsert(std::span< const std::pair< Key, Value > > B, F f=F())
the pairs of inserted, by JoinAlgorithms::multiInsert(); on a key already there, the value f( mine ,...
Definition JoinAlgorithms.h:940
void differenceWith(E &ex, T &&o)
differenceWith( o ) on the threads of ex
static T join2(T &&l, T &&r)
the tree of the keys of and of , which are consumed, by JoinAlgorithms::join2(), in time
T extractRange(const Key &lo, const Key &hi)
the pairs of the keys in , taken out of the tree by JoinAlgorithms::extract(), in time
std::tuple< T, std::optional< Value >, T > split(const Key &k) &&
the keys before , the value of (if there), the keys after , by JoinAlgorithms::split(); the tree is ...
void intersectWith(E &ex, T &&o, F f=F())
intersectWith( o , f ) on the threads of ex
void differenceWith(T &&o)
the keys not in o, which is consumed, by JoinAlgorithms::subtract(); the work of unionWith(),...
Definition JoinAlgorithms.h:926
static T join(T &&l, const Key &k, const Value &v, T &&r)
the tree of the keys of , the pair and the keys of , by the join of the scheme; and are consumed,...
void multiRemove(std::span< const Key > B)
the keys of removed, by JoinAlgorithms::multiRemove(), work
Definition JoinAlgorithms.h:954
void unionWith(E &ex, T &&o, F f=F())
unionWith( o , f ) on the threads of ex
void filter(P p)
only the pairs with p( k , v ) kept, by JoinAlgorithms::filter(), work
Definition JoinAlgorithms.h:966
U mapReduce(E &ex, M map, R reduce, U id) const
mapReduce( map , reduce , id ) on the threads of ex
void filter(E &ex, P p)
filter( p ) on the threads of ex
U mapReduce(M map, R reduce, U id) const
by an associative reduce of identity id, by JoinAlgorithms::mapReduce(), work
Definition JoinAlgorithms.h:980
the executor of the calling thread alone, which makes the calls in their order
Definition Executor.h:265
the nodes of a binary search tree as the algorithms based on join see them: nil(),...
Definition JoinAlgorithms.h:216
constexpr std::size_t kJoinGrain
the sum of the sizes of two trees below which the algorithms run on the calling thread alone
Definition JoinAlgorithms.h:200
the join of the AVL trees; A gives also height( t ), -1 for nil, which connect() keeps
Definition JoinAlgorithms.h:245
typename A::Node Node
the type of the nodes
Definition JoinAlgorithms.h:246
static Node * joinRight(Node *l, Node *m, Node *r)
the join when is higher than by more than 1, by the right spine of
static Node * joinLeft(Node *l, Node *m, Node *r)
the join when is higher than by more than 1, the mirror of joinRight()
static Node * join(Node *l, Node *m, Node *r)
the join of the AVL trees and with between them, in time
a tree taken apart at its root
Definition JoinAlgorithms.h:461
Tree r
the right subtree
Definition JoinAlgorithms.h:464
Node * m
the root, alone
Definition JoinAlgorithms.h:463
Tree l
the left subtree
Definition JoinAlgorithms.h:462
a tree: its root and its rank
Definition JoinAlgorithms.h:454
Rank r
the rank
Definition JoinAlgorithms.h:456
Node * t
the root, nil if empty
Definition JoinAlgorithms.h:455
the algorithms on the trees whose only balancing is the join of A; each of them consumes the trees it...
Definition JoinAlgorithms.h:445
typename A::Value Value
the type of the values
Definition JoinAlgorithms.h:449
static Tree join2(Tree l, Tree r)
the tree of the keys of and of , with no key in between, in time
typename A::Node Node
the type of the nodes
Definition JoinAlgorithms.h:447
static Tree filter(E &ex, Tree x, const P &p)
the nodes of with kept, the others freed: work and span
static U mapReduce(E &ex, Node *t, const M &map, const R &reduce, const U &id)
the reduction of the values of the pairs of the tree of root , in the order of the keys,...
static Tree insert(Tree x, Node *n, bool &fresh)
the node alone inserted in , fresh whether its key was not there (if it was, its value replaces the ...
static Node * split(Tree x, const Key &k, Tree &l, Tree &r)
the keys of smaller than in , those larger in , and the node of returned, alone (nil if is not in...
static Tree whole(Node *t)
the tree of root , its rank computed
static Tree extract(Tree &x, const Key &lo, const Key &hi)
the keys of in taken out into the tree returned, by two splits, two joins and a join2,...
static Exposed expose(Tree x)
the subtrees and the root of
static Tree multiInsert(E &ex, Tree x, Node *const *N, std::size_t n, const F &f)
the nodes alone of , whose keys increase, inserted in ; on a key already there the value ,...
static Tree intersect(E &ex, Tree a, Tree b, const F &f)
the intersection of and , the value , with the work and the span of unite(); the nodes that leave ar...
static Tree multiRemove(E &ex, Tree x, const Key *K, std::size_t n, std::size_t &gone)
the keys of , increasing, taken out of and freed, gone how many were there: the difference of and ...
static Node * splitLast(Tree x, Tree &rest)
the node of the largest key of returned, alone, and the others in rest, in time
static const Key & firstKey(Node *t)
the smallest key of
static Tree empty(void)
the empty tree
static Tree join(Tree l, Node *m, Tree r)
the join of the scheme, with the ranks
static Tree unite(E &ex, Tree a, Tree b, const F &f)
the union of and , on a key of both the value , with work and span for sizes
static Tree build(E &ex, Node *const *N, std::size_t n)
the tree of the nodes alone of , whose keys increase: the middle one joined with the trees of the tw...
static const Key & lastKey(Node *t)
the largest key of
typename A::Key Key
the type of the keys
Definition JoinAlgorithms.h:448
static Tree subtract(E &ex, Tree a, Tree b)
the keys of not in , with the work and the span of unite(); the nodes of and those of that leave a...
static Tree remove(Tree x, const Key &k, bool &gone)
the key taken out of and freed, gone whether it was there, by joins on the way back and join2 where...
typename A::Rank Rank
the type of the ranks
Definition JoinAlgorithms.h:450
the join of the Red-Black trees, whose ranks are the black heights; A gives also red( t ),...
Definition JoinAlgorithms.h:291
static std::pair< Node *, int > join(Node *l, int bl, Node *m, Node *r, int br)
the join of the Red-Black trees and , of black heights and , with between them: the root and its b...
static Node * joinRight(Node *l, int bl, Node *m, Node *r, int br)
the join when the black height of is larger than , by the right spine of
typename A::Node Node
the type of the nodes
Definition JoinAlgorithms.h:292
static Node * joinLeft(Node *l, int bl, Node *m, Node *r, int br)
the join when the black height of is larger than , the mirror of joinRight()
the value of the first tree on a key in both
Definition JoinAlgorithms.h:839
V operator()(const V &a, const V &) const
Definition JoinAlgorithms.h:842
the value of the second tree, or of the batch, on a key in both
Definition JoinAlgorithms.h:829
V operator()(const V &, const V &b) const
Definition JoinAlgorithms.h:832
the join of the treaps; A gives also priority( t ), of a node
Definition JoinAlgorithms.h:410
static Node * join(Node *l, Node *m, Node *r)
the join of the treaps and with between them, in expected time
typename A::Node Node
the type of the nodes
Definition JoinAlgorithms.h:411
the join of the trees balanced by weight, with
Definition JoinAlgorithms.h:347
static constexpr std::size_t kAlphaNum
, up
Definition JoinAlgorithms.h:350
static std::size_t weight(const Node *t)
the weight of , its size plus 1
static Node * joinLeft(Node *l, Node *m, Node *r)
the join when is heavier than beyond the balance, the mirror of joinRight()
typename A::Node Node
the type of the nodes
Definition JoinAlgorithms.h:348
static bool like(std::size_t a, std::size_t b)
whether the weights and may be the two sides of a node:
static Node * join(Node *l, Node *m, Node *r)
the join of the trees and balanced by weight with between them, in time
static Node * joinRight(Node *l, Node *m, Node *r)
the join when is heavier than beyond the balance, by the right spine of
static constexpr std::size_t kAlphaDen
and down
Definition JoinAlgorithms.h:351