AMCAX Kernel 1.0.0.0
AMCAX::Meshing::IndexDenseHeap< value_type, key_type, comparator > Class Template Reference

Each element is a pair of key and value (k, v). Key is supposed to be an index with type index_t. Value is usually something to be sorted, e.g., priority. IndexDenseHeap use a heap to sort values by comparing value. It also can modify value by key and resort the values. More...

#include <utilities/IndexHeap.hpp>

Collaboration diagram for AMCAX::Meshing::IndexDenseHeap< value_type, key_type, comparator >:

Public Types

using kv_pair = std::pair< key_type, value_type >
 

Public Member Functions

 IndexDenseHeap ()
 Default constructor.
 
constexpr size_t min_size ()
 
size_t heap_size () const
 
void reserve (size_t s)
 
bool empty () const
 
template<bool AllowUpdate = true>
void push (key_type key, const value_type &value)
 push a (key, value) pair into heap.
 
const kv_pair & top () const
 get the (key, value) pair on the top of heap.
 
void pop ()
 pop the (key, value) pair on the top of heap.
 
bool exist (key_type key) const
 
void update (key_type key, const value_type &value)
 update a value specified by key. More...
 
void remove (size_t key)
 remove a pair of key and value specified by key.
 

Public Attributes

const key_type InvalidIndex = static_cast<key_type>(-1)
 

Protected Member Functions

constexpr size_t empty_pos () const
 
constexpr size_t first_pos () const
 
size_t last_pos () const
 
index_t leftc (index_t i) const
 
index_t rightc (index_t i) const
 
index_t parent (index_t i) const
 
bool compare (index_t i0, index_t i1) const
 Compare two kv_pair by value in heap indexed by i0 and i1.
 
void up_move (index_t idx)
 move element in heap[idx] up. More...
 
void down_move (index_t idx)
 move element in heap[idx] down. More...
 

Protected Attributes

std::vector< key_type > m_pos_in_heap
 
std::vector< kv_pair > m_heap
 < map key to position in heap
 

Detailed Description

template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
class AMCAX::Meshing::IndexDenseHeap< value_type, key_type, comparator >

Each element is a pair of key and value (k, v). Key is supposed to be an index with type index_t. Value is usually something to be sorted, e.g., priority. IndexDenseHeap use a heap to sort values by comparing value. It also can modify value by key and resort the values.

Note
We suppose that key is densely distributed, otherwise use unordered_map to implement m_pos_in_heap.

Member Function Documentation

◆ down_move()

template<typename value_type , typename key_type = index_t, typename comparator = std::less<value_type>>
void AMCAX::Meshing::IndexDenseHeap< value_type, key_type, comparator >::down_move ( index_t  idx)
inlineprotected

move element in heap[idx] down.

Parameters
idxthe position in heap.

◆ up_move()

template<typename value_type , typename key_type = index_t, typename comparator = std::less<value_type>>
void AMCAX::Meshing::IndexDenseHeap< value_type, key_type, comparator >::up_move ( index_t  idx)
inlineprotected

move element in heap[idx] up.

Parameters
idxthe position in heap.

◆ update()

template<typename value_type , typename key_type = index_t, typename comparator = std::less<value_type>>
void AMCAX::Meshing::IndexDenseHeap< value_type, key_type, comparator >::update ( key_type  key,
const value_type &  value 
)
inline

update a value specified by key.

Parameters
valuethe new value.

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