ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::FibonacciHeapPriorityQueue< T, P, A > Class Template Reference

a priority queue on a Fibonacci heap, a collection of trees heap ordered whose roots are in a circular list More...

#include <ADS/priority/FibonacciHeapPriorityQueue.h>

Classes

struct  Node
 a node of the heap More...
class  const_iterator
 the iterator of the view, constant, forward More...

Public types

using Item = T
 the type of the items
using Priority = P
 the type of the priorities
using Handle = Node *
 what insert() gives
using allocator_type = A
 the type of the allocator
using value_type = std::pair< P , T >
 the type of the items of the view
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the type of the distances between iterators
using reference = PairRef< const P & , const T & >
 the type of a reference to an item of the view
using const_reference = reference
 the type of a constant reference to an item
using iterator = const_iterator
 the same as const_iterator

Public member functions

 FibonacciHeapPriorityQueue (void)=default
 the empty heap
 FibonacciHeapPriorityQueue (const A &alloc)
 the empty queue, the blocks of its nodes from alloc
allocator_type get_allocator (void) const
 the allocator of the blocks of the nodes
 FibonacciHeapPriorityQueue (const FibonacciHeapPriorityQueue &)=delete
 no copy: the handles point into the heap
FibonacciHeapPriorityQueue & operator= (const FibonacciHeapPriorityQueue &)=delete
 no copy: the handles point into the heap
 FibonacciHeapPriorityQueue (FibonacciHeapPriorityQueue &&other) noexcept
 the items of other, which is left empty; its handles stay valid here
 ~FibonacciHeapPriorityQueue ()
 the heap and its nodes destroyed
bool empty (void) const
 whether the heap has no item
int size (void) const
 the number of items, \( n \)
const T & min (void) const
 the item of smallest priority, the least of the roots
const P & minPriority (void) const
 the smallest priority
Handle insert (const T &x, const P &p)
 inserts \( x \) with the priority \( p \) and gives its handle, a tree of one node among the roots, in \( O( 1 ) \) time
T deleteMin (void)
 removes the item of smallest priority and returns it, in \( O( \log n ) \) amortized time; the handle of the item is no longer valid
void decrease (Handle x, const P &p)
 lowers to \( p \) the priority of the node \( x \), in \( O( 1 ) \) amortized time
const_iterator begin (void) const
 the first item of the view
const_iterator end (void) const
 the end of the view
const_iterator cbegin (void) const
 the same as begin()
const_iterator cend (void) const
 the same as end()

Detailed description

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
class ADS::FibonacciHeapPriorityQueue< T, P, A >

a priority queue on a Fibonacci heap, a collection of trees heap ordered whose roots are in a circular list

Member typedef documentation

◆ allocator_type

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
using ADS::FibonacciHeapPriorityQueue< T, P, A >::allocator_type = A

the type of the allocator

◆ const_reference

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
using ADS::FibonacciHeapPriorityQueue< T, P, A >::const_reference = reference

the type of a constant reference to an item

◆ difference_type

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
using ADS::FibonacciHeapPriorityQueue< T, P, A >::difference_type = std::ptrdiff_t

the type of the distances between iterators

◆ Handle

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
using ADS::FibonacciHeapPriorityQueue< T, P, A >::Handle = Node *

what insert() gives

◆ Item

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
using ADS::FibonacciHeapPriorityQueue< T, P, A >::Item = T

the type of the items

◆ iterator

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
using ADS::FibonacciHeapPriorityQueue< T, P, A >::iterator = const_iterator

the same as const_iterator

◆ Priority

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
using ADS::FibonacciHeapPriorityQueue< T, P, A >::Priority = P

the type of the priorities

◆ reference

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
using ADS::FibonacciHeapPriorityQueue< T, P, A >::reference = PairRef< const P & , const T & >

the type of a reference to an item of the view

◆ size_type

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
using ADS::FibonacciHeapPriorityQueue< T, P, A >::size_type = std::size_t

the type of the sizes

◆ value_type

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
using ADS::FibonacciHeapPriorityQueue< T, P, A >::value_type = std::pair< P , T >

the type of the items of the view

Constructor and destructor documentation

