Go to the documentation of this file.
7#define MIN(a, b) ( ( a ) > ( b ) ? ( b ) : ( a ) )
22 T2H = (
int * ) calloc(
N,
sizeof(
int ) );
25 for (
int i = 0; i <
N; i++ ) {
37void Heap :: setToEmpty(
int N) {
39 for (
int i = 0; i <
N; i++ ) {
44int Heap :: parentInd(
int inInd) {
45 return ( inInd - 1 ) / 2;
48int Heap :: leftChildInd(
int inInd) {
52int Heap :: rightChildInd(
int inInd) {
56int Heap :: lastParentInd() {
63void Heap :: swapElements(
int Ind1,
int Ind2) {
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;
87void Heap :: upHeap(
int Ind) {
92 parent = ( Ind - 1 ) / 2;
93 if (
Keys [ Ind ] <
Keys [ parent ] ) {
102void Heap :: downHeap(
int Ind) {
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 ) {
136bool Heap :: isInHeap(
int Ind) {
139 return (
T2H [ Ind ] >= 0 );
142int Heap :: nElems() {
146void Heap :: insert(
double time,
int Ind) {
151 H2T = (
int * ) realloc(
H2T,
167void Heap :: update(
double time,
int Ind) {
176double Heap :: getSmallest(
int *Ind) {
178 double heapRoot =
Keys [ 0 ];
196int Heap :: checkHeapProperty(
int pInd) {
198 int rChild = lChild + 1;
217void Heap :: print() {
219 for (
int iter = 0; iter <
heapCount; iter++ ) {
220 printf(
"%.3g ",
Keys [ iter ]);
224void Heap :: recurse(
int row,
int pad,
int spacing,
int S) {
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 = (int) ( pow( 2, ( row - 1 ) ) - 1 );
236 int end = (int)
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 ]);
250void Heap :: printTree() {
259 int nRows = (int) (1 + floor( log2(
heapCount) ));
269double *Heap :: formMatrix(
int m,
int n) {
270 double *mat = (
double * ) calloc( m * n,
sizeof(
double ) );
271 for (
int iter = 0; iter <
heapCount; iter++ ) {
272 mat [
H2T [ iter ] ] =
Keys [ iter ];
void swapElements(int Ind1, int Ind2)
int checkHeapProperty(int pInd)
Debugging tools.
void upHeap(int Ind)
Elementary heap operations.
int heapCount
Keeps track of the number of elements in heap.
int Initial_Heap_Alloc_Size
Variables that control the memory allocation for the heap.
int leftChildInd(int inInd)
void recurse(int row, int pad, int spacing, int S)
Used by printTree. Does the actual printing, top-down.
This page is part of the
OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak
Bořek Patzák
Project e-mail:
oofem@fsv.cvut.cz
Generated at for OOFEM by
doxygen
1.15.0 written by Dimitri van Heesch,
© 1997-2011