60#ifndef __ADS_RandomizedSearchTree
61 #define __ADS_RandomizedSearchTree
93template< std::totally_ordered K ,
class V >
106 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
135 void insert(
const K & k ,
const V & v );
161 [[nodiscard]] std::size_t
size(
void )
const {
return( sz( f_root ) ); }
168 [[nodiscard]] std::optional< std::pair< K , V > >
174 [[nodiscard]]
const K *
findKey(
const K & k )
const;
183 [[nodiscard]] std::pair< K , V >
select( std::size_t i )
const;
186 [[nodiscard]] std::size_t
rank(
const K & k )
const;
200 std::unique_ptr< Node > left ,
211 static auto root(
const auto & o ) {
return( o.f_root.get() ); }
213 static auto left(
const auto * n ) {
return( n->left.get() ); }
215 static auto right(
const auto * n ) {
return( n->right.get() ); }
217 static auto read(
const auto * n ) {
250 using Ptr = std::unique_ptr< Node >;
252 static std::size_t sz(
const Ptr & t ) {
return( t ? t->s : 0 ); }
253 static void update( Ptr & t ) { t->s = 1 + sz( t->left ) + sz( t->right ); }
254 Node * find(
const K & k )
const;
255 void insert( Ptr & t , Ptr & u );
256 static std::pair< Ptr , Ptr > split( Ptr t ,
const K & k );
257 Ptr join( Ptr a , Ptr b );
258 bool remove( Ptr & t ,
const K & k );
259 static int height(
const Ptr & t );
260 static bool valid(
const Ptr & t ,
const K * lo ,
const K * hi );
277#include "ADS/tree/impl/RandomizedSearchTree.tpp"
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 engineered random numbers, beyond the book: generators of 64 bits that cost a few instructions an...
Hashing with random tables, beyond the book:
a bidirectional iterator on the nodes of a binary tree of the owner O in symmetric order,...
Definition Iterators.h:867
const_iterator begin(void) const
the iterator on the smallest key
Definition RandomizedSearchTree.h:237
void forEach(F &&f) const
f( k , v ) on the pairs by increasing keys
K Key
the type of the keys
Definition RandomizedSearchTree.h:99
PairRef< const K &, const V & > reference
references, by value
Definition RandomizedSearchTree.h:230
const_iterator cbegin(void) const
as begin()
Definition RandomizedSearchTree.h:245
std::size_t size(void) const
the number of keys
Definition RandomizedSearchTree.h:161
std::size_t rank(const K &k) const
the number of keys smaller than , by the sizes
std::pair< K, V > select(std::size_t i) const
the pair of rank , by the sizes, as Treap::select()
std::ptrdiff_t difference_type
the type of the distances
Definition RandomizedSearchTree.h:229
int height(void) const
the height, if empty, in
std::pair< K, V > value_type
the pairs ( key , value ) by value, which own their copies
Definition RandomizedSearchTree.h:223
reference const_reference
the same
Definition RandomizedSearchTree.h:231
std::optional< V > lookup(const K &k) const
the value of , or nothing, in expected time
V mapped_type
the type of the values
Definition RandomizedSearchTree.h:227
bool contains(const K &k) const
true if is there
const_iterator end(void) const
the iterator past the largest key
Definition RandomizedSearchTree.h:241
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)
const_iterator iterator
the constant iterator
Definition RandomizedSearchTree.h:234
std::size_t size_type
the type of the sizes
Definition RandomizedSearchTree.h:228
PathIterator< RandomizedSearchTree, Shape > const_iterator
the constant iterator by increasing key, along the path from the root
Definition RandomizedSearchTree.h:233
V Value
the type of the values
Definition RandomizedSearchTree.h:100
const K * findKey(const K &k) const
the address of the key , nil if absent, in expected time: the find( x ) of a USet of Morin [see Dict...
void insert(const K &k, const V &v)
associates to , in expected time
K key_type
the type of the keys
Definition RandomizedSearchTree.h:225
const K * lowerBoundKey(const K &k) const
the address of the smallest key not smaller than , nil if none, in expected time: the find( x ) of a...
void remove(const K &k)
removes , if it is there, in expected time
RandomizedSearchTree(std::uint64_t seed=1)
the empty tree, its random choices drawn from the seed
Definition RandomizedSearchTree.h:103
const_iterator cend(void) const
as end()
Definition RandomizedSearchTree.h:247
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
the shape of the tree, for PathIterator
Definition RandomizedSearchTree.h:209
static auto read(const auto *n)
the pair of the node n
Definition RandomizedSearchTree.h:217
static auto root(const auto &o)
the root of the tree o
Definition RandomizedSearchTree.h:211
static auto right(const auto *n)
the right child of the node n
Definition RandomizedSearchTree.h:215
static auto left(const auto *n)
the left child of the node n
Definition RandomizedSearchTree.h:213