ModErn Text Analysis
META Enumerates Textual Applications
fixed_heap.h
Go to the documentation of this file.
1 
10 #ifndef META_FIXED_HEAP_H_
11 #define META_FIXED_HEAP_H_
12 
13 #include <vector>
14 
15 #include "meta/config.h"
16 
17 namespace meta
18 {
19 namespace util
20 {
33 template <class T, class Comp>
35 {
36  public:
37  using iterator = typename std::vector<T>::iterator;
38  using const_iterator = typename std::vector<T>::const_iterator;
39  using size_type = typename std::vector<T>::size_type;
40 
45  fixed_heap(uint64_t max_elems, Comp comp);
46 
51  void push(const T& elem);
52 
57  template <class... Args>
58  void emplace(Args&&... args);
59 
64  size_type size() const;
65 
69  size_type max_elems() const;
70 
75  std::vector<T> extract_top();
76 
81  const_iterator begin() const;
82 
87  const_iterator end() const;
88 
89  private:
90  uint64_t max_elems_;
91  Comp comp_;
92  std::vector<T> pq_;
93 };
94 
99 template <class T, class BinaryFunction>
101  BinaryFunction&& bf)
102 {
104  std::forward<BinaryFunction>(bf));
105 }
106 }
107 }
108 
109 #include "meta/util/fixed_heap.tcc"
110 #endif
size_type max_elems() const
Definition: fixed_heap.tcc:52
fixed_heap< T, BinaryFunction > make_fixed_heap(uint64_t max_elems, BinaryFunction &&bf)
Constructs a fixed_heap from a maximum size and binary comparison function.
Definition: fixed_heap.h:100
std::vector< T > extract_top()
Clears the heap and returns the top elements.
Definition: fixed_heap.tcc:58
const_iterator end() const
Definition: fixed_heap.tcc:77
fixed_heap(uint64_t max_elems, Comp comp)
Definition: fixed_heap.tcc:14
Keeps a constant number of high-priority elements.
Definition: fixed_heap.h:34
void emplace(Args &&... args)
Definition: fixed_heap.tcc:22
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retrieval, data mining, and other applications of text processing.
Definition: analyzer.h:25
void push(const T &elem)
Definition: fixed_heap.tcc:34
const_iterator begin() const
Definition: fixed_heap.tcc:71
size_type size() const
Definition: fixed_heap.tcc:46