Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
HeapBase.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <stdexcept>
35
36namespace ogdf {
37
47template<typename IMPL, typename H, typename T, typename C>
48class HeapBase {
50
51public:
56 using Handle = H*;
57
58 explicit HeapBase(const C& comp = C()) : m_comp(comp) { }
59
65 virtual const C& comparator() const { return m_comp; }
66
72 virtual const T& top() const = 0;
73
80 virtual Handle push(const T& value) = 0;
81
85 virtual void pop() = 0;
86
93 virtual void decrease(Handle handle, const T& value) = 0;
94
101 virtual const T& value(const Handle handle) const = 0;
102
110 virtual void merge(IMPL& other);
111};
112
113template<typename IMPL, typename H, typename T, typename C>
114void HeapBase<IMPL, H, T, C>::merge(IMPL& /*other*/) {
115 throw std::runtime_error("Merging two binary heaps is not supported");
116}
117
118}
Common interface for all heap classes.
Definition HeapBase.h:48
virtual void merge(IMPL &other)
Merges in values of other heap.
Definition HeapBase.h:114
virtual void pop()=0
Removes the topmost value from the heap.
HeapBase(const C &comp=C())
Definition HeapBase.h:58
virtual Handle push(const T &value)=0
Inserts a value into the heap.
virtual const T & top() const =0
Returns the topmost value in the heap.
virtual const T & value(const Handle handle) const =0
Returns the value of that handle.
H * Handle
The type of handle used to identify stored values.
Definition HeapBase.h:56
virtual const C & comparator() const
Returns the comparator used to sort the values in the heap.
Definition HeapBase.h:65
virtual void decrease(Handle handle, const T &value)=0
Decreases a single value.
The namespace for all OGDF objects.