62#ifndef __ADS_SkipListSequence
63 #define __ADS_SkipListSequence
120 [[nodiscard]] std::size_t
size(
void )
const {
return( f_size ); }
123 [[nodiscard]]
bool empty(
void )
const {
return( f_size == 0 ); }
126 [[nodiscard]]
int levels(
void )
const {
return( f_levels ); }
144 [[nodiscard]]
const T &
get( std::size_t i )
const;
149 void set( std::size_t i ,
const T & v );
172 void add( std::size_t i ,
const T & v );
185 return( nodeAt( i )->item );
191 void insert( std::size_t i ,
const T & v ) {
add( i , v ); }
274 static constexpr int kMax = 32;
293 static constexpr std::size_t kTower =
294 (
sizeof( Node ) +
alignof( Link ) - 1 ) /
alignof( Link ) *
298 static Link * tower( Node * x ) {
299 return( std::launder(
reinterpret_cast< Link *
>(
300 reinterpret_cast< std::byte *
>( x ) + kTower ) ) );
307 template<
bool Const >
314 using reference = std::conditional_t< Const , const T & , T & >;
335 f_x = tower( f_x )[ 0 ].next;
349 Node * f_x =
nullptr;
362 return(
iterator( f_head[ 0 ].next ) );
381 Link * towerOf( Node * x )
const {
382 return( x ? tower( x ) :
const_cast< Link *
>( f_head ) );
386 Node * nodeAt( std::size_t i )
const;
389 static Node * make(
const T & v ,
int L );
392 static void dispose( Node * x )
noexcept;
395 void clearHead(
void );
398 [[nodiscard]]
bool valid(
void )
const;
402 std::size_t f_size = 0;
415#include "ADS/sequence/impl/SkipListSequence.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
Hashing with random tables, beyond the book:
std::conditional_t< Const, const T &, T & > reference
a reference to an item
Definition SkipListSequence.h:314
reference operator*(void) const
the item of the node
Definition SkipListSequence.h:332
basic_iterator(Node *x)
on the node
Definition SkipListSequence.h:324
bool operator==(const basic_iterator &o) const =default
equal on the same node
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition SkipListSequence.h:316
basic_iterator & operator++(void)
to the next node of the bottom level
Definition SkipListSequence.h:334
basic_iterator(void)=default
the end
std::forward_iterator_tag iterator_category
the concept and the category of the iterator
Definition SkipListSequence.h:318
basic_iterator operator++(int)
to the next node, returning the iterator before the step
Definition SkipListSequence.h:339
T value_type
the type of the items
Definition SkipListSequence.h:312
SkipListSequence(SkipListSequence &&other) noexcept
the nodes of other, which is left empty
SkipListSequence(const SkipListSequence &)=delete
no copy, since the nodes are linked by pointers
std::ptrdiff_t difference_type
the distances
Definition SkipListSequence.h:354
iterator begin(void)
the iterator on the first item
Definition SkipListSequence.h:361
basic_iterator< true > const_iterator
the constant iterator
Definition SkipListSequence.h:358
const T & const_reference
a constant reference
Definition SkipListSequence.h:356
SkipListSequence truncate(std::size_t i)
the items of index to taken out and returned as a sequence, in expected time (exercise 4....
basic_iterator< false > iterator
the iterator
Definition SkipListSequence.h:357
const_iterator end(void) const
the constant iterator past the last item
Definition SkipListSequence.h:371
void push_back(const T &v)
appended, add( size() , v )
Definition SkipListSequence.h:199
T & reference
a reference to an item
Definition SkipListSequence.h:355
const T & get(std::size_t i) const
the item of index , in expected time
iterator end(void)
the iterator past the last item
Definition SkipListSequence.h:365
const_iterator begin(void) const
the constant iterator on the first item
Definition SkipListSequence.h:367
T value_type
the items
Definition SkipListSequence.h:352
const_iterator cend(void) const
as end()
Definition SkipListSequence.h:377
std::size_t size(void) const
the number of items
Definition SkipListSequence.h:120
SkipListSequence(std::uint64_t seed=detail::instanceSeed())
the empty sequence, its levels drawn by a generator from the seed, by default one of its own [see det...
SkipListSequence & operator=(const SkipListSequence &)=delete
no copy, since the nodes are linked by pointers
int levels(void) const
the number of levels in use
Definition SkipListSequence.h:126
void absorb(SkipListSequence &s)
the items of appended, in order, and left empty, in expected time (exercise 4.12 of Morin)
void insert(std::size_t i, const T &v)
inserted at , add( i , v ) (the name of IndexedList)
Definition SkipListSequence.h:191
void add(std::size_t i, const T &v)
inserted at the index , the items from on moving one place up, in expected time
T Item
the type of the items
Definition SkipListSequence.h:101
T remove(std::size_t i)
the item of index removed and returned, the items after it moving one place down,...
std::size_t size_type
the type of the sizes
Definition SkipListSequence.h:353
bool empty(void) const
true if there is no item
Definition SkipListSequence.h:123
~SkipListSequence()
frees the memory of the structure
void erase(std::size_t i)
the item of index removed, remove( i ) (the name of IndexedList)
Definition SkipListSequence.h:196
void set(std::size_t i, const T &v)
the item of index replaced by , by the search of get()
const T & operator[](std::size_t i) const
the item of index , as get( i ) (the name of IndexedList)
Definition SkipListSequence.h:176
const_iterator cbegin(void) const
as begin()
Definition SkipListSequence.h:375
T & operator[](std::size_t i)
the item of index , to be read or written, by the search of get()
Definition SkipListSequence.h:183
#define ADS_PRE(cond)
[check]
Definition Contract.h:121