7 #define MIN(a, b) ( ( a ) > ( b ) ? ( b ) : ( a ) ) 22 T2H = (
int * ) calloc( N,
sizeof(
int ) );
25 for (
int i = 0; i <
N; i++ ) {
39 for (
int i = 0; i <
N; i++ ) {
45 return ( inInd - 1 ) / 2;
72 tmpKey =
Keys [ Ind1 ];
74 Keys [ Ind2 ] = tmpKey;
78 T2H [
H2T [ Ind1 ] ] = Ind2;
79 T2H [ H2T [ Ind2 ] ] = Ind1;
82 tmpInd = H2T [ Ind1 ];
83 H2T [ Ind1 ] = H2T [ Ind2 ];
84 H2T [ Ind2 ] = tmpInd;
92 parent = ( Ind - 1 ) / 2;
93 if (
Keys [ Ind ] <
Keys [ parent ] ) {
104 int child1, child2, minChild;
112 while ( Ind <= ( (
heapCount - 2 ) / 2 ) ) {
113 child1 = 2 * Ind + 1;
118 if (
Keys [ child1 ] <
Keys [ Ind ] ) {
126 if ( minChild != Ind ) {
139 return (
T2H [ Ind ] >= 0 );
151 H2T = (
int * ) realloc(
H2T,
178 double heapRoot =
Keys [ 0 ];
198 int rChild = lChild + 1;
219 for (
int iter = 0; iter <
heapCount; iter++ ) {
220 printf(
"%.3g ",
Keys [ iter ]);
227 int newSpacing = ( ( int ) ceil( 2.0 * ( (
double ) spacing ) +
228 ( ( double ) S ) ) );
229 int newPad = ( ( int ) ceil( ( (
double ) pad ) + ( (
double ) spacing ) / 2.0
230 + ( (
double )
S ) / 2.0 ) );
231 recurse(row - 1, newPad, newSpacing, S);
235 int beg = ( pow( 2, ( row - 1 ) ) - 1 );
236 int end =
MIN( (
heapCount - 1 ), ( pow(2, row) - 2 ) );
240 for (
int i = 0; i < pad; i++ ) {
245 for (
int elem = beg; elem <= end; elem++ ) {
246 printf(
"%-*.*g", S + spacing, S,
Keys [ elem ]);
259 int nRows = 1 + floor( log2(
heapCount) );
270 double *mat = (
double * ) calloc( m * n,
sizeof(
double ) );
271 for (
int iter = 0; iter <
heapCount; iter++ ) {
272 mat [
H2T [ iter ] ] =
Keys [ iter ];
double getSmallest(int *Ind)
void swapElements(int Ind1, int Ind2)
void recurse(int row, int pad, int spacing, int S)
Used by printTree. Does the actual printing, top-down.
int checkHeapProperty(int pInd)
Debugging tools.
void insert(double time, int Ind)
void upHeap(int Ind)
Elementary heap operations.
int heapCount
Keeps track of the number of elements in heap.
double * Keys
Heap arrays: Keys contains certain real values that need to be sorted.
void setToEmpty(int N)
Interface with external algorithms (such as fast marching)
int leftChildInd(int inInd)
int parentInd(int inInd)
Index calculations.
int rightChildInd(int inInd)
void update(double time, int Ind)
double * formMatrix(int m, int n)
int Initial_Heap_Alloc_Size
Variables that control the memory allocation for the heap.
the oofem namespace is to define a context or scope in which all oofem names are defined.
Heap(int N)
Constructor and destructor.