TPIE

2362a60
pq_merge_heap.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2008, 2012, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
24 
25 #ifndef _TPIE_PQ_MERGE_HEAP_H_
26 #define _TPIE_PQ_MERGE_HEAP_H_
27 
28 #include "tpie_log.h"
29 #include <cassert>
30 #include <tpie/memory.h>
31 
32 namespace tpie{
33 
40 template<typename T, typename Comparator = std::less<T> >
42  public:
43  typedef memory_size_type run_type;
44 
50  pq_merge_heap(memory_size_type elements);
51 
56 
63  void push(const T& x, run_type run);
64 
68  void pop();
69 
77  void pop_and_push(const T& x, run_type run);
78 
84  const T& top() const;
85 
91  run_type top_run() const;
92 
98  memory_size_type size() const;
99 
105  bool empty() const;
106 
107  private:
108  void fixDown();
109  void validate();
110  void dump();
111 
112  memory_size_type m_size;
113  Comparator comp_;
114 
115  T* heap;
116  run_type* runs;
117  memory_size_type maxsize;
118 };
119 
120 #include "pq_merge_heap.inl"
121 }
122 
123 #endif
124 
bool empty() const
Return true if queue is empty, otherwise false.
const T & top() const
See what's on the top of the priority queue.
Definition: pq_merge_heap.h:85
Memory management subsystem.
void pop()
Remove the top element from the priority queue.
Definition: pq_merge_heap.h:60
Logging functionality and log_level codes for different priorities of log messages.
void pop_and_push(const T &x, run_type run)
Remove the top element from the priority queue and insert another.
Definition: pq_merge_heap.h:74
void push(const T &x, run_type run)
Insert an element into the priority queue.
Definition: pq_merge_heap.h:37
pq_merge_heap(memory_size_type elements)
Constructor.
Definition: pq_merge_heap.h:23
run_type top_run() const
Return top element run number.
Definition: pq_merge_heap.h:92
memory_size_type size() const
Returns the size of the queue.
Definition: pq_merge_heap.h:98
~pq_merge_heap()
Destructor.
Definition: pq_merge_heap.h:31