OSDN Git Service

日本語版
[nazghul-jp/nazghul-jp.git] / src / heap.h
1 //
2 // nazghul - an old-school RPG engine
3 // Copyright (C) 2002, 2003 Gordon McNutt
4 //
5 // This program is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 2 of the License, or (at your option)
8 // any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13 // more details.
14 //
15 // You should have received a copy of the GNU General Public License along with
16 // this program; if not, write to the Free Foundation, Inc., 59 Temple Place,
17 // Suite 330, Boston, MA 02111-1307 USA
18 //
19 // Gordon McNutt
20 // gmcnutt@users.sourceforge.net
21 //
22 #ifndef heap_h
23 #define heap_h
24
25 #include "macros.h"
26
27 BEGIN_DECL
28
29 #define heap_entry(ptr,type,field) \
30         ((type*)((char*)(ptr)-(unsigned long)(&((type *)0)->field)))
31
32 #define heap_empty(h) (!(h)->num_entries)
33
34 struct heap {
35         unsigned int max_entries;
36         unsigned int num_entries;
37         int **entries;
38 };
39
40 extern struct heap *heap_create(unsigned int max_entries);
41 extern void heap_destroy(struct heap *heap);
42 extern void heapify(struct heap *heap, int i);
43 extern int heap_expand(struct heap *heap);
44 extern int heap_insert(struct heap *heap, int *entry);
45 extern int *heap_extract(struct heap *heap);
46 extern void heap_clean(struct heap *heap);
47
48 END_DECL
49
50 #endif