62#ifndef __ADS_HashedTreap
63 #define __ADS_HashedTreap
95template< std::totally_ordered K ,
class V >
108 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
136 void insert(
const K & k ,
const V & v );
172 [[nodiscard]] std::size_t
size(
void )
const {
return( f_size ); }
179 [[nodiscard]] std::optional< std::pair< K , V > >
185 [[nodiscard]]
const K *
findKey(
const K & k )
const;
203 std::unique_ptr< Node > left ,
214 static auto root(
const auto & o ) {
return( o.f_root.get() ); }
216 static auto left(
const auto * n ) {
return( n->left.get() ); }
218 static auto right(
const auto * n ) {
return( n->right.get() ); }
220 static auto read(
const auto * n ) {
253 using Ptr = std::unique_ptr< Node >;
256 std::uint64_t priority(
const Node * u )
const {
257 return( f_h( std::uint64_t(
reinterpret_cast< std::uintptr_t
>( u ) ) ) );
259 static void rotateRight( Ptr & t );
260 static void rotateLeft( Ptr & t );
261 int insert( Ptr & t ,
const K & k ,
const V & v );
262 bool remove( Ptr & t ,
const K & k );
263 static int height(
const Ptr & t );
264 bool valid(
const Ptr & t ,
const K * lo ,
const K * hi )
const;
268 std::size_t f_size = 0;
282#include "ADS/tree/impl/HashedTreap.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:
const_iterator iterator
the constant iterator
Definition HashedTreap.h:237
const_iterator cend(void) const
as end()
Definition HashedTreap.h:250
void forEach(F &&f) const
f( k , v ) on the pairs by increasing keys
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 > lookup(const K &k) const
the value of , or nothing, in expected time
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...
K key_type
the type of the keys
Definition HashedTreap.h:228
std::ptrdiff_t difference_type
the type of the distances
Definition HashedTreap.h:232
std::pair< K, V > value_type
the pairs ( key , value ) by value, which own their copies
Definition HashedTreap.h:226
void remove(const K &k)
removes , if it is there, in expected time, by the removal of Treap::remove() with
const_iterator cbegin(void) const
as begin()
Definition HashedTreap.h:248
std::size_t size(void) const
the number of keys
Definition HashedTreap.h:172
const_iterator end(void) const
the iterator past the largest key
Definition HashedTreap.h:244
PathIterator< HashedTreap, Shape > const_iterator
the constant iterator by increasing key, along the path from the root
Definition HashedTreap.h:236
K Key
the type of the keys
Definition HashedTreap.h:101
HashedTreap(std::uint64_t seed=1)
the empty treap, the tables of its hash drawn from the seed
Definition HashedTreap.h:105
std::size_t size_type
the type of the sizes
Definition HashedTreap.h:231
V Value
the type of the values
Definition HashedTreap.h:102
int height(void) const
the height, if empty, in
V mapped_type
the type of the values
Definition HashedTreap.h:230
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...
PairRef< const K &, const V & > reference
references, by value
Definition HashedTreap.h:233
bool contains(const K &k) const
true if is there
void insert(const K &k, const V &v)
associates to , in expected time, by the insertion of Treap::insert() with
reference const_reference
the same
Definition HashedTreap.h:234
const_iterator begin(void) const
the iterator on the smallest key
Definition HashedTreap.h:240
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
the shape of the tree, for PathIterator
Definition HashedTreap.h:212
static auto root(const auto &o)
the root of the tree o
Definition HashedTreap.h:214
static auto read(const auto *n)
the pair of the node n
Definition HashedTreap.h:220
static auto left(const auto *n)
the left child of the node n
Definition HashedTreap.h:216
static auto right(const auto *n)
the right child of the node n
Definition HashedTreap.h:218