ScummVM API documentation
iavl_tree.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NUVIE_MISC_IAVL_TREE_H
23 #define NUVIE_MISC_IAVL_TREE_H
24 
25 namespace Ultima {
26 namespace Nuvie {
27 
28 /* typedef the keytype */
29 // TODO: Clean up object manager so it isn't intermixing pointers and ints
30 //typedef long iAVLKey;
31 union iAVLKey {
32  void *_ptr;
33  long _int;
34 };
35 
36 /* Comparison function for integers is subtraction. */
37 #define iAVLKey_cmp(tree, a, b) ((a._int) - (b._int))
38 
39 
40 typedef struct _iAVLNode {
41  iAVLKey key;
42  long depth;
43  void *item;
44  struct _iAVLNode *parent;
45  struct _iAVLNode *left;
46  struct _iAVLNode *right;
47 } iAVLNode;
48 
49 
50 typedef struct {
51  iAVLNode *top;
52  long count;
53  iAVLKey(*getkey)(const void *item);
54 } iAVLTree;
55 
56 
57 typedef struct {
58  const iAVLTree *avltree;
59  const iAVLNode *curnode;
60 } iAVLCursor;
61 
62 
63 extern iAVLTree *iAVLAllocTree(iAVLKey(*getkey)(void const *item));
64 extern void iAVLFreeTree(iAVLTree *avltree, void (freeitem)(void *item));
65 extern void iAVLCleanTree(iAVLTree *avltree, void (freeitem)(void *item));
66 extern int iAVLInsert(iAVLTree *avltree, void *item);
67 extern void *iAVLSearch(iAVLTree const *avltree, iAVLKey key);
68 extern int iAVLDelete(iAVLTree *avltree, iAVLKey key);
69 extern void *iAVLFirst(iAVLCursor *avlcursor, iAVLTree const *avltree);
70 extern void *iAVLNext(iAVLCursor *avlcursor);
71 
72 } // End of namespace Nuvie
73 } // End of namespace Ultima
74 
75 #endif
Definition: iavl_tree.h:50
Definition: iavl_tree.h:57
Definition: detection.h:27
Definition: iavl_tree.h:40
Definition: iavl_tree.h:31