69 #define __ADS_SkipList
103template< std::totally_ordered K ,
class V >
153 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
177 void insert(
const K & k ,
const V & v );
205 [[nodiscard]] std::size_t
size(
void )
const;
208 [[nodiscard]]
bool empty(
void )
const {
return( f_size == 0 ); }
219 static constexpr int kMax = 32;
231 static constexpr std::size_t kTower =
232 (
sizeof( Node ) +
alignof( Node * ) - 1 ) /
alignof( Node * ) *
236 static Node ** tower( Node * x ) {
237 return( std::launder(
reinterpret_cast< Node **
>(
238 reinterpret_cast< std::byte *
>( x ) + kTower ) ) );
270 return(
reference( f_x->key , f_x->value ) );
274 f_x = tower( f_x )[ 0 ];
288 Node * f_x =
nullptr;
331 [[nodiscard]]
const K *
findKey(
const K & k )
const;
372 Node * before(
const K & k , Node * update[ kMax ] )
const;
375 Node ** towerOf( Node * x )
const {
376 return( x ? tower( x ) :
const_cast< Node **
>( f_head ) );
380 static Node * make(
const K & k ,
const V & v ,
int L );
383 static void dispose( Node * x )
noexcept;
386 [[nodiscard]]
bool sorted(
void )
const;
388 Node * f_head[ kMax ] = {};
389 Node * f_finger[ kMax ] = {};
391 std::size_t f_size = 0;
404#include "ADS/dictionary/impl/SkipList.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 SkipList.h:249
std::forward_iterator_tag iterator_concept
the concept of the iterator, for C++20
Definition SkipList.h:258
std::pair< K, V > value_type
the type of the items, for the standard library
Definition SkipList.h:254
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition SkipList.h:256
reference operator*(void) const
the pair of the node
Definition SkipList.h:269
std::input_iterator_tag iterator_category
the category of the iterator
Definition SkipList.h:260
PairRef< const K &, const V & > reference
a reference to an item
Definition SkipList.h:252
const_iterator & operator++(void)
to the next node of the bottom level
Definition SkipList.h:273
const_iterator(Node *x)
on the pair of the node
Definition SkipList.h:266
const_iterator(void)=default
the end
bool operator==(const const_iterator &o) const =default
equal on the same node
const_iterator operator++(int)
to the next node, returning the iterator before the step
Definition SkipList.h:278
~SkipList()
frees the memory of the structure
V Value
the type of the values
Definition SkipList.h:110
PairRef< const K &, const V & > reference
a reference to an item
Definition SkipList.h:302
const_iterator lowerBound(const K &k) const
the iterator on the smallest key not smaller than , end() if there is none (the find(x) of an SSet of...
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition SkipList.h:300
const_iterator cend(void) const
the constant iterator past the last item
Definition SkipList.h:319
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...
SkipList(const SkipList &)=delete
no copy, since the nodes are linked by pointers
void forEach(F &&f) const
f( k , v ) on the pairs by increasing keys
std::pair< K, V > value_type
the type of the items, for the standard library
Definition SkipList.h:292
V mapped_type
the type of the values
Definition SkipList.h:296
std::size_t size_type
the type of the sizes
Definition SkipList.h:298
bool empty(void) const
true if there is no key
Definition SkipList.h:208
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...
std::optional< V > fingerLookup(const K &k)
the value of , or nothing, by a finger search from the key of the previous fingerLookup(),...
K key_type
the type of the keys
Definition SkipList.h:294
SkipList(SkipList &&other) noexcept
the nodes of other, which is left empty
std::size_t size(void) const
the number of keys
const_iterator begin(void) const
the iterator on the first item
Definition SkipList.h:309
reference const_reference
a constant reference to an item
Definition SkipList.h:304
SkipList & operator=(const SkipList &)=delete
no copy, since the nodes are linked by pointers
void remove(const K &k)
removes the key , if it is there, unlinking its node from each of its levels after before( k ) and dr...
int levels(void) const
the number of levels in use
std::optional< V > lookup(const K &k) const
the value of the key , or nothing, in expected time
void insert(const K &k, const V &v)
associates the value to the key , in expected time
SkipList(std::uint64_t seed=1)
the empty list, its levels drawn by a generator from the seed
const_iterator end(void) const
the iterator past the last item
Definition SkipList.h:313
const_iterator iterator
the iterator on the items
Definition SkipList.h:306
K Key
the type of the keys
Definition SkipList.h:109
const_iterator cbegin(void) const
the constant iterator on the first item
Definition SkipList.h:317
bool contains(const K &k) const
true if the key is there
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