Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

PQ.h
Go to the documentation of this file.
1 
33 #pragma once
34 
37 
38 #include <limits>
39 #include <unordered_map>
40 
41 namespace ogdf {
42 namespace matching_blossom {
43 
47 template<typename E, typename TWeight, typename C = std::less<TWeight>,
48  template<typename, class> class Impl = PairingHeap>
49 class BlossomPQ
50  : public PrioritizedQueue<E, TWeight, C, Impl>,
51  public KeyIteratorContainer<E, typename PrioritizedQueue<E, TWeight, C, Impl>::Handle> {
52 protected:
55  using Handle = typename SuperQueue::Handle;
56 
57  std::unordered_map<E, Handle> m_handles;
58 
59 public:
61 
63  bool contains(const E& element) const { return m_handles.find(element) != m_handles.end(); }
64 
65  /*
66  * Returns the priority of the key.
67  * Note that the behaviour is undefined if the key is not present.
68  */
69  TWeight priority(const E& element) const {
70  auto it = m_handles.find(element);
71  OGDF_ASSERT(it != m_handles.end());
72  return this->value(it->second).priority();
73  }
74 
79  void push(const E& element, const TWeight priority) {
80  OGDF_ASSERT(!contains(element));
81  m_handles[element] = SuperQueue::push(element, priority);
82  }
83 
85  void pop() {
88  }
89 
95  void decrease(const E& element, const TWeight priority) {
96  Handle pos = m_handles[element];
98  }
99 
101  void merge(ThisQueue& other) {
102  SuperQueue::merge(other);
103  for (auto entry : other.m_handles) {
104  m_handles[entry.first] = entry.second;
105  }
106  other.m_handles.clear();
107  }
108 
110  void clear() {
112  m_handles.clear();
113  }
114 
117  void remove(const E& e) {
118  OGDF_ASSERT(this->contains(e));
119  this->decrease(e, -infinity<TWeight>());
120  OGDF_ASSERT(this->topElement() == e);
121  this->pop();
122  }
123 };
124 
125 }
126 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::matching_blossom::BaseIteratorContainer
Dummy class for scoped iteration of a std::unordered_map.
Definition: utils.h:109
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
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:220
ogdf::pq_internal::PrioritizedQueue::decrease
void decrease(Handle pos, const P &priority)
Definition: PriorityQueue.h:301
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:117
ogdf::pq_internal::PrioritizedQueue
Defines a queue for handling prioritized elements.
Definition: PriorityQueue.h:269
ogdf::PriorityQueue::clear
void clear()
Removes all the entries from the queue.
Definition: PriorityQueue.h:203
ogdf::matching_blossom::BlossomPQ::m_handles
std::unordered_map< E, Handle > m_handles
Definition: PQ.h:57
ogdf::PriorityQueue::pop
void pop()
Removes the top element from the heap.
Definition: PriorityQueue.h:175
ogdf::matching_blossom::BlossomPQ::clear
void clear()
Removes all elements from this queue.
Definition: PQ.h:110
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:101
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:295
ogdf::matching_blossom::BlossomPQ::contains
bool contains(const E &element) const
Returns whether this queue contains that key.
Definition: PQ.h:63
ogdf::matching_blossom::BlossomPQ::BlossomPQ
BlossomPQ()
Definition: PQ.h:60
ogdf::pq_internal::PrioritizedQueue::topElement
const E & topElement() const
Returns the topmost element in the queue.
Definition: PriorityQueue.h:284
ogdf::matching_blossom::BlossomPQ::priority
TWeight priority(const E &element) const
Definition: PQ.h:69
ogdf::matching_blossom::BlossomPQ::decrease
void decrease(const E &element, const TWeight priority)
Decreases the priority of the given element.
Definition: PQ.h:95
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:79
ogdf::pq_internal::PrioritizedQueue::Handle
typename SuperQueue::handle Handle
The type of handle for accessing the elements of this queue.
Definition: PriorityQueue.h:278
ogdf::matching_blossom::BlossomPQ::pop
void pop()
Removes the topmost element from the queue.
Definition: PQ.h:85
ogdf::matching_blossom::BlossomPQ
A custom priority queue for the blossom algorithm, based on the PrioritizedMapQueue....
Definition: PQ.h:49
ogdf::PriorityQueue
Priority queue interface wrapper for heaps.
Definition: PriorityQueue.h:60
ogdf::PriorityQueue::merge
void merge(PriorityQueue &other)
Merges in enqueued values of other queue.
Definition: PriorityQueue.h:196