1 |
|
---|
2 | /*
|
---|
3 | *@@sourcefile tree.h:
|
---|
4 | * header file for tree.c (red-black balanced binary trees).
|
---|
5 | * See remarks there.
|
---|
6 | */
|
---|
7 |
|
---|
8 | #if __cplusplus
|
---|
9 | extern "C" {
|
---|
10 | #endif
|
---|
11 |
|
---|
12 | #ifndef XWPTREE_INCLUDED // Allow multiple inclusions
|
---|
13 | #define XWPTREE_INCLUDED
|
---|
14 |
|
---|
15 | #if (!defined OS2_INCLUDED) && (!defined _OS2_H) && (!defined __SIMPLES_DEFINED) // changed V0.9.0 (99-10-22) [umoeller]
|
---|
16 | typedef unsigned long BOOL;
|
---|
17 | typedef unsigned long ULONG;
|
---|
18 | typedef long *PLONG;
|
---|
19 | #define TRUE (BOOL)1
|
---|
20 | #define FALSE (BOOL)0
|
---|
21 |
|
---|
22 | #ifdef __IBMCPP__ // added V0.9.0 (99-10-22) [umoeller]
|
---|
23 | #define APIENTRY _System
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | #define __SIMPLES_DEFINED
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | typedef enum { BLACK, RED } nodeColor;
|
---|
30 |
|
---|
31 | /*
|
---|
32 | *@@ TREE:
|
---|
33 | * tree node.
|
---|
34 | *
|
---|
35 | * To use the tree functions, all your structures
|
---|
36 | * must have a TREE structure as their first member.
|
---|
37 | *
|
---|
38 | * Example:
|
---|
39 | *
|
---|
40 | + typedef struct _MYTREENODE
|
---|
41 | + {
|
---|
42 | + TREE tree;
|
---|
43 | + char acMyData[1000];
|
---|
44 | + } MYTREENODE, *PMYTREENODE;
|
---|
45 | *
|
---|
46 | * See tree.c for an introduction to the tree functions.
|
---|
47 | */
|
---|
48 |
|
---|
49 | typedef struct _TREE
|
---|
50 | {
|
---|
51 | struct _TREE *left,
|
---|
52 | *right,
|
---|
53 | *parent;
|
---|
54 | nodeColor color; // the node's color (BLACK, RED)
|
---|
55 |
|
---|
56 | ULONG ulKey; // the node's key (data)
|
---|
57 |
|
---|
58 | } TREE, *PTREE;
|
---|
59 |
|
---|
60 | #if defined(__IBMC__) || defined(__IBMCPP__)
|
---|
61 | #define TREEENTRY _Optlink
|
---|
62 | #else
|
---|
63 | // EMX or whatever: doesn't know calling conventions
|
---|
64 | #define TREEENTRY
|
---|
65 | #endif
|
---|
66 |
|
---|
67 | #define STATUS_OK 0
|
---|
68 | #define STATUS_DUPLICATE_KEY -1
|
---|
69 | #define STATUS_INVALID_NODE -2
|
---|
70 |
|
---|
71 | typedef int TREEENTRY FNTREE_COMPARE(ULONG ul1, ULONG ul2);
|
---|
72 |
|
---|
73 | // Function prototypes
|
---|
74 | void treeInit(TREE **root,
|
---|
75 | PLONG plCount);
|
---|
76 |
|
---|
77 | int TREEENTRY treeCompareKeys(ULONG ul1, ULONG ul2);
|
---|
78 |
|
---|
79 | int TREEENTRY treeCompareStrings(ULONG ul1, ULONG ul2);
|
---|
80 |
|
---|
81 | int treeInsert(TREE **root,
|
---|
82 | PLONG plCount,
|
---|
83 | TREE *x,
|
---|
84 | FNTREE_COMPARE *pfnCompare);
|
---|
85 |
|
---|
86 | int treeDelete(TREE **root,
|
---|
87 | PLONG plCount,
|
---|
88 | TREE *z);
|
---|
89 |
|
---|
90 | TREE* treeFind(TREE *root,
|
---|
91 | ULONG key,
|
---|
92 | FNTREE_COMPARE *pfnCompare);
|
---|
93 |
|
---|
94 | TREE* treeFirst(TREE *r);
|
---|
95 |
|
---|
96 | TREE* treeLast(TREE *r);
|
---|
97 |
|
---|
98 | TREE* treeNext(TREE *r);
|
---|
99 |
|
---|
100 | TREE* treePrev(TREE *r);
|
---|
101 |
|
---|
102 | TREE** treeBuildArray(TREE* pRoot,
|
---|
103 | PLONG plCount);
|
---|
104 |
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | #if __cplusplus
|
---|
108 | }
|
---|
109 | #endif
|
---|
110 |
|
---|