93 #define __ADS_DaryHeap
125template<
class T ,
class Better = std::less< T > ,
unsigned D = 4 ,
126 bool BottomUp = false ,
class A = HugePageAllocator< T > >
130 static_assert( D >= 2 ,
"a heap needs at least two children per node" );
137 explicit DaryHeap( Better better = Better() ,
const A & alloc = A() );
159 [[nodiscard]]
const T &
top(
void )
const;
236 [[nodiscard]] std::vector< T >
smallest( std::size_t k )
const;
241 [[nodiscard]]
static constexpr std::size_t
parent( std::size_t i ) {
242 return( ( i - 1 ) / D );
247 [[nodiscard]]
static constexpr std::size_t
child( std::size_t i ,
249 return( D * i + j + 1 );
253 [[nodiscard]]
bool empty(
void )
const;
256 [[nodiscard]] std::size_t
size(
void )
const;
282 template< std::input_iterator I , std::sentinel_for< I > S >
316 return( f_A.data() + f_A.size() );
329 void up( std::size_t i , T x );
331 void down( std::size_t i , T x );
335 void bottomUp( T x );
339 [[nodiscard]]
bool ordered(
void )
const;
342 detail::AllocVector< A , T > f_A;
355#include "ADS/priority/impl/DaryHeap.tpp"
The rules of the allocator-aware containers of the standard ([container.reqmts], [allocator....
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
An allocator for the large blocks of a structure, beyond the book: a request of at least one huge pag...
void assign(I first, S last)
the items of in place of those of the heap, arranged by the construction of Floyd in time for item...
void clear(void)
removes all the items
std::ptrdiff_t difference_type
Definition DaryHeap.h:296
DaryHeap(Better better=Better(), const A &alloc=A())
the empty heap of the order better, its vector from alloc
const_iterator cbegin(void) const
the same as begin()
Definition DaryHeap.h:319
const_iterator cend(void) const
the same as end()
Definition DaryHeap.h:321
void reserve(std::size_t n)
room for items, so that the pushes up to do not reallocate
std::size_t size_type
Definition DaryHeap.h:294
const_iterator end(void) const
the end of the view
Definition DaryHeap.h:315
static constexpr std::size_t parent(std::size_t i)
the parent of the place , (the layout of Eytzinger with children, exercise 10.4 of Morin's book)
Definition DaryHeap.h:241
allocator_type get_allocator(void) const
the allocator of the vector
Definition DaryHeap.h:308
E Item
Definition DaryHeap.h:134
T pop(void)
removes the best item and returns it, the last item moved down from the root, in time
HugePageAllocator< E > allocator_type
Definition DaryHeap.h:306
E value_type
Definition DaryHeap.h:292
std::size_t size(void) const
the number of items,
static constexpr std::size_t child(std::size_t i, std::size_t j)
the child of the place , (exercise 10.4 of Morin's book)
Definition DaryHeap.h:247
const_iterator begin(void) const
the first item of the view
Definition DaryHeap.h:313
bool empty(void) const
whether the heap has no item
const E & reference
Definition DaryHeap.h:298
const E * const_iterator
Definition DaryHeap.h:304
const E & const_reference
Definition DaryHeap.h:300
const E * iterator
Definition DaryHeap.h:302
void push(const T &x)
pushes , moving it up while better than its parent, in time
std::vector< T > smallest(std::size_t k) const
the best items in order, or all of them if fewer, in time (exercise 10.10 of Morin's book)
const T * secondTop(void) const
the second best item, the best of the children of the root, or nil if there are fewer than two items,...
const T & top(void) const
the best item
T erase(std::size_t i)
removes the item in the place of the view and returns it, in time: the last item takes its place an...