source: trunk/gsdl3/src/packages/mg/lib/mgheap.h@ 3745

Last change on this file since 3745 was 3745, checked in by mdewsnip, 21 years ago

Addition of MG package for search and retrieval

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/**************************************************************************
2 *
3 * mgheap.h -- Heap routines
4 * Copyright (C) 1994 Neil Sharman
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * $Id: mgheap.h 3745 2003-02-20 21:20:24Z mdewsnip $
21 *
22 **************************************************************************/
23
24/* Care should be taken when using these routines as NO error checking is
25 * done.
26 */
27
28
29
30/* The heap comparison routine should return
31 * <0 : If a should be before b
32 * 0 : If a and b are equal
33 * >0 : If a should be after b
34 */
35typedef int (*heap_comp) (void *a, void *b);
36
37
38/************************************************************************
39 *
40 * NOTE: If you choose to change the comparison function the first thing
41 * you do after changing the function is call heap_build.
42 *
43 */
44void heap_build (void *heap, int size, int num, heap_comp hc);
45
46
47
48/************************************************************************
49 *
50 * NOTE : The heap must be built before heap_sort is called.
51 * This has the effect of reversing the order of the array.
52 * e.g. if your comparison function is designed to pull the
53 * biggest thing off the heap first then the result of
54 * sorting with this function will be to put the bigest
55 * thing at the end of the array.
56 *
57 */
58void heap_sort (void *heap, int size, int num, heap_comp hc);
59
60/***********************************************************************
61 *
62 * NOTE: After deleting the head the heap will be one item shorter.
63 * The deleted item will be placed at the end of the heap.
64 *
65 */
66void heap_deletehead (void *heap, int size, int *num, heap_comp hc);
67
68
69/***********************************************************************
70 *
71 * If you change the "value" of the root node of the heap then you
72 * should call this to re-pritorize the heap.
73 *
74 */
75void heap_changedhead (void *heap, int size, int num, heap_comp hc);
76
77
78/***********************************************************************
79 *
80 * This assumes that the item has been added to the end of the
81 * array that is the heap. But that num has not been changed.
82 *
83 */
84void heap_additem (void *heap, int size, int *num, heap_comp hc);
Note: See TracBrowser for help on using the repository browser.