Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oldheap.h
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: heap.h
3  ** Purpose: Definition of heap access routines.
4  ** Author: Dan Johnson
5  ** History: 3/13/89, DSJ, Created.
6  **
7  ** (c) Copyright Hewlett-Packard Company, 1988.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  ******************************************************************************/
18 #ifndef HEAP_H
19 #define HEAP_H
20 
21 /*-----------------------------------------------------------------------------
22  Include Files and Type Defines
23 -----------------------------------------------------------------------------*/
24 #include "host.h"
25 #include "cutil.h"
26 
27 #define HEAPFULL 3000
28 
29 #define EMPTY -1
30 #define TESS_HEAP_OK 0
31 
32 struct HEAPENTRY {
34  void *Data;
35 };
36 
37 struct HEAP {
41 };
42 
43 /*-----------------------------------------------------------------------------
44  Macros
45 -----------------------------------------------------------------------------*/
46 #define FreeHeap(H) memfree(H)
47 #define MaxSizeOfHeap(H) (H->Size)
48 #define SizeOfHeap(H) (H->FirstFree - 1)
49 #define InitHeap(H) (H->FirstFree = 1)
50 #define HeapFull(H) ((H)->FirstFree > (H)->Size)
51 #define HeapEmpty(H) ((H)->FirstFree <= 1)
52 
53 /* macros for accessing elements in heap by index. The indicies vary from
54  0 to SizeOfHeap-1. No bounds checking is done. Elements accessed in
55  this manner are in random order relative to the Key values. These
56  macros should never be used as the LHS of an assignment statement as this
57  will corrupt the heap.*/
58 #define HeapKeyFor(H,E) ((H)->Entry[(E)+1].Key)
59 #define HeapDataFor(H,E) ((H)->Entry[(E)+1].Data)
60 
61 /*-----------------------------------------------------------------------------
62  Public Function Prototypes
63 -----------------------------------------------------------------------------*/
64 HEAP *MakeHeap(int Size);
65 
66 int HeapPop(HEAP *Heap, FLOAT32 *Key, void *out_ptr);
67 
68 int HeapPopWorst(HEAP *Heap, FLOAT32 *Key, void *out_ptr);
69 
70 void HeapPush(HEAP *Heap, FLOAT32 Key, void *Data);
71 
72 void HeapStore(HEAP *Heap, HEAPENTRY *Entry);
73 
74 int GetTopOfHeap(HEAP *Heap, HEAPENTRY *Entry);
75 
76 void FreeHeapData(HEAP *Heap, void_dest destructor);
77 
78 bool HeapPushCheckSize(HEAP *Heap, FLOAT32 Key, void *Data);
79 
80 #endif