GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
heap.h
Go to the documentation of this file.
1 /* LIBDGL -- a Directed Graph Library implementation
2  * Copyright (C) 2002 Roberto Micarelli
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /* best view tabstop=4
20  */
21 
22 #ifndef _DGL_HEAP_H_
23 #define _DGL_HEAP_H_
24 
25 typedef union _dglHeapData {
26  void *pv;
27  int n;
28  unsigned int un;
29  long l;
30  unsigned long ul;
31 
33 
34 typedef struct _dglHeapNode {
35  long key;
37  unsigned char flags;
38 
40 
41 typedef struct _dglHeap {
42 
43  long index; /* last node / number of current nodes (complete-binary-tree
44  array representation ...) */
45  long count; /* number of allocated nodes in ->pnode array */
46  long block; /* allocation block size expressed in number of nodes */
47  dglHeapNode_s *pnode; /* the node-array */
48 
50 
51 extern void dglHeapInit(dglHeap_s *pheap);
52 
53 typedef void (*dglHeapCancelItem_fn)(dglHeap_s *pheap, dglHeapNode_s *pitem);
54 extern void dglHeapFree(dglHeap_s *pheap, dglHeapCancelItem_fn pfnCancelItem);
55 
56 extern int dglHeapInsertMax(dglHeap_s *pheap, long key, unsigned char flags,
57  dglHeapData_u value);
58 
59 extern int dglHeapExtractMax(dglHeap_s *pheap, dglHeapNode_s *pnoderet);
60 
61 extern int dglHeapInsertMin(dglHeap_s *pheap, long key, unsigned char flags,
62  dglHeapData_u value);
63 
64 extern int dglHeapExtractMin(dglHeap_s *pheap, dglHeapNode_s *pnoderet);
65 
66 #endif
struct _dglHeapNode dglHeapNode_s
void(* dglHeapCancelItem_fn)(dglHeap_s *pheap, dglHeapNode_s *pitem)
Definition: heap.h:53
void dglHeapInit(dglHeap_s *pheap)
Definition: heap.c:27
int dglHeapInsertMin(dglHeap_s *pheap, long key, unsigned char flags, dglHeapData_u value)
Definition: heap.c:50
void dglHeapFree(dglHeap_s *pheap, dglHeapCancelItem_fn pfnCancelItem)
Definition: heap.c:35
int dglHeapExtractMax(dglHeap_s *pheap, dglHeapNode_s *pnoderet)
Definition: heap.c:134
struct _dglHeap dglHeap_s
int dglHeapInsertMax(dglHeap_s *pheap, long key, unsigned char flags, dglHeapData_u value)
Definition: heap.c:108
int dglHeapExtractMin(dglHeap_s *pheap, dglHeapNode_s *pnoderet)
Definition: heap.c:76
union _dglHeapData dglHeapData_u
long key
Definition: heap.h:35
unsigned char flags
Definition: heap.h:37
dglHeapData_u value
Definition: heap.h:36
Definition: heap.h:41
dglHeapNode_s * pnode
Definition: heap.h:47
long index
Definition: heap.h:43
long block
Definition: heap.h:46
long count
Definition: heap.h:45
unsigned int un
Definition: heap.h:28
void * pv
Definition: heap.h:26
unsigned long ul
Definition: heap.h:30
long l
Definition: heap.h:29
int n
Definition: heap.h:27