NeoPZ
TPZLimitedPriorityQueue.h
Go to the documentation of this file.
1 /*
2  * File: TPZLimitedPriorityQueue.h
3  * Author: thiago
4  *
5  * Created on 10 de Agosto de 2018, 18:12
6  */
7 
8 #ifndef TPZLIMITEDPRIORITYQUEUE_H
9 #define TPZLIMITEDPRIORITYQUEUE_H
10 
11 #include "TPZPriorityQueue.h"
12 #include <vector>
13 
14 template <class T, class Compare = std::less<typename std::vector<T>::value_type>>
15 class TPZLimitedPriorityQueue : public TPZPriorityQueue<T, std::vector<T>, Compare> {
16 public:
17  TPZLimitedPriorityQueue(const typename std::vector<T>::size_type limit) : TPZPriorityQueue<T, std::vector<T>, Compare>(), limit(limit) {
18  }
19  TPZLimitedPriorityQueue(const TPZLimitedPriorityQueue& orig) = default;
20 
22  TPZPriorityQueue<T, std::vector<T>, Compare>::operator =(other);
23  limit = other.limit;
24  return *this;
25  }
26 
27  void addItem(const T &item) {
28  this->push(item);
29  std::sort(this->c.begin(), this->c.end(), this->comp);
30  if (this->c.size() > this->limit){
31  this->c.pop_back();
32  }
33  }
34 
35  virtual ~TPZLimitedPriorityQueue() = default;
36 private:
37  typename std::vector<T>::size_type limit;
38 };
39 
40 #endif /* TPZLIMITEDPRIORITYQUEUE_H */
41 
TPZLimitedPriorityQueue & operator=(const TPZLimitedPriorityQueue &other)
virtual ~TPZLimitedPriorityQueue()=default
TPZLimitedPriorityQueue(const typename std::vector< T >::size_type limit)
std::vector< T >::size_type limit