60#ifndef __ADS_MeldableHeap
61 #define __ADS_MeldableHeap
92template<
class T ,
class Less = std::less< T > ,
93 class A = std::allocator< T > >
106 const A & alloc = A() );
128 [[nodiscard]]
const T &
top(
void )
const;
191 [[nodiscard]] std::vector< T >
smallest( std::size_t k )
const;
194 [[nodiscard]] std::size_t
size(
void )
const {
return( f_n ); }
197 [[nodiscard]]
bool empty(
void )
const {
return( f_n == 0 ); }
208 Node * left =
nullptr;
209 Node * right =
nullptr;
210 Node * parent =
nullptr;
214 typename std::allocator_traits< A >::template rebind_alloc< Node >;
215 using Traits = std::allocator_traits< NodeAlloc >;
244 Node *
merge( Node * a , Node * b );
247 Node * make( T && x );
250 void drop( Node * u );
254 [[nodiscard]]
bool subtree(
const Node * u , std::size_t & n )
const;
258 [[nodiscard]]
bool consistent(
void )
const;
260 Node * f_root =
nullptr;
264 std::uint64_t f_bits = 0;
278#include "ADS/priority/impl/MeldableHeap.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
Hashing with random tables, beyond the book:
bool empty(void) const
true if there are no items
Definition MeldableHeap.h:197
T pop(void)
removes the smallest item and returns it, merging the two subtrees of the root, in expected time
static const T & get(Handle h)
the item of the handle
MeldableHeap(const MeldableHeap &)=delete
~MeldableHeap()
frees the nodes
const T & top(void) const
the smallest item
MeldableHeap(MeldableHeap &&o) noexcept
the heap of o, which is left empty
const T * secondTop(void) const
the second smallest item, the smaller child of the root, or nil if there are fewer than two items (ex...
T erase(Handle h)
removes the item of the handle and returns it, merging the two subtrees of its node in its place,...
void clear(void)
removes every item
MeldableHeap & operator=(const MeldableHeap &)=delete
Node * Handle
what push() gives, for erase()
Definition MeldableHeap.h:102
Handle push(T x)
adds , merging the heap with a heap of one node, in expected time; the handle of its node
std::vector< T > smallest(std::size_t k) const
the smallest items in increasing order, or all of them if fewer, in time (exercise 10....
MeldableHeap & operator=(MeldableHeap &&o) noexcept
the heap of o, which gets the items of this one
std::size_t size(void) const
the number of items
Definition MeldableHeap.h:194
void meld(MeldableHeap &o)
moves the items of o into this heap, in expected time; o is left empty, and its handles become handl...
MeldableHeap(Less less=Less(), std::uint64_t seed=1, const A &alloc=A())
the empty heap of the order less, its coins drawn from the seed
T Item
the type of the items
Definition MeldableHeap.h:101
the generator SplitMix64, a UniformRandomBitGenerator
Definition RandomHashing.h:122
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
SortedListSet< T > merge(const SortedListSet< T > &A, const SortedListSet< T > &B, bool a, bool b, bool both)
the merge of the sorted lists of and : an item of only, of only or of both goes into the result if...