61#ifndef __ADS_FingerTreap
62 #define __ADS_FingerTreap
94template< std::totally_ordered K ,
class V >
115 explicit Finger( Node * u ) : f_u( u ) { }
116 Node * f_u =
nullptr;
130 : f_root( other.f_root ) , f_size( other.f_size ) , f_g( other.f_g ) {
131 other.f_root = other.f_finger =
nullptr;
140 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
178 void insert(
const K & k ,
const V & v );
191 [[nodiscard]] std::size_t
size(
void )
const {
return( f_size ); }
198 [[nodiscard]] std::optional< std::pair< K , V > >
204 [[nodiscard]]
const K *
findKey(
const K & k )
const;
213 [[nodiscard]] std::pair< K , V >
select( std::size_t i )
const;
216 [[nodiscard]] std::size_t
rank(
const K & k )
const;
230 std::uint64_t priority;
231 Node * left =
nullptr;
232 Node * right =
nullptr;
233 Node * parent =
nullptr;
236 std::size_t
size = 1;
246 static auto root(
const auto & o ) {
return( o.f_root ); }
248 static auto left(
const auto * n ) {
return( n->left ); }
250 static auto right(
const auto * n ) {
return( n->right ); }
252 static auto read(
const auto * n ) {
286 Node *
search(
const K & k , Node * u )
const;
289 static void update( Node * u ) {
291 1 + ( u->left ? u->left->size : 0 ) + ( u->right ? u->right->size : 0 );
292 u->lo = u->left ? u->left->lo : u;
293 u->hi = u->right ? u->right->hi : u;
297 void rotateRight( Node * u );
300 void rotateLeft( Node * u );
303 [[nodiscard]]
bool valid(
void )
const;
306 Node * f_root =
nullptr;
307 Node * f_finger =
nullptr;
308 std::size_t f_size = 0;
322#include "ADS/tree/impl/FingerTreap.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...
Hashing with random tables, beyond the book:
a node of the treap, from which a search may start; valid until the node is removed
Definition FingerTreap.h:108
Finger(void)=default
no node: a search from it starts at the root
friend class FingerTreap
Definition FingerTreap.h:114
void remove(const K &k)
removes , if it is there, in expected time: the node rotated down to a leaf, the child of larger pri...
bool contains(const K &k) const
true if is there
void insert(const K &k, const V &v)
associates to , in expected time: a leaf rotated up while its priority beats its parent's,...
const_iterator end(void) const
the iterator past the largest key
Definition FingerTreap.h:276
std::ptrdiff_t difference_type
the type of the distances
Definition FingerTreap.h:264
PathIterator< FingerTreap, Shape > const_iterator
the constant iterator by increasing key, along the path from the root
Definition FingerTreap.h:268
K Key
the type of the keys
Definition FingerTreap.h:102
PairRef< const K &, const V & > reference
references, by value
Definition FingerTreap.h:265
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)
std::optional< V > lookupFrom(const K &k, Finger f) const
the value of , or nothing, by a search from , in expected time, the keys between and that of (the...
std::size_t size_type
the type of the sizes
Definition FingerTreap.h:263
const_iterator cbegin(void) const
as begin()
Definition FingerTreap.h:280
FingerTreap(const FingerTreap &)=delete
no copy, since the nodes are linked by pointers
std::optional< V > lookup(const K &k) const
the value of , or nothing, from the root, in expected time
std::size_t rank(const K &k) const
the number of keys smaller than , by the sizes
std::pair< K, V > value_type
the pairs ( key , value ) by value, which own their copies
Definition FingerTreap.h:258
FingerTreap(std::uint64_t seed=1)
the empty treap, its priorities drawn from the seed
Definition FingerTreap.h:120
FingerTreap & operator=(const FingerTreap &)=delete
no copy, since the nodes are linked by pointers
void forEach(F &&f) const
f( k , v ) on the pairs by increasing keys
reference const_reference
the same
Definition FingerTreap.h:266
std::pair< K, V > select(std::size_t i) const
the pair of rank , by the sizes, as Treap::select()
K key_type
the type of the keys
Definition FingerTreap.h:260
const_iterator begin(void) const
the iterator on the smallest key
Definition FingerTreap.h:272
const_iterator cend(void) const
as end()
Definition FingerTreap.h:282
int height(void) const
the height, if empty, in
~FingerTreap()
frees the nodes
std::optional< V > fingerLookup(const K &k)
the value of , or nothing, by a search from the node of the last fingerLookup(), which becomes the no...
V Value
the type of the values
Definition FingerTreap.h:103
std::size_t size(void) const
the number of keys
Definition FingerTreap.h:191
const_iterator iterator
the constant iterator
Definition FingerTreap.h:269
V mapped_type
the type of the values
Definition FingerTreap.h:262
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...
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...
FingerTreap(FingerTreap &&other) noexcept
the nodes of other, which is left empty
Definition FingerTreap.h:129
Finger finger(const K &k) const
the node of , or the last node of its search from the root, as a finger
a bidirectional iterator on the nodes of a binary tree of the owner O in symmetric order,...
Definition Iterators.h:867
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
long search(const S &s, const typename S::Item &v)
the place of counted from 0, or
the shape of the tree, for PathIterator
Definition FingerTreap.h:244
static auto read(const auto *n)
the pair of the node n
Definition FingerTreap.h:252
static auto right(const auto *n)
the right child of the node n
Definition FingerTreap.h:250
static auto root(const auto &o)
the root of the tree o
Definition FingerTreap.h:246
static auto left(const auto *n)
the left child of the node n
Definition FingerTreap.h:248