66#ifndef __ADS_SpaceEfficientSortedSet
67 #define __ADS_SpaceEfficientSortedSet
96template< std::totally_ordered T >
97 requires std::semiregular< T >
108 std::uint64_t seed = 1 );
121 [[nodiscard]] std::size_t
size(
void )
const {
return( f_size ); }
124 [[nodiscard]]
bool empty(
void )
const {
return( f_size == 0 ); }
128 return( f_blocks * ( f_b + 1 ) );
136 [[nodiscard]]
const T *
find(
const T & x )
const;
231 std::unique_ptr< T[] > a;
234 Block * prev =
nullptr;
235 Block * next =
nullptr;
246 const T & item(
void )
const {
return( b ? o->at( b , b->s - 1 ) : *x ); }
248 friend bool operator==(
const Key & p ,
const Key & q ) {
249 return( p.item() == q.item() );
252 friend bool operator<(
const Key & p ,
const Key & q ) {
253 return( p.item() < q.item() );
256 friend bool operator>(
const Key & p ,
const Key & q ) {
return( q < p ); }
258 friend bool operator<=(
const Key & p ,
const Key & q ) {
259 return( ! ( q < p ) );
262 friend bool operator>=(
const Key & p ,
const Key & q ) {
263 return( ! ( p < q ) );
268 const T & at(
const Block * B , std::size_t i )
const {
269 return( B->a[ ( B->h + i ) % ( f_b + 1 ) ] );
272 T & at( Block * B , std::size_t i ) {
273 return( B->a[ ( B->h + i ) % ( f_b + 1 ) ] );
277 Block * blockOf(
const T & x )
const;
280 std::size_t place(
const Block * B ,
const T & x )
const;
283 Block * newBlock( Block * B );
286 void freeBlock( Block * B );
289 void shiftForward( Block * B , Block * C );
292 void shiftBack( Block * B , Block * C );
295 [[nodiscard]]
bool valid(
void )
const;
298 std::size_t f_size = 0;
299 std::size_t f_blocks = 0;
300 Block * f_first =
nullptr;
301 Block * f_last =
nullptr;
302 SkipList< Key , Block * > f_index;
314#include "ADS/set/impl/SpaceEfficientSortedSet.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The skip list of Pugh, beyond the book: a sorted list of the keys with express lanes,...
a SET of ordered items in blocks of about items, indexed by a skip list, the SESSet of Morin
Definition SpaceEfficientSortedSet.h:99
bool contains(const T &x) const
true if is an item, by lowerBound()
const T * lowerBound(const T &x) const
the address of the smallest item not smaller than , nil if there is none (the find(x) of an SSet),...
bool empty(void) const
true if there is no item
Definition SpaceEfficientSortedSet.h:124
std::size_t capacity(void) const
the number of places of the blocks,
Definition SpaceEfficientSortedSet.h:127
T Item
the type of the items
Definition SpaceEfficientSortedSet.h:103
std::size_t size(void) const
the number of items
Definition SpaceEfficientSortedSet.h:121
SpaceEfficientSortedSet & operator=(const SpaceEfficientSortedSet &)=delete
no copy, since the blocks are linked by pointers
SpaceEfficientSortedSet(std::size_t b=32, std::uint64_t seed=1)
the empty set, with blocks of places
const T * find(const T &x) const
the address of the item equal to , nil if there is none (the find(x) of a USet), valid until the next...
bool remove(const T &x)
removed, if it is there, in amortized expected time: a block left with items takes the first item o...
bool insert(const T &x)
added, if it is not there, in amortized expected time; true if it was not there
~SpaceEfficientSortedSet()
frees the blocks
SpaceEfficientSortedSet(const SpaceEfficientSortedSet &)=delete
no copy, since the blocks are linked by pointers
void forEach(F &&f) const
f( x ) on the items in increasing order