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>
|
|
using
| kv_pair = std::pair<key_type, value_type> |
| |
|
|
| IndexDenseHeap () |
| | Default constructor.
|
| |
| constexpr size_t
| min_size () |
| | Gets the minimum physical size of the heap array.
|
| |
| size_t
| heap_size () const |
| | Gets the current number of elements stored in the heap.
|
| |
| void
| reserve (size_t s) |
| | Reserves memory to minimize reallocation overhead.
|
| |
| bool
| empty () const |
| | Checks whether the heap contains no elements.
|
| |
| 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 |
| | Check if a key exists.
|
| |
| void
| update (key_type key, const value_type &value) |
| | update a value specified by key.
|
| |
| void
| remove (size_t key) |
| | remove a pair of key and value specified by key.
|
| |
|
|
const key_type
| InvalidIndex = static_cast<key_type>(-1) |
| |
|
|
std::vector< key_type >
| m_pos_in_heap |
| | map key to position in heap
|
| |
|
std::vector< kv_pair >
| m_heap |
| | sort (key, value).
|
| |
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.
◆ compare()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
Compare two kv_pair by value in heap indexed by i0 and i1.
- Parameters
-
| i0 | first index for compare |
| i1 | second index for compare |
- Returns
- true if element i0 has higher priority than i1 false otherwise
◆ down_move()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
move element in heap[idx] down.
- Parameters
-
◆ empty()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
Checks whether the heap contains no elements.
- Returns
- true if the heap is empty, false otherwise
◆ empty_pos()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
|
|
inline
constexpr
protected
|
Sentinel value representing empty/invalid position.
- Returns
- 0 indicating an empty or invalid position
◆ exist()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
Check if a key exists.
- Parameters
-
- Returns
- true if key exists,false otherwise
◆ first_pos()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
|
|
inline
constexpr
protected
|
Index of the first element.
- Returns
- 1 the starting index of valid heap elements
◆ heap_size()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
Gets the current number of elements stored in the heap.
- Returns
- the count of valid primitives in the heap
◆ last_pos()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
Index of the last element in the heap.
- Returns
- the last valid heap position
◆ leftc()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
get Index of the left child of node at index i
- Parameters
-
- Returns
- Index of the left child of node at index i
◆ min_size()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
Gets the minimum physical size of the heap array.
- Returns
- the starting offset of the heap (typically 1)
◆ parent()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
get Index of the parent of node at index i
- Parameters
-
- Returns
- Index of the parent of node at index i
◆ push()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
template<bool AllowUpdate = true>
push a (key, value) pair into heap.
- Parameters
-
| key | the key for pair |
| value | the value for pair |
◆ remove()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
remove a pair of key and value specified by key.
- Parameters
-
◆ reserve()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
Reserves memory to minimize reallocation overhead.
- Parameters
-
| s | the expected total number of elements |
◆ rightc()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
get Index of the right child of node at index i
- Parameters
-
- Returns
- Index of the right child of node at index i
◆ top()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
get the (key, value) pair on the top of heap.
- Returns
- the (key, value) pair on the top of heap.
◆ up_move()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
move element in heap[idx] up.
- Parameters
-
◆ update()
template<typename value_type, typename key_type = index_t, typename comparator = std::less<value_type>>
update a value specified by key.
- Parameters
-
| key | specified key |
| value | the new value. |
The documentation for this class was generated from the following file: