Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
bitpit::MinPQueue< T, T1 > Class Template Reference

class for min priority queue. More...

Public Member Functions

 MinPQueue (bool a=false, std::vector< std::array< int, 2 > > *b=NULL)
 
 MinPQueue (int, bool a=false, std::vector< std::array< int, 2 > > *b=NULL)
 
 ~MinPQueue (void)
 
void buildHeap (void)
 
void clear (void)
 
void display (std::ostream &)
 
void extract (T &)
 
void extract (T &, T1 &)
 
void insert (T &)
 
void insert (T &, T1 &)
 
void modify (int, T &)
 
void modify (int, T &, T1 &)
 

Public Attributes

int heap_size
 
std::vector< T > keys
 
std::vector< T1 > labels
 
std::vector< std::array< int, 2 > > * map
 
int MAXSTK
 

Detailed Description

template<class T, class T1 = T>
class bitpit::MinPQueue< T, T1 >

class for min priority queue.

Class for priority element insertion and extraction. Elements inserted in a min. priority queue are internally sorted on a binary tree to ensure the following property (heap property): given a parent node in the tree (P), and given its children nodes (L and R), P < L and P < R. In this way, the root element is the one with smallest value in the tree.

Each time a new element is inserted or removed from the heap, the tree is updated by moving the elements upwards or downwards on each branch to maintain the heap property. The new position of elements in the tree can be tracked by passing a non-null pointer to a mapping (a vector< array<int, 2> >) to the heap constructor. At any time, the mapping will store the following information:

Template parameter T can be of any copy-constructible type for which operator< is defined

Definition at line 163 of file SortAlgorithms.hpp.

Constructor & Destructor Documentation

◆ MinPQueue() [1/2]

template<class T , class T1 >
bitpit::MinPQueue< T, T1 >::MinPQueue ( bool flag_label = false,
std::vector< std::array< int, 2 > > * map_ = NULL )

Default constructor for class MinPQueue. Initialize an empty priority queue. If a pointer to a vector<array<int, 2>> is provided, the mapping between the original and current element position in the tree is tracked.

Parameters
[in]flag_labelflag for using node labelling (true) or not (false).
[in]map_(default = NULL) pointer to map between the original->current element positions

Definition at line 85 of file PQueue.tpp.

◆ MinPQueue() [2/2]

template<class T , class T1 >
bitpit::MinPQueue< T, T1 >::MinPQueue ( int maxstack,
bool flag_label = false,
std::vector< std::array< int, 2 > > * map_ = NULL )

Constructor #1 for class MinPQueue. Initialize an empty priority queue. The size of memory reserve is specified by maxstack. If a pointer to a vector<array<int, 2>> is provided, the mapping between the original and current element position in the tree is tracked.

Parameters
[in]maxstacksize of memory reserve.
[in]flag_labelflag for using node labelling (true) or not (false).
[in]map_(default = NULL) pointer to map between the original->current element positions

Definition at line 135 of file PQueue.tpp.

◆ ~MinPQueue()

template<class T , class T1 >
bitpit::MinPQueue< T, T1 >::~MinPQueue ( void )

Default destructor for class MinPQueue. Clear queue content and free memory.

Definition at line 181 of file PQueue.tpp.

Member Function Documentation

◆ buildHeap()

template<class T , class T1 >
void bitpit::MinPQueue< T, T1 >::buildHeap ( void )

Build a min heap, from data currently stored in the underlying container.

Definition at line 387 of file PQueue.tpp.

◆ clear()

template<class T , class T1 >
void bitpit::MinPQueue< T, T1 >::clear ( void )

Clear current content without freeing memory.

Definition at line 223 of file PQueue.tpp.

◆ display()

template<class T , class T1 >
void bitpit::MinPQueue< T, T1 >::display ( std::ostream & out)

Display info about the heap to output stream (e.g. current number of element stored in the tree, memory reserved, etc.)

Parameters
[in,out]outoutput stream

Definition at line 787 of file PQueue.tpp.

◆ extract() [1/2]

template<class T , class T1 >
void bitpit::MinPQueue< T, T1 >::extract ( T & root)

Extract the next element (i.e. the element on the root of the tree) from heap list and reduce heap size by one element. After extraction heap property is automatically restored by updating the tree.

Parameters
[in,out]rootvalue of element at tree root.

Definition at line 482 of file PQueue.tpp.

◆ extract() [2/2]

template<class T , class T1 >
void bitpit::MinPQueue< T, T1 >::extract ( T & root,
T1 & root_label )

Extract the next element (i.e. the element on the root of the tree) from heap list and reduce heap size by one element. After extraction heap property is automatically restored by updating the tree.

Parameters
[in,out]rootvalue of element at tree root.
[in,out]root_labellabel associated to root element (available only if flag_label is set to 'true' at heap construction)

Definition at line 422 of file PQueue.tpp.

◆ insert() [1/2]

template<class T , class T1 >
void bitpit::MinPQueue< T, T1 >::insert ( T & key_new)

Insert a new element in the heap. After insertion the heap property is automatically restored by updating the tree.

Parameters
[in]key_newvalue of the new element.

Definition at line 587 of file PQueue.tpp.

◆ insert() [2/2]

template<class T , class T1 >
void bitpit::MinPQueue< T, T1 >::insert ( T & key_new,
T1 & label_new )

Insert a new element in the heap. After insertion the heap property is automatically restored by updating the tree.

Parameters
[in]key_newvalue of the new element.
[in]label_newlabel associated to the new element (available only if flag_label is set to 'true' at heap construction)

Definition at line 538 of file PQueue.tpp.

◆ modify() [1/2]

template<class T , class T1 >
void bitpit::MinPQueue< T, T1 >::modify ( int i,
T & key_new )

Modify the value of an existing element in the heap. The heap property is automatically restored by moving down/upwards the element in the tree.

Parameters
[in]iindex of element in the tree.
[in]key_newnew value of the element.

Definition at line 725 of file PQueue.tpp.

◆ modify() [2/2]

template<class T , class T1 >
void bitpit::MinPQueue< T, T1 >::modify ( int i,
T & key_new,
T1 & label_new )

Modify the value of an existing element in the heap. The heap property is automatically restored by moving down/upwards the element in the tree.

Parameters
[in]iindex of element in the tree.
[in]key_newnew value of the element.
[in]label_newnew label to assign to the element (available only if flag_label is set to 'true' at heap construction)

Definition at line 649 of file PQueue.tpp.

Member Data Documentation

◆ heap_size

template<class T , class T1 = T>
int bitpit::MinPQueue< T, T1 >::heap_size

number of elements in stack

Definition at line 168 of file SortAlgorithms.hpp.

◆ keys

template<class T , class T1 = T>
std::vector< T > bitpit::MinPQueue< T, T1 >::keys

stack

Definition at line 169 of file SortAlgorithms.hpp.

◆ labels

template<class T , class T1 = T>
std::vector< T1 > bitpit::MinPQueue< T, T1 >::labels

labels associated to keys

Definition at line 170 of file SortAlgorithms.hpp.

◆ map

template<class T , class T1 = T>
std::vector< std::array<int,2> >* bitpit::MinPQueue< T, T1 >::map

pointer to mapper

Definition at line 171 of file SortAlgorithms.hpp.

◆ MAXSTK

template<class T , class T1 = T>
int bitpit::MinPQueue< T, T1 >::MAXSTK

Maximal stack size between resize

Definition at line 167 of file SortAlgorithms.hpp.


The documentation for this class was generated from the following files:
--- layout: doxygen_footer ---