46#ifndef __ADS_IndexedSkipList
47 #define __ADS_IndexedSkipList
82template< std::totally_ordered K ,
class V >
108 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
135 void insert(
const K & k ,
const V & v );
169 [[nodiscard]] std::size_t
size(
void )
const {
return( f_size ); }
172 [[nodiscard]]
bool empty(
void )
const {
return( f_size == 0 ); }
176 [[nodiscard]] std::size_t
rank(
const K & k )
const;
184 static constexpr int kMax = 32;
204 static constexpr std::size_t kTower =
205 (
sizeof( Node ) +
alignof( Link ) - 1 ) /
alignof( Link ) *
209 static Link * tower( Node * x ) {
210 return( std::launder(
reinterpret_cast< Link *
>(
211 reinterpret_cast< std::byte *
>( x ) + kTower ) ) );
240 return(
reference( f_x->key , f_x->value ) );
244 f_x = tower( f_x )[ 0 ].next;
258 Node * f_x =
nullptr;
293 [[nodiscard]]
const K *
findKey(
const K & k )
const;
320 Link * towerOf( Node * x )
const {
321 return( x ? tower( x ) :
const_cast< Link *
>( f_head ) );
326 Node * before(
const K & k , Node * update[ kMax ] ,
327 std::size_t
rank[ kMax ] )
const;
330 static Node * make(
const K & k ,
const V & v ,
int L );
333 static void dispose( Node * x )
noexcept;
336 [[nodiscard]]
bool valid(
void )
const;
340 std::size_t f_size = 0;
353#include "ADS/dictionary/impl/IndexedSkipList.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:
the iterator on the pairs, along the bottom level
Definition IndexedSkipList.h:219
const_iterator operator++(int)
to the next node, returning the iterator before the step
Definition IndexedSkipList.h:248
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition IndexedSkipList.h:226
std::input_iterator_tag iterator_category
the category of the iterator
Definition IndexedSkipList.h:230
bool operator==(const const_iterator &o) const =default
equal on the same node
const_iterator(void)=default
the end
reference operator*(void) const
the pair of the node
Definition IndexedSkipList.h:239
std::forward_iterator_tag iterator_concept
the concept of the iterator, for C++20
Definition IndexedSkipList.h:228
const_iterator(Node *x)
on the pair of the node
Definition IndexedSkipList.h:236
PairRef< const K &, const V & > reference
a reference to an item
Definition IndexedSkipList.h:222
std::pair< K, V > value_type
the type of the items, for the standard library
Definition IndexedSkipList.h:224
const_iterator & operator++(void)
to the next node of the bottom level
Definition IndexedSkipList.h:243
PairRef< const K &, const V & > reference
references, by value
Definition IndexedSkipList.h:269
K key_type
the type of the keys
Definition IndexedSkipList.h:264
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...
bool empty(void) const
true if there is no key
Definition IndexedSkipList.h:172
IndexedSkipList(const IndexedSkipList &)=delete
no copy, since the nodes are linked by pointers
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...
std::size_t size_type
the type of the sizes
Definition IndexedSkipList.h:267
void remove(const K &k)
removes , if it is there, in expected time: on each level of its node the link that reaches it is re...
const_iterator cend(void) const
as end()
Definition IndexedSkipList.h:284
IndexedSkipList(std::uint64_t seed=1)
the empty list, its levels drawn by a generator from the seed
IndexedSkipList(IndexedSkipList &&other) noexcept
the nodes of other, which is left empty
const_iterator end(void) const
the iterator past the largest key
Definition IndexedSkipList.h:278
std::size_t size(void) const
the number of keys
Definition IndexedSkipList.h:169
const_iterator begin(void) const
the iterator on the smallest key
Definition IndexedSkipList.h:274
V Value
the type of the values
Definition IndexedSkipList.h:89
bool contains(const K &k) const
true if is there
const_iterator select(std::size_t i) const
the iterator on the key of rank , i.e., with keys smaller than it, in expected time (the get(i) of ...
void forEach(F &&f) const
f( k , v ) on the pairs by increasing keys
std::size_t rank(const K &k) const
the number of keys smaller than , the sum of the widths along the search of , in expected time
std::ptrdiff_t difference_type
the distances
Definition IndexedSkipList.h:268
IndexedSkipList & operator=(const IndexedSkipList &)=delete
no copy, since the nodes are linked by pointers
V mapped_type
the type of the values
Definition IndexedSkipList.h:266
K Key
the type of the keys
Definition IndexedSkipList.h:88
reference const_reference
the same
Definition IndexedSkipList.h:270
const_iterator iterator
the constant iterator
Definition IndexedSkipList.h:271
std::optional< V > lookup(const K &k) const
the value of , or nothing, by the search of SkipList, in expected time
std::pair< K, V > value_type
the type of the items, for the standard library
Definition IndexedSkipList.h:262
~IndexedSkipList()
frees the memory of the structure
void insert(const K &k, const V &v)
associates to , in expected time
const_iterator cbegin(void) const
as begin()
Definition IndexedSkipList.h:282
const_iterator lowerBound(const K &k) const
the iterator on the smallest key not smaller than (the find(x) of an SSet of Morin),...
the generator SplitMix64, a UniformRandomBitGenerator
Definition RandomHashing.h:122
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