Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

PQ.h
Go to the documentation of this file.
1 
33 #pragma once
34 
36 #include <ogdf/basic/basic.h>
39 
40 #include <functional>
41 #include <unordered_map>
42 
43 namespace ogdf {
44 namespace matching_blossom {
45 
49 template<typename E, typename TWeight, typename C = std::less<TWeight>,
50  template<typename, class> class Impl = PairingHeap>
51 class BlossomPQ
52  : public PrioritizedQueue<E, TWeight, C, Impl>,
53  public KeyIteratorContainer<E, typename PrioritizedQueue<E, TWeight, C, Impl>::Handle> {
54 protected:
57  using Handle = typename SuperQueue::Handle;
58 
59  std::unordered_map<E, Handle> m_handles;
60 
61 public:
63 
65  bool contains(const E& element) const { return m_handles.find(element) != m_handles.end(); }
66 
67  /*
68  * Returns the priority of the key.
69  * Note that the behaviour is undefined if the key is not present.
70  */
71  TWeight priority(const E& element) const {
72  auto it = m_handles.find(element);
73  OGDF_ASSERT(it != m_handles.end());
74  return this->value(it->second).priority();
75  }
76 
81  void push(const E& element, const TWeight priority) {
82  OGDF_ASSERT(!contains(element));
83  m_handles[element] = SuperQueue::push(element, priority);
84  }
85 
87  void pop() {
90  }
91 
97  void decrease(const E& element, const TWeight priority) {
98  Handle pos = m_handles[element];
100  }
101 
103  void merge(ThisQueue& other) {
104  SuperQueue::merge(other);
105  for (auto entry : other.m_handles) {
106  m_handles[entry.first] = entry.second;
107  }
108  other.m_handles.clear();
109  }
110 
112  void clear() {
114  m_handles.clear();
115  }
116 
119  void remove(const E& e) {
120  OGDF_ASSERT(this->contains(e));
121  this->decrease(e, -infinity<TWeight>());
122  OGDF_ASSERT(this->topElement() == e);
123  this->pop();
124  }
125 };
126 
127 }
128 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::matching_blossom::BaseIteratorContainer
Dummy class for scoped iteration of a std::unordered_map.
Definition: utils.h:112
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
PriorityQueue.h
Priority queue interface wrapping various heaps.
ogdf::PriorityQueue::value
const T & value(handle pos) const
Returns the priority of that handle.
Definition: PriorityQueue.h:222
ogdf::pq_internal::PrioritizedQueue::decrease
void decrease(Handle pos, const P &priority)
Definition: PriorityQueue.h:303
ogdf::matching_blossom::BlossomPQ::remove
void remove(const E &e)
Remove e from the queue by decreasing its priority to the minimum. e must be present in the queue; if...
Definition: PQ.h:119
ogdf::pq_internal::PrioritizedQueue
Defines a queue for handling prioritized elements.
Definition: PriorityQueue.h:271
ogdf::PriorityQueue::clear
void clear()
Removes all the entries from the queue.
Definition: PriorityQueue.h:205
ogdf::matching_blossom::BlossomPQ::m_handles
std::unordered_map< E, Handle > m_handles
Definition: PQ.h:59
ogdf::PriorityQueue::pop
void pop()
Removes the top element from the heap.
Definition: PriorityQueue.h:177
ogdf::matching_blossom::BlossomPQ::clear
void clear()
Removes all elements from this queue.
Definition: PQ.h:112
ogdf::matching_blossom::BlossomPQ::merge
void merge(ThisQueue &other)
Merge this Priority Queue with another one. The other queue is cleared afterwards.
Definition: PQ.h:103
ogdf::pq_internal::PrioritizedQueue::push
Handle push(const E &element, const P &priority)
Pushes a new element with the respective priority to the queue.
Definition: PriorityQueue.h:297
ogdf::matching_blossom::BlossomPQ::contains
bool contains(const E &element) const
Returns whether this queue contains that key.
Definition: PQ.h:65
PairingHeap.h
Implementation of pairing heap data structure.
ogdf::matching_blossom::BlossomPQ::BlossomPQ
BlossomPQ()
Definition: PQ.h:62
ogdf::pq_internal::PrioritizedQueue::topElement
const E & topElement() const
Returns the topmost element in the queue.
Definition: PriorityQueue.h:286
ogdf::matching_blossom::BlossomPQ::priority
TWeight priority(const E &element) const
Definition: PQ.h:71
basic.h
Basic declarations, included by all source files.
ogdf::matching_blossom::BlossomPQ::decrease
void decrease(const E &element, const TWeight priority)
Decreases the priority of the given element.
Definition: PQ.h:97
utils.h
Utility functions and classes regarding map access and iteration.
ogdf::matching_blossom::BlossomPQ::push
void push(const E &element, const TWeight priority)
Adds a new element to the queue.
Definition: PQ.h:81
ogdf::pq_internal::PrioritizedQueue::Handle
typename SuperQueue::handle Handle
The type of handle for accessing the elements of this queue.
Definition: PriorityQueue.h:280
ogdf::matching_blossom::BlossomPQ::pop
void pop()
Removes the topmost element from the queue.
Definition: PQ.h:87
ogdf::matching_blossom::BlossomPQ
A custom priority queue for the blossom algorithm, based on the PrioritizedMapQueue....
Definition: PQ.h:51
ogdf::PriorityQueue
Priority queue interface wrapper for heaps.
Definition: PriorityQueue.h:62
ogdf::PriorityQueue::merge
void merge(PriorityQueue &other)
Merges in enqueued values of other queue.
Definition: PriorityQueue.h:198