1 | /* $Id: avl.h,v 1.2 2000-01-22 18:20:59 bird Exp $
|
---|
2 | *
|
---|
3 | * AVL-Tree (lookalike) declaration.
|
---|
4 | *
|
---|
5 | * Copyright (c) 1999 knut st. osmundsen
|
---|
6 | *
|
---|
7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | *
|
---|
9 | */
|
---|
10 | #ifndef _AVL_H_
|
---|
11 | #define _AVL_H_
|
---|
12 |
|
---|
13 | #ifdef __cplusplus
|
---|
14 | extern "C" {
|
---|
15 | #endif
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * AVL configuration. PRIVATE!
|
---|
19 | */
|
---|
20 | #define AVL_MAX_HEIGHT 19 /* Up to 2^16 nodes. */
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * AVL key type
|
---|
24 | */
|
---|
25 | typedef unsigned long AVLKEY;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * AVL Core node.
|
---|
29 | */
|
---|
30 | typedef struct _AVLNodeCore
|
---|
31 | {
|
---|
32 | AVLKEY Key; /* Key value. */
|
---|
33 | struct _AVLNodeCore * pLeft; /* Pointer to left leaf node. */
|
---|
34 | struct _AVLNodeCore * pRight; /* Pointer to right leaf node. */
|
---|
35 | unsigned char uchHeight; /* Height of this tree: max(heigth(left), heigth(right)) + 1 */
|
---|
36 | } AVLNODECORE, *PAVLNODECORE, **PPAVLNODECORE;
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * AVL Enum data - All members are PRIVATE! Don't touch!
|
---|
40 | */
|
---|
41 | typedef struct _AVLEnumData
|
---|
42 | {
|
---|
43 | char fFromLeft;
|
---|
44 | char cEntries;
|
---|
45 | char achFlags[AVL_MAX_HEIGHT];
|
---|
46 | PAVLNODECORE aEntries[AVL_MAX_HEIGHT];
|
---|
47 | } AVLENUMDATA, *PAVLENUMDATA;
|
---|
48 |
|
---|
49 |
|
---|
50 | /*
|
---|
51 | * callback type
|
---|
52 | */
|
---|
53 | typedef unsigned ( _PAVLCALLBACK)(PAVLNODECORE, void*);
|
---|
54 | typedef _PAVLCALLBACK *PAVLCALLBACK;
|
---|
55 |
|
---|
56 |
|
---|
57 | void AVLInsert(PPAVLNODECORE ppTree, PAVLNODECORE pNode);
|
---|
58 | PAVLNODECORE AVLRemove(PPAVLNODECORE ppTree, AVLKEY Key);
|
---|
59 | PAVLNODECORE AVLGet(PPAVLNODECORE ppTree, AVLKEY Key);
|
---|
60 | PAVLNODECORE AVLGetWithParent(PPAVLNODECORE ppTree, PPAVLNODECORE ppParent, AVLKEY Key);
|
---|
61 | PAVLNODECORE AVLGetWithAdjecentNodes(PPAVLNODECORE ppTree, AVLKEY Key, PPAVLNODECORE ppLeft, PPAVLNODECORE ppRight);
|
---|
62 | unsigned AVLDoWithAll(PPAVLNODECORE ppTree, int fFromLeft, PAVLCALLBACK pfnCallBack, void *pvParam);
|
---|
63 | PAVLNODECORE AVLBeginEnumTree(PPAVLNODECORE ppTree, PAVLENUMDATA pEnumData, int fFromLeft);
|
---|
64 | PAVLNODECORE AVLGetNextNode(PAVLENUMDATA pEnumData);
|
---|
65 | PAVLNODECORE AVLGetBestFit(PPAVLNODECORE ppTree, AVLKEY Key, int fAbove);
|
---|
66 |
|
---|
67 |
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * Just in case NULL is undefined.
|
---|
71 | */
|
---|
72 | #ifndef NULL
|
---|
73 | #define NULL ((void*)0)
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | #ifdef __cplusplus
|
---|
77 | }
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | #endif
|
---|