|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
40 template<
typename V,
typename P>
66 template<
typename V,
typename P>
100 static constexpr std::size_t
BITS =
sizeof(P) * 8;
123 # if __has_builtin(__builtin_clz)
124 static std::size_t
msbSet(
unsigned int mask) {
125 return mask == 0 ? 0 : (
BITS - __builtin_clz(mask));
128 static std::size_t
msbSet(
unsigned long mask) {
129 return mask == 0 ? 0 : (
BITS - __builtin_clzl(mask));
132 static std::size_t
msbSet(
unsigned long long mask) {
133 return mask == 0 ? 0 : (
BITS - __builtin_clzll(mask));
139 template<
typename V,
typename P>
144 template<
typename V,
typename P>
146 for (
Bucket& bucket : m_buckets) {
148 while (it !=
nullptr) {
149 auto next = it->next;
156 template<
typename V,
typename P>
165 template<
typename V,
typename P>
169 if (m_buckets[0] !=
nullptr) {
170 V result =
std::move(m_buckets[0]->value);
176 if (m_buckets[0] !=
nullptr) {
177 m_buckets[0]->
prev =
nullptr;
182 std::size_t ind = BITS + 1 - msbSet(m_bucketMask);
184 Bucket bucket = m_buckets[ind];
185 m_buckets[ind] =
nullptr;
187 m_bucketMask ^= (P(1) << (8 *
sizeof(P) - ind));
192 for (
Bucket it = bucket; it !=
nullptr; it = it->
next) {
198 if (min->
prev !=
nullptr) {
204 if (min->
next !=
nullptr) {
212 while (bucket !=
nullptr) {
214 bucket->
prev =
nullptr;
223 template<
typename V,
typename P>
225 std::size_t ind = msbSet(heapNode->
priority ^ m_minimum);
227 heapNode->
next = m_buckets[ind];
228 if (m_buckets[ind] !=
nullptr) {
229 m_buckets[ind]->prev = heapNode;
231 m_buckets[ind] = heapNode;
234 m_bucketMask |= (P(1) << (BITS - ind));
The namespace for all OGDF objects.
P m_bucketMask
Priority of the lowest element so far.
P m_minimum
Number of elements.
static constexpr std::size_t BITS
static std::size_t msbSet(T mask)
Returns most significant bit set on given mask.
~RadixHeap()
Destructs the heap.
std::size_t size() const
Number of elements contained within the heap.
const T & move(const T &v)
V pop()
Removes the top element from the heap and returns its value.
RadixHeapNode< V, P > * next
void insert(RadixHeapNode< V, P > *heapNode)
Buckets with values.
RadixHeapNode< V, P > * prev
Radix heap data structure implementation.
RadixHeapNode(const V &nodeValue, const P &nodePriority)
std::array< Bucket, BITS+1 > m_buckets
Mask describing state of buckets (for fast lookup).
RadixHeap()
Creates empty heap.
bool empty() const
Checks whether the heap is empty.
RadixHeapNode< V, P > * push(const V &value, const P &priority)
Inserts a new node with given value and priority into a heap.