|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
45 template<
typename,
typename>
74 template<
typename T,
typename C = std::less<T>>
85 explicit RMHeap(
const C& cmp = C(),
int initialSize = -1);
96 const T&
top()
const override;
154 template<
typename T,
typename C>
156 :
base_type(cmp), m_rand((
std::random_device())()), m_root(nullptr) { }
158 template<
typename T,
typename C>
163 template<
typename T,
typename C>
165 return m_root->value;
168 template<
typename T,
typename C>
171 m_root = merge(m_root, heapNode);
176 template<
typename T,
typename C>
179 m_root = merge(m_root->left, m_root->right);
180 if (m_root !=
nullptr) {
181 m_root->parent =
nullptr;
186 template<
typename T,
typename C>
188 heapNode->
value = value;
189 if (heapNode == m_root) {
194 heapNode->
left =
nullptr;
195 heapNode->
right =
nullptr;
196 heapNode->
parent =
nullptr;
198 m_root = merge(m_root, heapNode);
201 template<
typename T,
typename C>
203 m_root = merge(m_root, other.
m_root);
207 template<
typename T,
typename C>
217 if (m_rand() % 2 == 0) {
219 if (a->
left !=
nullptr) {
224 if (a->
right !=
nullptr) {
225 a->
right->parent = a;
230 if (m_rand() % 2 == 0) {
232 if (b->
left !=
nullptr) {
237 if (b->
right !=
nullptr) {
238 b->
right->parent = b;
245 template<
typename T,
typename C>
248 if (heapNode == heapNode->
parent->left) {
249 heapNode->
parent->left = merged;
251 heapNode->
parent->right = merged;
253 if (merged !=
nullptr) {
258 template<
typename T,
typename C>
260 if (heapNode ==
nullptr) {
264 release(heapNode->
left);
265 release(heapNode->
right);
The namespace for all OGDF objects.
Common interface for all heap classes.
Randomized meldable heap node.
void merge(RMHeap< T, C > &other) override
Merges in values of other heap.
RMHeapNode< T > * push(const T &value) override
Inserts a new node with given value into a heap.
const T & value(RMHeapNode< T > *heapNode) const override
Returns the value of the node.
const T & top() const override
Returns reference to the top element in the heap.
virtual ~RMHeap()
Destructs the heap.
RMHeapNode(const T &nodeValue)
Creates heap node with a given nodeValue.
static void release(RMHeapNode< T > *heapNode)
Recursively releases memory occupied by heap pointed by heapNode.
std::default_random_engine m_rand
Random values generator.
Randomized meldable heap implementation.
RMHeapNode< T > * parent
Parent of the node.
Interface for heap implementations.
void pop() override
Removes the top element from the heap.
RMHeapNode< T > * m_root
Root node of the heap.
RMHeapNode< T > * left
Left child of the node.
RMHeapNode< T > * right
Right child of the node.
RMHeap(const C &cmp=C(), int initialSize=-1)
Creates empty randomized meldable heap.
T value
Value contained in the node.
void remove(RMHeapNode< T > *heapNode)
Removes given heapNode from the main tree (does not free memory!).
static void remove(V &ts, const T &t)
void decrease(RMHeapNode< T > *heapNode, const T &value) override
Decreases value of the given heapNode to value.