NeoPZ
TPZPriorityQueue.h
Go to the documentation of this file.
1 #ifndef TPZPRIORITYQUEUE_H
2 #define TPZPRIORITYQUEUE_H
3 
4 #include <queue>
5 #include <mutex>
6 #include <iostream>
7 #include <algorithm>
8 
9 template <class T, class Container = std::vector<T>, class Compare = std::less<typename Container::value_type>>
11 public:
12 
14 
15  }
16 
18  this->c = other.c;
19  this->comp = other.comp;
20  };
21 
23  if (this != &other){
24  this->c = other.c;
25  this->comp = other.comp;
26  }
27  return *this;
28  }
29 
30  void addItem(const T &item) {
31  this->c.push_back(item);
32  std::sort(this->c.begin(), this->c.end(), this->comp);
33  }
34 
35  T popTop() {
36  T highestItem = this->top();
37  this->pop();
38  return highestItem;
39  }
40 
41  bool remove(T& value) {
42  auto it = std::find(this->c.begin(), this->c.end(), value);
43  if (it != this->c.end()) {
44  this->c.erase(it);
45  std::sort(this->c.begin(), this->c.end(), this->comp);
46  return true;
47  } else {
48  return false;
49  }
50  }
51 
52  void remove(const typename Container::size_type begin, const typename Container::size_type end) {
53  this->c.erase(this->c.begin() + begin, this->c.begin() + end);
54  }
55 
56  T top() {
57  return c.operator[](0);
58  }
59 
60  typename Container::size_type size() const {
61  return c.size();
62  }
63 
64  const T &getItem(const typename Container::size_type index) const {
65  return this->c.operator[](index);
66  }
67 
68  void pop() {
69  c.erase(c.begin());
70  }
71 
72  void pop_back(const typename Container::size_type count) {
73  c.erase(c.end()-count, c.end());
74  }
75 
76  void push(T &item) {
77  c.push_back(item);
78  }
79 
80  void push(const T &item) {
81  c.push_back(item);
82  }
83 
84  mutable std::mutex mMutex;
85 
86 protected :
87 
88  Container c;
89  Compare comp;
90 
91 };
92 
93 #endif // TPZPRIORITYQUEUE_H
void addItem(const T &item)
pthread_mutex_t mutex
Semaphore which controls multiple threads.
Container::size_type size() const
void push(const T &item)
const T & getItem(const typename Container::size_type index) const
TPZPriorityQueue & operator=(const TPZPriorityQueue &other)
TPZPriorityQueue(const TPZPriorityQueue &other)
void push(T &item)
void pop_back(const typename Container::size_type count)