File: heap.h

package info (click to toggle)
zoem 08-248-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,752 kB
  • ctags: 2,074
  • sloc: ansic: 17,928; sh: 789; makefile: 228
file content (82 lines) | stat: -rw-r--r-- 1,856 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*   (C) Copyright 2001, 2002, 2003, 2004, 2005 Stijn van Dongen
 *   (C) Copyright 2006, 2007 Stijn van Dongen
 *
 * This file is part of tingea.  You can redistribute and/or modify tingea
 * under the terms of the GNU General Public License; either version 3 of the
 * License or (at your option) any later version.  You should have received a
 * copy of the GPL along with tingea, in the file COPYING.
*/


/* TODO
 *    interface that copies old element someplace.
 *    interface that copies new element destination someplace.
 *    heap merges (for mcxdiameter application [binomial heaps])
 *    removal by key.
 *    key lookup/increment.
*/

#ifndef tingea_heap_h
#define tingea_heap_h


/*    With a min-heap the parents are smaller than the children.
 *    Use a min-heap to compute the K largest elements.
 *    (notice that a new element only has to be compared with the root (when
 *    the heap is at full capacity) to know whether it should enter the heap
 *    and evict the root.
 *
 *    Vice versa, compute K smallest elements with a max-heap.
*/

enum
{  MCX_MIN_HEAP = 10000   /*    find large elements                 */
,  MCX_MAX_HEAP           /*    find small elements                 */
}  ;


typedef struct
{  void     *base
;  dim      heapSize
;  dim      elemSize
;  int      (*cmp)(const void* lft, const void* rgt)
;  mcxenum  type
;  dim      n_inserted
;
}  mcxHeap  ;


mcxHeap* mcxHeapInit
(  void*    heap
)  ;


mcxHeap* mcxHeapNew
(  mcxHeap* heap
,  dim      heapSize
,  dim      elemSize
,  int      (*cmp)(const void* lft, const void* rgt)
,  mcxenum  HEAPTYPE          /* MCX_MIN_HEAP or MCX_MAX_HEAP */
)  ;


void mcxHeapFree
(  mcxHeap**   heap
)  ;

void mcxHeapRelease
(  void* heapv
)  ;  

void mcxHeapClean
(  mcxHeap*   heap
)  ;  

void mcxHeapInsert
(  mcxHeap* heap
,  void*    elem
)  ;


#endif