33#include <NDEVR/Buffer.h>
40 template<
class t_comp_type,
class t_value_type,
bool t_is_min>
47 void insert(t_comp_type comparison, t_value_type value)
49 const uint04 length = m_values.size();
50 m_values.add({ value, comparison });
64 return m_values[0].second;
68 return m_values[0].first;
76 return m_values.size();
86 sorted_values.
setSize(m_values.size());
90 sorted_values[i] = heap.m_values[0];
99 sorted_values.
setSize(m_values.size());
103 sorted_values[i] = heap.m_values[0].first;
106 return sorted_values;
108 [[nodiscard]] t_value_type
replaceExtreme(t_comp_type comparison, t_value_type value)
const
110 t_value_type extreme = m_values[0];
111 m_values[0].first = value;
112 m_values[0].second = comparison;
117 t_value_type extreme = m_values[0].first;
123 m_values[0] = m_values.last();
124 m_values.removeLast();
128 void bubbleDown(
uint04 index)
130 const uint04 length = m_values.size();
133 uint04 left_child_index = (index << 1) + 1U;
134 uint04 right_child_index = (index << 1) + 2U;
136 if (left_child_index >= length)
141 if (Compare(m_values[index].second, m_values[left_child_index].second))
142 min_index = left_child_index;
144 if ((right_child_index < length) && Compare(m_values[min_index].second, m_values[right_child_index].second))
145 min_index = right_child_index;
147 if (min_index != index)
150 m_values.swapIndices(index, min_index);
157 void bubbleUp(
uint04 index)
163 uint04 parent_index = ((index - 1) >> 1);
164 if (Compare(m_values[parent_index].second, m_values[index].second))
166 m_values.swapIndices(index, parent_index);
167 index = parent_index;
173 static bool Compare(t_comp_type a, t_comp_type b)
175 if constexpr (t_is_min)
182 Buffer<std::pair<t_value_type, t_comp_type>,
uint04, ObjectAllocator<true>> m_values;
185 template<
class t_comp_type,
class t_value_type>
188 template<
class t_comp_type,
class t_value_type>
A heap data structure that takes the form of a binary tree which is a common way of.
Definition BinaryHeap.hpp:42
const Buffer< std::pair< t_value_type, t_comp_type > > & getAll() const
Definition BinaryHeap.hpp:78
t_value_type replaceExtreme(t_comp_type comparison, t_value_type value) const
Definition BinaryHeap.hpp:108
void insert(t_comp_type comparison, t_value_type value)
Definition BinaryHeap.hpp:47
Buffer< std::pair< t_value_type, t_comp_type > > & values()
Definition BinaryHeap.hpp:58
t_value_type extremeValue() const
Definition BinaryHeap.hpp:66
uint04 size() const
Definition BinaryHeap.hpp:74
t_value_type popExtreme()
Definition BinaryHeap.hpp:115
Buffer< std::pair< t_value_type, t_comp_type > > sortedValues() const
Definition BinaryHeap.hpp:82
void deleteExtreme()
Definition BinaryHeap.hpp:121
void clear()
Definition BinaryHeap.hpp:70
t_comp_type extremeComp() const
Definition BinaryHeap.hpp:62
const Buffer< std::pair< t_value_type, t_comp_type > > & values() const
Definition BinaryHeap.hpp:53
BinaryHeap(uint04 size)
Definition BinaryHeap.hpp:44
Buffer< t_value_type > sortedIndices() const
Definition BinaryHeap.hpp:95
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:59
void setSize(t_index_type new_size)
Definition Buffer.hpp:1330
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:177
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:94