SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
DynamicPriorityQueue.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm>
4 #include <iostream>
5 #include <queue>
6 #include <vector>
7 
8 namespace smtrat {
9 
10  template<typename T, typename Compare = std::less<T>>
11  class PriorityQueue: public std::priority_queue<T,std::vector<T>,Compare> {
12  using super = std::priority_queue<T,std::vector<T>,Compare>;
13  public:
14  explicit PriorityQueue(): super() {}
15  explicit PriorityQueue(const Compare& comp): super(comp) {}
16  const auto& data() const {
17  return super::c;
18  }
19  auto& data() {
20  return super::c;
21  }
22  auto find(const T& t) const {
23  return std::find(data().begin(), data().end(), t);
24  }
25  auto begin() const {
26  return data().begin();
27  }
28  auto begin() {
29  return data().begin();
30  }
31  auto end() const {
32  return data().end();
33  }
34  auto end() {
35  return data().end();
36  }
37  auto erase(typename std::vector<T>::const_iterator it) {
38  return data().erase(it);
39  }
40  auto erase(typename std::vector<T>::const_iterator it, typename std::vector<T>::const_iterator end) {
41  return data().erase(it, end);
42  }
43  void fix() {
44  std::make_heap(data().begin(), data().end(), super::comp);
45  }
46  template<typename F>
47  void removeIf(F&& f) {
48  auto it = std::remove_if(data().begin(), data().end(), f);
49  data().erase(it, data().end());
50  std::make_heap(data().begin(), data().end(), super::comp);
51  }
52  void clear() {
53  data().clear();
54  }
55  };
56  template<typename TT, typename C>
57  std::ostream& operator<<(std::ostream& os, const PriorityQueue<TT,C>& pq) {
58  os << "[";
59  for (auto it = pq.data().begin(); it != pq.data().end(); it++) {
60  if (it != pq.data().begin()) os << ", ";
61  os << *it;
62  }
63  return os << "]";
64  }
65 
66  template<typename T, typename Compare = std::less<T>>
68  using Sequence = std::vector<T>;
69 
70  public:
71  using value_type = typename Sequence::value_type;
72 
73  protected:
75  Compare comp;
76 
77  public:
78 
79  explicit DynamicPriorityQueue(const Compare& _comp = Compare()):
80  c(), comp(_comp)
81  {}
82  explicit DynamicPriorityQueue(Sequence&& _seq, const Compare& _comp = Compare()):
83  c(std::move(_seq)), comp(_comp)
84  {
85  std::make_heap(c.begin(), c.end(), comp);
86  }
87 
88  void fix() {
89  std::make_heap(c.begin(), c.end(), comp);
90  }
91 
92  bool empty() const {
93  return c.empty();
94  }
95 
96  std::size_t size() const {
97  return c.size();
98  }
99 
100  const T& top() const {
101  return c.front();
102  }
103 
104  void push(const T& t) {
105  c.push_back(t);
106  std::push_heap(c.begin(), c.end(), comp);
107  }
108 
109  void push(T&& t) {
110  c.push_back(std::move(t));
111  std::push_heap(c.begin(), c.end(), comp);
112  }
113 
114  template<typename... Args>
115  void emplace(Args&&... args) {
116  c.emplace_back(std::forward<Args>(args)...);
117  std::push_heap(c.begin(), c.end(), comp);
118  }
119 
120  void pop() {
121  std::pop_heap(c.begin(), c.end(), comp);
122  c.pop_back();
123  }
124  T popTop() {
125  T r = top();
126  pop();
127  return r;
128  }
129  };
130 }
DynamicPriorityQueue(const Compare &_comp=Compare())
typename Sequence::value_type value_type
DynamicPriorityQueue(Sequence &&_seq, const Compare &_comp=Compare())
PriorityQueue(const Compare &comp)
auto erase(typename std::vector< T >::const_iterator it, typename std::vector< T >::const_iterator end)
const auto & data() const
auto find(const T &t) const
auto erase(typename std::vector< T >::const_iterator it)
std::priority_queue< T, std::vector< T >, Compare > super
static bool find(V &ts, const T &t)
Definition: Alg.h:47
Class to create the formulas for axioms.
std::ostream & operator<<(std::ostream &os, CMakeOptionPrinter cmop)