77 template<
class T,
class Cmp>
80 Heap(
const Cmp& cmpFunction,
81 int initialNumElements = 32);
130 void Print(ostream& out)
const;
153 void PrintRoot(ostream& out,
int rootElem,
int indentLevel)
const;
163 void SiftUp(
int rootElem);
172 template<
class T,
class Cmp>
177 template<
class T,
class Cmp>
182 template<
class T,
class Cmp>
187 template<
class T,
class Cmp>
195 template<
class T,
class Cmp>
200 template<
class T,
class Cmp>
205 template<
class T,
class Cmp>
210 template<
class T,
class Cmp>
215 template<
class T,
class Cmp>
220 template<
class T,
class Cmp>
225 template<
class T,
class Cmp>
235 template<
class T,
class Cmp>
242 template<
class T,
class Cmp>
256 template<
class T,
class Cmp>
273 template<
class T,
class Cmp>
279 template<
class T,
class Cmp>
288 template<
class T,
class Cmp>
304 template<
class T,
class Cmp>
311 while (rootElem > 0) {
314 rootElem =
Parent(rootElem);
326 template<
class T,
class Cmp>
346 template<
class T,
class Cmp>
390 template<
class T,
class Cmp>
428 template<
class T,
class Cmp>
434 #if W_DEBUG_LEVEL > 2 443 template<
class T,
class Cmp>
447 T* newElements =
new T[newSize];
459 template<
class T,
class Cmp>
475 template<
class T,
class Cmp>
483 template<
class T,
class Cmp>
487 for (
int i =
LeftChild(top); i < last; i++) {
498 template<
class T,
class Cmp>
503 for (
int i = 0; i < indentLevel; i++) {
void DecreasedN(int i)
Inform heap that element i must drop in heap to restore heap property. More efficient than general He...
Definition: w_heap.h:221
#define w_assert1(x)
Level 1 should not add significant extra time.
Definition: w_base.h:198
void PrintRoot(ostream &out, int rootElem, int indentLevel) const
Definition: w_heap.h:499
void SiftUp(int rootElem)
Definition: w_heap.h:391
void CheckHeapRoot(int rootElem) const
Definition: w_heap.h:460
const Cmp & cmp
Definition: w_heap.h:143
void AddElement(const T &elem)
Put in heap and recompute to restore heap property.
Definition: w_heap.h:305
int maxNumElements
Definition: w_heap.h:139
int LeftChild(int i) const
Definition: w_heap.h:173
Heap(const Cmp &cmpFunction, int initialNumElements=32)
Definition: w_heap.h:226
General-purpose heap.
Definition: w_heap.h:78
void SiftDown(int rootElem)
Definition: w_heap.h:347
~Heap()
Definition: w_heap.h:236
T * elements
Definition: w_heap.h:141
void ReplacedFirst()
Inform heap that I replaced the top: recompute, but more efficient than Heapify() ...
Definition: w_heap.h:211
int RightSibling(int i) const
Definition: w_heap.h:183
bool HeapProperty(int root) const
Check heap property from given root to the bottom.
Definition: w_heap.h:476
void IncreasedN(int i)
Inform heap that element i must rise in heap to restore heap property. More efficient than general He...
Definition: w_heap.h:216
T RemoveN(int i)
Remove element from the middle.
Definition: w_heap.h:243
void GrowElements(int newSize)
Definition: w_heap.h:444
void CheckHeap() const
Check heap property.
Definition: w_heap.h:196
int Parent(int i) const
Definition: w_heap.h:188
const T & Second() const
Get reference element just below top (do not remove)
Definition: w_heap.h:289
#define w_assert9(x)
changing an assert to an assert9 turns it off.
Definition: w_base.h:243
void Print(ostream &out) const
Dump heap.
Definition: w_heap.h:206
void Heapify()
Recompute to restore heap property.
Definition: w_heap.h:429
T & First()
Get reference to top of heap (do not remove)
Definition: w_heap.h:274
int numElements
Definition: w_heap.h:137
void AddElementDontHeapify(const T &elem)
Put in heap but do NOT recompute to restore heap property.
Definition: w_heap.h:327
T & Value(int i)
Get reference arbitrary element (do not remove)
Definition: w_heap.h:280
#define T
Definition: w_okvl_inl.h:45
T RemoveFirst()
Take top/largest element off.
Definition: w_heap.h:257
int NumElements() const
How many elements in the heap?
Definition: w_heap.h:201
int RightChild(int i) const
Definition: w_heap.h:178