1
// Wild Magic Source Code
3
// http://www.geometrictools.com
4
// Copyright (c) 1998-2007
6
// This library is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU Lesser General Public License as published by
8
// the Free Software Foundation; either version 2.1 of the License, or (at
9
// your option) any later version. The license is available for reading at
10
// either of the locations:
11
// http://www.gnu.org/copyleft/lgpl.html
12
// http://www.geometrictools.com/License/WildMagicLicense.pdf
13
// The license applies to versions 0 through 4 of Wild Magic.
15
// Version: 4.0.2 (2006/10/15)
20
#include "Wm4System.h"
25
template <typename Generator, typename Real> class TMinHeap;
27
template <typename Generator, typename Real>
34
Generator GetGenerator () const;
35
Real GetValue () const;
38
friend class TMinHeap<Generator,Real>;
40
Generator m_tGenerator;
45
template <typename Generator, typename Real>
49
TMinHeap (int iMaxQuantity, int iGrowBy);
53
int GetMaxQuantity () const;
54
int GetGrowBy () const;
55
int GetQuantity () const;
56
const TMinHeapRecord<Generator,Real>* GetRecord (int i) const;
58
// Insert into the heap the number fValue that corresponds to the object
59
// identified by iGenerator. The return value is a pointer to the heap
60
// record storing the information.
61
const TMinHeapRecord<Generator,Real>* Insert (Generator tGenerator,
64
// Remove the root of the heap. The root contains the minimum value of
65
// all heap elements. The root information is returned by the function's
67
void Remove (Generator& rtGenerator, Real& rfValue);
69
// The value of a heap record must be modified through this function call.
70
// The side effect is that the heap must be updated accordingly to
71
// accommodate the new value.
72
void Update (const TMinHeapRecord<Generator,Real>* pkConstRecord,
75
// Support for debugging. The first two functions check if the array of
76
// records really do form a heap. The last function prints the heap
78
bool IsValid (int iStart, int iFinal);
80
void Print (const char* acFilename);
83
// The actual record storage, allocated in one large chunk.
84
int m_iMaxQuantity, m_iGrowBy, m_iQuantity;
85
TMinHeapRecord<Generator,Real>* m_akRecords;
87
// Pointers to the records in storage. The two-level system avoids the
88
// large number of allocations and deallocations that would occur if each
89
// element of m_apkRecord were to be allocated/deallocated individually.
90
TMinHeapRecord<Generator,Real>** m_apkRecords;
93
#include "Wm4TMinHeap.inl"