51#ifndef __ADS_TreapList
52 #define __ADS_TreapList
91 explicit TreapList( std::uint64_t seed = detail::instanceSeed() )
95 [[nodiscard]] std::size_t
size(
void )
const {
return( sz( f_root ) ); }
98 [[nodiscard]]
bool empty(
void )
const {
return( ! f_root ); }
116 [[nodiscard]]
const T &
get( std::size_t i )
const;
121 void set( std::size_t i ,
const T & v );
143 void add( std::size_t i ,
const T & v );
156 return( nodeAt( i )->item );
162 void insert( std::size_t i ,
const T & v ) {
add( i , v ); }
223 std::uint64_t priority;
225 std::unique_ptr< Node > left ,
236 static auto root(
const auto & o ) {
return( o.f_root.get() ); }
238 static auto left(
const auto * n ) {
return( n->left.get() ); }
240 static auto right(
const auto * n ) {
return( n->right.get() ); }
242 static const T &
read(
const auto * n ) {
return( n->item ); }
268 using Ptr = std::unique_ptr< Node >;
270 static std::size_t sz(
const Ptr & t ) {
return( t ? t->s : 0 ); }
271 static void update( Ptr & t ) { t->s = 1 + sz( t->left ) + sz( t->right ); }
272 static void rotateRight( Ptr & t );
273 static void rotateLeft( Ptr & t );
274 Node * nodeAt( std::size_t i )
const;
275 void add( Ptr & t , std::size_t i ,
const T & v );
276 static T
remove( Ptr & t , std::size_t i );
277 static std::pair< Ptr , Ptr > split( Ptr t , std::size_t i );
278 static Ptr join( Ptr a , Ptr b );
279 static bool valid(
const Ptr & t );
294#include "ADS/sequence/impl/TreapList.tpp"
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...
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
void absorb(TreapList &s)
the items of appended, in order, and left empty, by the join of the two treaps, in expected time
bool empty(void) const
true if there is no item
Definition TreapList.h:98
T remove(std::size_t i)
the item of index removed and returned, in expected time, the node rotated down as in Treap::remove...
const_iterator end(void) const
the iterator past the last item
Definition TreapList.h:259
std::size_t size(void) const
the number of items
Definition TreapList.h:95
T value_type
the items
Definition TreapList.h:245
TreapList truncate(std::size_t i)
the items of index to taken out and returned as a sequence, by the split of the treap at ,...
const_iterator cbegin(void) const
as begin()
Definition TreapList.h:263
void insert(std::size_t i, const T &v)
inserted at , add( i , v ) (the name of IndexedList)
Definition TreapList.h:162
void push_back(const T &v)
appended, add( size() , v )
Definition TreapList.h:170
const T & const_reference
a constant reference
Definition TreapList.h:249
T & operator[](std::size_t i)
the item of index , to be read or written, by the search of get()
Definition TreapList.h:154
const T & get(std::size_t i) const
the item of index , in expected time
const_iterator begin(void) const
the iterator on the first item
Definition TreapList.h:255
T Item
the type of the items
Definition TreapList.h:87
const_iterator iterator
the constant iterator
Definition TreapList.h:252
PathIterator< TreapList, Shape > const_iterator
the constant iterator in the order of the sequence
Definition TreapList.h:251
const_iterator cend(void) const
as end()
Definition TreapList.h:265
std::size_t size_type
the type of the sizes
Definition TreapList.h:246
const T & reference
a constant reference
Definition TreapList.h:248
void add(std::size_t i, const T &v)
inserted at the index , in expected time
std::ptrdiff_t difference_type
the type of the distances
Definition TreapList.h:247
TreapList(std::uint64_t seed=detail::instanceSeed())
the empty sequence, its priorities drawn from the seed, by default one of its own [see detail::instan...
Definition TreapList.h:91
void set(std::size_t i, const T &v)
the item of index replaced by , by the descent of get()
const T & operator[](std::size_t i) const
the item of index , as get( i ) (the name of IndexedList)
Definition TreapList.h:147
void erase(std::size_t i)
the item of index removed, remove( i ) (the name of IndexedList)
Definition TreapList.h:167
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
the shape of the tree, for PathIterator
Definition TreapList.h:234
static auto left(const auto *n)
the left child of the node n
Definition TreapList.h:238
static auto right(const auto *n)
the right child of the node n
Definition TreapList.h:240
static auto root(const auto &o)
the root of the tree o
Definition TreapList.h:236
static const T & read(const auto *n)
the item of the node n
Definition TreapList.h:242