◆ FibonacciHeapPriorityQueue() [1/4]

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
ADS::FibonacciHeapPriorityQueue< T, P, A >::FibonacciHeapPriorityQueue ( void )
default

the empty heap

◆ FibonacciHeapPriorityQueue() [2/4]

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
ADS::FibonacciHeapPriorityQueue< T, P, A >::FibonacciHeapPriorityQueue ( const A & alloc)
inlineexplicit

the empty queue, the blocks of its nodes from alloc

◆ FibonacciHeapPriorityQueue() [3/4]

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
ADS::FibonacciHeapPriorityQueue< T, P, A >::FibonacciHeapPriorityQueue ( const FibonacciHeapPriorityQueue< T, P, A > & )
delete

no copy: the handles point into the heap

◆ FibonacciHeapPriorityQueue() [4/4]

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
ADS::FibonacciHeapPriorityQueue< T, P, A >::FibonacciHeapPriorityQueue ( FibonacciHeapPriorityQueue< T, P, A > && other)
noexcept

the items of other, which is left empty; its handles stay valid here

◆ ~FibonacciHeapPriorityQueue()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
ADS::FibonacciHeapPriorityQueue< T, P, A >::~FibonacciHeapPriorityQueue ( )

the heap and its nodes destroyed

Member function documentation

◆ begin()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
const_iterator ADS::FibonacciHeapPriorityQueue< T, P, A >::begin ( void ) const
inlinenodiscard

the first item of the view

◆ cbegin()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
const_iterator ADS::FibonacciHeapPriorityQueue< T, P, A >::cbegin ( void ) const
inlinenodiscard

the same as begin()

◆ cend()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
const_iterator ADS::FibonacciHeapPriorityQueue< T, P, A >::cend ( void ) const
inlinenodiscard

the same as end()

◆ decrease()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
void ADS::FibonacciHeapPriorityQueue< T, P, A >::decrease ( Handle x,
const P & p )

lowers to \( p \) the priority of the node \( x \), in \( O( 1 ) \) amortized time

In pseudocode (Fredman and Tarjan, beyond the book), the cascading cut keeping a node of degree \( k \) with at least \( F_{k+2} \) descendants:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{decrease}( x , p ) \cr 2 & \quad x.\mathit{priority} \gets p;\ y \gets x.\mathit{parent} \cr 3 & \quad \textbf{if}\ y \ne \textbf{nil}\ \textbf{and} \ x.\mathit{priority} < y.\mathit{priority}\ \textbf{then} \cr 4 & \qquad \mathrm{cut}( x , y );\ z \gets y \cr 5 & \qquad \textbf{while}\ z.\mathit{parent} \ne \textbf{nil} \ \textbf{do}\quad \triangleright\ \text{the cascading cut} \cr 6 & \qquad\quad \textbf{if not}\ z.\mathit{mark}\ \textbf{then} \ z.\mathit{mark} \gets \textbf{true};\ \textbf{break} \cr 7 & \qquad\quad w \gets z.\mathit{parent};\ \mathrm{cut}( z , w );\ z \gets w \cr 8 & \quad \textbf{if}\ x.\mathit{priority} < \mathit{min}.\mathit{priority}\ \textbf{then}\ \mathit{min} \gets x \cr 9 & \textbf{procedure}\ \mathrm{cut}( x , y ) \cr 10 & \quad \text{remove } x \text{ from the children of } y; \ y.\mathit{degree} \gets y.\mathit{degree} - 1 \cr 11 & \quad x.\mathit{parent} \gets \textbf{nil};\ x.\mathit{mark} \gets \textbf{false};\ \text{add } x \text{ to the list of the} \text{ roots} \end{array}} \]

Precondition
\( x \) is a node of this heap and \( p \) is not larger than its priority
Postcondition
\( x \) has the priority \( p \)

◆ deleteMin()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
T ADS::FibonacciHeapPriorityQueue< T, P, A >::deleteMin ( void )

removes the item of smallest priority and returns it, in \( O( \log n ) \) amortized time; the handle of the item is no longer valid

