36#ifndef __ADS_SplayTree
37 #define __ADS_SplayTree
66template< std::totally_ordered K ,
class V >
120 [[nodiscard]] std::optional< V >
lookup(
const K & k );
144 void insert(
const K & k ,
const V & v );
174 [[nodiscard]] std::optional< std::pair< K , V > >
lowerBound(
const K & k );
179 [[nodiscard]]
const K *
findKey(
const K & k );
188 [[nodiscard]] std::size_t
size(
void )
const;
191 [[nodiscard]] std::optional< K >
root(
void )
const;
204 Node *left = nullptr ,
219 static auto root(
const auto & o ) {
return( o.f_root ); }
221 static auto left(
const auto * n ) {
return( n->left ); }
223 static auto right(
const auto * n ) {
return( n->right ); }
225 static auto read(
const auto * n ) {
259 static Node * splay( Node * t ,
const K & k );
261 static void destroy( Node * t );
264 static void visit(
const Node * t , F & f );
266 static bool ordered(
const Node * t ,
const K * lo ,
const K * hi );
290 Node * lowerBoundNode(
const K & k );
292 Node * f_root =
nullptr;
293 std::size_t f_size = 0;
305#include "ADS/tree/impl/SplayTree.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...
a bidirectional iterator on the nodes of a binary tree of the owner O in symmetric order,...
Definition Iterators.h:867
~SplayTree()
frees the nodes
bool contains(const K &k)
true if is there; , or the last node on its path, goes to the root, in amortized time
void forEach(F &&f) const
f( k , v ) on the pairs by increasing keys
V mapped_type
the type of the values
Definition SplayTree.h:235
const_iterator iterator
the constant iterator
Definition SplayTree.h:242
SplayTree & operator=(const SplayTree &)=delete
no copy
V Value
the type of the values
Definition SplayTree.h:73
K Key
the type of the keys
Definition SplayTree.h:72
reference const_reference
the same
Definition SplayTree.h:239
const K * findKey(const K &k)
the address of the key , nil if absent, splayed as by lookup() in amortized time: the find( x ) of a...
const_iterator end(void) const
the iterator past the largest key
Definition SplayTree.h:249
SplayTree(const SplayTree &)=delete
no copy
void remove(const K &k)
removes , if it is there, in amortized time
std::ptrdiff_t difference_type
the type of the distances
Definition SplayTree.h:237
std::optional< V > lookup(const K &k)
the value of , or nothing; , or the last node on its path, goes to the root, in amortized time
PairRef< const K &, const V & > reference
references, by value
Definition SplayTree.h:238
const K * lowerBoundKey(const K &k)
the address of the smallest key not smaller than , nil if none, by lowerBoundNode() in amortized tim...
void insert(const K &k, const V &v)
associates to , which goes to the root, in amortized time
const_iterator begin(void) const
the iterator on the smallest key
Definition SplayTree.h:245
const_iterator cend(void) const
as end()
Definition SplayTree.h:255
const_iterator cbegin(void) const
as begin()
Definition SplayTree.h:253
std::size_t size_type
the type of the sizes
Definition SplayTree.h:236
PathIterator< SplayTree, Shape > const_iterator
the constant iterator by increasing key, along the path from the root
Definition SplayTree.h:241
SplayTree(void)=default
the empty tree
SplayTree(SplayTree &&other) noexcept
the nodes of other, which is left empty
std::pair< K, V > value_type
the pairs ( key , value ) by value, which own their copies
Definition SplayTree.h:231
std::optional< std::pair< K, V > > lowerBound(const K &k)
the smallest key not smaller than and its value, or nothing (the find( x ) of an SSet of Morin),...
K key_type
the type of the keys
Definition SplayTree.h:233
std::optional< K > root(void) const
the key at the root, if any
std::size_t size(void) const
the number of keys
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 SplayTree.h:217
static auto root(const auto &o)
the root of the tree o
Definition SplayTree.h:219
static auto left(const auto *n)
the left child of the node n
Definition SplayTree.h:221
static auto read(const auto *n)
the pair of the node n
Definition SplayTree.h:225
static auto right(const auto *n)
the right child of the node n
Definition SplayTree.h:223