1 /*   (C) Copyright 2001, 2002, 2003, 2004, 2005 Stijn van Dongen
2  *   (C) Copyright 2006, 2007, 2008, 2009  Stijn van Dongen
3  *
4  * This file is part of tingea.  You can redistribute and/or modify tingea
5  * under the terms of the GNU General Public License; either version 3 of the
6  * License or (at your option) any later version.  You should have received a
7  * copy of the GPL along with tingea, in the file COPYING.
8 */
9 
10 #ifndef tingea_heap_h
11 #define tingea_heap_h
12 
13 /*    Use a heap to compute the K largest elements according to some sortin
14  *    criterion.
15  *    Note that a new element only has to be compared with the root (when
16  *    the heap is at full capacity) to know whether it should enter the heap
17  *    and evict the root.
18 */
19 
20 typedef struct
21 {  void     *base
22 ;  dim      heapSize
23 ;  dim      elemSize
24 ;  int      (*cmp)(const void* lft, const void* rgt)
25 ;  dim      n_inserted
26 ;
27 }  mcxHeap  ;
28 
29 
30 mcxHeap* mcxHeapInit
31 (  void*    heap
32 )  ;
33 
34 
35 mcxHeap* mcxHeapNew
36 (  mcxHeap* heap
37 ,  dim      heapSize
38 ,  dim      elemSize
39 ,  int      (*cmp)(const void* lft, const void* rgt)
40 )  ;
41 
42 
43 void mcxHeapFree
44 (  mcxHeap**   heap
45 )  ;
46 
47 void mcxHeapRelease
48 (  void* heapv
49 )  ;
50 
51 void mcxHeapClean
52 (  mcxHeap*   heap
53 )  ;
54 
55 void mcxHeapInsert
56 (  mcxHeap* heap
57 ,  void*    elem
58 )  ;
59 
60 
61 #endif
62 
63