|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
48 template<
typename,
typename>
88 template<
typename T,
typename C = std::less<T>>
99 explicit FibonacciHeap(
const C& cmp = C(),
int initialSize = -1);
110 const T&
top()
const override;
162 std::array<FibonacciHeapNode<T>*,
sizeof(size_t) * 8>
m_ranked;
184 template<
typename T,
typename C>
190 template<
typename T,
typename C>
195 template<
typename T,
typename C>
197 if (heapNode ==
nullptr) {
203 release(heapNode->
child);
208 }
while (heapNode !=
end);
211 template<
typename T,
typename C>
214 return m_minimal->value;
217 template<
typename T,
typename C>
220 splice(m_knot, heapNode);
222 if (m_minimal ==
nullptr || this->comparator()(heapNode->
value, m_minimal->value)) {
223 m_minimal = heapNode;
229 template<
typename T,
typename C>
232 if (m_knot->next->next == m_knot && m_knot->next->child ==
nullptr) {
233 m_knot->prev = m_knot->next = m_knot;
243 m_minimal = m_knot->next;
244 for (
auto it = m_knot->next->next; it != m_knot; it = it->next) {
245 if (this->comparator()(it->value, m_minimal->value)) {
251 template<
typename T,
typename C>
253 heapNode->
value = value;
254 if (this->comparator()(heapNode->
value, m_minimal->value)) {
255 m_minimal = heapNode;
261 template<
typename T,
typename C>
271 if (this->comparator()(other.
m_minimal->value, m_minimal->value)) {
277 template<
typename T,
typename C>
279 if (m_minimal->child) {
287 }
while (it != m_minimal->
child);
293 template<
typename T,
typename C>
297 for (
auto it = m_knot->next; it != m_knot;) {
301 maxr = std::max(
r, maxr);
302 while (m_ranked[
r]) {
303 if (this->comparator()(m_ranked[
r]->value, it->value)) {
304 link(m_ranked[
r], it);
307 link(it, m_ranked[
r]);
309 m_ranked[
r] =
nullptr;
311 maxr = std::max(maxr,
r);
318 for (
size_t i = 0; i <= maxr; i++) {
319 m_ranked[i] =
nullptr;
323 template<
typename T,
typename C>
330 splice(root->
child, child);
337 template<
typename T,
typename C>
339 heapNode->
prev->next = heapNode->
next;
340 heapNode->
next->prev = heapNode->
prev;
341 heapNode->
next = heapNode;
342 heapNode->
prev = heapNode;
345 template<
typename T,
typename C>
347 m_knot->next->prev = other->
prev;
348 other->
prev->next = m_knot->next;
349 m_knot->next = other;
350 other->
prev = m_knot;
353 template<
typename T,
typename C>
356 target->
next->prev = heapNode;
358 target->
next = heapNode;
359 heapNode->
prev = target;
362 template<
typename T,
typename C>
366 if (parent ==
nullptr) {
372 if (parent->
rank == 0) {
373 parent->
child =
nullptr;
374 }
else if (parent->
child == heapNode) {
378 heapNode->
parent =
nullptr;
379 splice(m_knot, heapNode);
The namespace for all OGDF objects.
FibonacciHeapNode(const T &nodeValue)
Creates heap node with a given nodeValue.
Common interface for all heap classes.
void remove()
Removes minimal tree and moves its children to tree list.
FibonacciHeapNode()
Creates empty root node.
bool marked
Indicates whether node is marked or not.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
FibonacciHeapNode< T > * prev
Previous sibling of the node.
void compress()
Reduces number of trees inside a heap by linking ones with same degree.
void link(FibonacciHeapNode< T > *root, FibonacciHeapNode< T > *child)
Makes child node a child of root node.
FibonacciHeap(const C &cmp=C(), int initialSize=-1)
Creates empty Fibonacci heap.
void decrease(FibonacciHeapNode< T > *heapNode, const T &value) override
Decreases value of the given heapNode to value.
T value
Value contained in the node.
const T & value(FibonacciHeapNode< T > *heapNode) const override
Returns the value of the node.
void restore(FibonacciHeapNode< T > *heapNode)
Restores heap ordering in heapNode by making (cascade) cut.
FibonacciHeapNode< T > * m_minimal
Handle to the tree with lowest root priority.
FibonacciHeapNode< T > * push(const T &value) override
Inserts a new node with given value into a heap.
const T & top() const override
Returns reference to the top element in the heap.
std::array< FibonacciHeapNode< T > *, sizeof(size_t) *8 > m_ranked
Used to compress trees.
void release(FibonacciHeapNode< T > *heapNode)
Recursively releases memory starting at heapNode.
FibonacciHeapNode< T > * next
Next sibling of the node.
Interface for heap implementations.
void detach(FibonacciHeapNode< T > *heapNode)
Detaches given heapNode from its list and makes it self-circulate.
FibonacciHeapNode< T > * parent
Parent of the node.
void merge(FibonacciHeap< T, C > &other) override
Merges in values of other heap.
FibonacciHeapNode< T > * m_knot
Used for efficient tree list manipulation.
Basic declarations, included by all source files.
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)
Fibonacci heap implementation.
size_t rank
Determines rank of a node.
virtual ~FibonacciHeap()
Destructs the heap.
void pop() override
Removes the top element from the heap.
static void remove(V &ts, const T &t)
FibonacciHeapNode< T > * child
First child of the node.
void splice(FibonacciHeapNode< T > *target, FibonacciHeapNode< T > *heapNode)
Moves heapNode from its list to the target list.