[3168] | 1 | /* $Id: avl.h,v 1.3 2000-03-19 16:00:10 bird Exp $
|
---|
[1467] | 2 | *
|
---|
| 3 | * AVL-Tree (lookalike) declaration.
|
---|
| 4 | *
|
---|
[3168] | 5 | * This AVL implementation is configurable from this headerfile. By
|
---|
| 6 | * for example alterning the AVLKEY typedefinition an the AVL_<L|G|E|N>[E]
|
---|
| 7 | * macros you are able to create different trees. Currently you may only have
|
---|
| 8 | * one type of trees within one program (module).
|
---|
[1467] | 9 | *
|
---|
[3168] | 10 | * TREETYPE: unsigned long key.
|
---|
| 11 | *
|
---|
| 12 | *
|
---|
| 13 | * Copyright (c) 1999-2000 knut st. osmundsen
|
---|
| 14 | *
|
---|
[1467] | 15 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 16 | *
|
---|
| 17 | */
|
---|
| 18 | #ifndef _AVL_H_
|
---|
| 19 | #define _AVL_H_
|
---|
| 20 |
|
---|
| 21 | #ifdef __cplusplus
|
---|
| 22 | extern "C" {
|
---|
| 23 | #endif
|
---|
| 24 |
|
---|
[2501] | 25 | /*
|
---|
| 26 | * AVL configuration. PRIVATE!
|
---|
| 27 | */
|
---|
[3168] | 28 | #define AVL_MAX_HEIGHT 19 /* Up to 2^16 nodes. */
|
---|
| 29 | #undef AVL_MAY_TRY_INSERT_EQUAL /* No duplicate key! */
|
---|
[2501] | 30 |
|
---|
[3168] | 31 |
|
---|
| 32 | /*
|
---|
| 33 | * AVL Compare macros
|
---|
| 34 | */
|
---|
| 35 | #define AVL_L(key1, key2) ((key1) < (key2))
|
---|
| 36 | #define AVL_LE(key1, key2) ((key1) <= (key2))
|
---|
| 37 | #define AVL_G(key1, key2) ((key1) > (key2))
|
---|
| 38 | #define AVL_GE(key1, key2) ((key1) >= (key2))
|
---|
| 39 | #define AVL_E(key1, key2) ((key1) == (key2))
|
---|
| 40 | #define AVL_NE(key1, key2) ((key1) != (key2))
|
---|
| 41 |
|
---|
| 42 |
|
---|
[1467] | 43 | /**
|
---|
| 44 | * AVL key type
|
---|
| 45 | */
|
---|
| 46 | typedef unsigned long AVLKEY;
|
---|
| 47 |
|
---|
[3168] | 48 |
|
---|
[1467] | 49 | /**
|
---|
| 50 | * AVL Core node.
|
---|
| 51 | */
|
---|
| 52 | typedef struct _AVLNodeCore
|
---|
| 53 | {
|
---|
[2501] | 54 | AVLKEY Key; /* Key value. */
|
---|
[1467] | 55 | struct _AVLNodeCore * pLeft; /* Pointer to left leaf node. */
|
---|
| 56 | struct _AVLNodeCore * pRight; /* Pointer to right leaf node. */
|
---|
[2501] | 57 | unsigned char uchHeight; /* Height of this tree: max(heigth(left), heigth(right)) + 1 */
|
---|
[1467] | 58 | } AVLNODECORE, *PAVLNODECORE, **PPAVLNODECORE;
|
---|
| 59 |
|
---|
[3168] | 60 |
|
---|
[2501] | 61 | /**
|
---|
| 62 | * AVL Enum data - All members are PRIVATE! Don't touch!
|
---|
| 63 | */
|
---|
| 64 | typedef struct _AVLEnumData
|
---|
| 65 | {
|
---|
| 66 | char fFromLeft;
|
---|
| 67 | char cEntries;
|
---|
| 68 | char achFlags[AVL_MAX_HEIGHT];
|
---|
| 69 | PAVLNODECORE aEntries[AVL_MAX_HEIGHT];
|
---|
| 70 | } AVLENUMDATA, *PAVLENUMDATA;
|
---|
[1467] | 71 |
|
---|
| 72 |
|
---|
[2501] | 73 | /*
|
---|
| 74 | * callback type
|
---|
| 75 | */
|
---|
| 76 | typedef unsigned ( _PAVLCALLBACK)(PAVLNODECORE, void*);
|
---|
| 77 | typedef _PAVLCALLBACK *PAVLCALLBACK;
|
---|
[1467] | 78 |
|
---|
[2501] | 79 |
|
---|
[3168] | 80 | BOOL AVLInsert(PPAVLNODECORE ppTree, PAVLNODECORE pNode);
|
---|
[2501] | 81 | PAVLNODECORE AVLRemove(PPAVLNODECORE ppTree, AVLKEY Key);
|
---|
| 82 | PAVLNODECORE AVLGet(PPAVLNODECORE ppTree, AVLKEY Key);
|
---|
| 83 | PAVLNODECORE AVLGetWithParent(PPAVLNODECORE ppTree, PPAVLNODECORE ppParent, AVLKEY Key);
|
---|
| 84 | PAVLNODECORE AVLGetWithAdjecentNodes(PPAVLNODECORE ppTree, AVLKEY Key, PPAVLNODECORE ppLeft, PPAVLNODECORE ppRight);
|
---|
| 85 | unsigned AVLDoWithAll(PPAVLNODECORE ppTree, int fFromLeft, PAVLCALLBACK pfnCallBack, void *pvParam);
|
---|
| 86 | PAVLNODECORE AVLBeginEnumTree(PPAVLNODECORE ppTree, PAVLENUMDATA pEnumData, int fFromLeft);
|
---|
| 87 | PAVLNODECORE AVLGetNextNode(PAVLENUMDATA pEnumData);
|
---|
| 88 | PAVLNODECORE AVLGetBestFit(PPAVLNODECORE ppTree, AVLKEY Key, int fAbove);
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 |
|
---|
[1467] | 92 | /*
|
---|
| 93 | * Just in case NULL is undefined.
|
---|
| 94 | */
|
---|
| 95 | #ifndef NULL
|
---|
| 96 | #define NULL ((void*)0)
|
---|
| 97 | #endif
|
---|
| 98 |
|
---|
| 99 | #ifdef __cplusplus
|
---|
| 100 | }
|
---|
| 101 | #endif
|
---|
| 102 |
|
---|
| 103 | #endif
|
---|