Tesseract
3.02
|
00001 /****************************************************************************** 00002 ** Filename: heap.h 00003 ** Purpose: Definition of heap access routines. 00004 ** Author: Dan Johnson 00005 ** History: 3/13/89, DSJ, Created. 00006 ** 00007 ** (c) Copyright Hewlett-Packard Company, 1988. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 ******************************************************************************/ 00018 #ifndef HEAP_H 00019 #define HEAP_H 00020 00021 /*----------------------------------------------------------------------------- 00022 Include Files and Type Defines 00023 -----------------------------------------------------------------------------*/ 00024 #include "host.h" 00025 #include "cutil.h" 00026 00027 #define HEAPFULL 3000 00028 00029 #define EMPTY -1 00030 #define TESS_HEAP_OK 0 00031 00032 struct HEAPENTRY { 00033 FLOAT32 Key; 00034 void *Data; 00035 }; 00036 00037 struct HEAP { 00038 inT32 Size; 00039 inT32 FirstFree; 00040 HEAPENTRY Entry[1]; 00041 }; 00042 00043 /*----------------------------------------------------------------------------- 00044 Macros 00045 -----------------------------------------------------------------------------*/ 00046 #define FreeHeap(H) memfree(H) 00047 #define MaxSizeOfHeap(H) (H->Size) 00048 #define SizeOfHeap(H) (H->FirstFree - 1) 00049 #define InitHeap(H) (H->FirstFree = 1) 00050 #define HeapFull(H) ((H)->FirstFree > (H)->Size) 00051 #define HeapEmpty(H) ((H)->FirstFree <= 1) 00052 00053 /* macros for accessing elements in heap by index. The indicies vary from 00054 0 to SizeOfHeap-1. No bounds checking is done. Elements accessed in 00055 this manner are in random order relative to the Key values. These 00056 macros should never be used as the LHS of an assignment statement as this 00057 will corrupt the heap.*/ 00058 #define HeapKeyFor(H,E) ((H)->Entry[(E)+1].Key) 00059 #define HeapDataFor(H,E) ((H)->Entry[(E)+1].Data) 00060 00061 /*----------------------------------------------------------------------------- 00062 Public Function Prototypes 00063 -----------------------------------------------------------------------------*/ 00064 HEAP *MakeHeap(int Size); 00065 00066 int HeapPop(HEAP *Heap, FLOAT32 *Key, void *out_ptr); 00067 00068 int HeapPopWorst(HEAP *Heap, FLOAT32 *Key, void *out_ptr); 00069 00070 void HeapPush(HEAP *Heap, FLOAT32 Key, void *Data); 00071 00072 void HeapStore(HEAP *Heap, HEAPENTRY *Entry); 00073 00074 int GetTopOfHeap(HEAP *Heap, HEAPENTRY *Entry); 00075 00076 void FreeHeapData(HEAP *Heap, void_dest destructor); 00077 00078 bool HeapPushCheckSize(HEAP *Heap, FLOAT32 Key, void *Data); 00079 00080 #endif