In pseudocode (Fredman and Tarjan, beyond the book), \( A \) the roots by degree, the degrees below 64:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{deleteMin}() \cr 2 & \quad z \gets \mathit{min};\ n \gets n - 1 \cr 3 & \quad \text{splice the list of the children of } z \text{ into} \text{ the list of the roots} \cr 4 & \quad \text{remove } z \text{ from the list of the roots} \cr 5 & \quad \textbf{if}\ \text{the list is empty }\ \textbf{then} \ \mathit{min} \gets \textbf{nil}\ \textbf{else} \ \mathrm{consolidate}() \cr 6 & \quad \textbf{return}\ z.\mathit{value} \cr 7 & \textbf{procedure}\ \mathrm{consolidate}() \cr 8 & \quad A[ 0 .. 63 ] \gets \textbf{nil} \cr 9 & \quad \textbf{foreach}\ \text{root } y\ \textbf{do} \cr 10 & \qquad y.\mathit{parent} \gets \textbf{nil};\ y.\mathit{mark} \gets \textbf{false};\ d \gets y.\mathit{degree} \cr 11 & \qquad \textbf{while}\ A[ d ] \ne \textbf{nil}\ \textbf{do} \cr 12 & \qquad\quad z \gets A[ d ];\ A[ d ] \gets \textbf{nil} \cr 13 & \qquad\quad \textbf{if}\ z.\mathit{priority} < y.\mathit{priority}\ \textbf{then}\ \text{swap } y \text{ and } z \cr 14 & \qquad\quad \text{make } z \text{ a child of } y \text{, not} \text{ marked};\ d \gets d + 1;\ y.\mathit{degree} \gets d \cr 15 & \qquad A[ d ] \gets y \cr 16 & \quad \text{the roots} \gets \text{the trees of } A \text{ in a circular list};\ \mathit{min} \gets \text{the least} \text{ of them} \end{array}} \]

Precondition
the heap is not empty
Postcondition
one item less, none of smaller priority than the one removed

◆ empty()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
bool ADS::FibonacciHeapPriorityQueue< T, P, A >::empty ( void ) const
nodiscard

whether the heap has no item

◆ end()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
const_iterator ADS::FibonacciHeapPriorityQueue< T, P, A >::end ( void ) const
inlinenodiscard

the end of the view

◆ get_allocator()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
allocator_type ADS::FibonacciHeapPriorityQueue< T, P, A >::get_allocator ( void ) const
inlinenodiscard

the allocator of the blocks of the nodes

◆ insert()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
Handle ADS::FibonacciHeapPriorityQueue< T, P, A >::insert ( const T & x,
const P & p )

inserts \( x \) with the priority \( p \) and gives its handle, a tree of one node among the roots, in \( O( 1 ) \) time

In pseudocode (Fredman and Tarjan, beyond the book), \( \mathit{min} \) the root of least priority:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insert}( x , p ) \cr 2 & \quad z \gets \text{a node } ( p , x ) \text{ of degree 0, not} \text{ marked};\ n \gets n + 1 \cr 3 & \quad \textbf{if}\ \mathit{min} = \textbf{nil}\ \textbf{then} \ \mathit{min} \gets z \cr 4 & \quad \textbf{else} \cr 5 & \qquad \text{add } z \text{ to the list of the roots} \cr 6 & \qquad \textbf{if}\ z.\mathit{priority} < \mathit{min}.\mathit{priority}\ \textbf{then}\ \mathit{min} \gets z \cr 7 & \quad \textbf{return}\ z \end{array}} \]

Postcondition
one item more

◆ min()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
const T & ADS::FibonacciHeapPriorityQueue< T, P, A >::min ( void ) const
nodiscard

the item of smallest priority, the least of the roots

Precondition
the heap is not empty

◆ minPriority()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
const P & ADS::FibonacciHeapPriorityQueue< T, P, A >::minPriority ( void ) const
nodiscard

the smallest priority

Precondition
the heap is not empty

◆ operator=()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
FibonacciHeapPriorityQueue & ADS::FibonacciHeapPriorityQueue< T, P, A >::operator= ( const FibonacciHeapPriorityQueue< T, P, A > & )
delete

no copy: the handles point into the heap

◆ size()

template<class T, std::totally_ordered P = int, class A = HugePageAllocator< T >>
int ADS::FibonacciHeapPriorityQueue< T, P, A >::size ( void ) const
nodiscard

the number of items, \( n \)


The documentation for this class was generated from the following file: