1 /* $Id: rbTree.h,v 1.5 2004/11/09 21:58:44 yooden Exp $ */
2 /*******************************************************************************
4 * rbTree.h -- Nirvana Editor Red-Black Balanced Binary Tree Header File *
6 * Copyright 2002 The NEdit Developers *
8 * This is free software; you can redistribute it and/or modify it under the *
9 * terms of the GNU General Public License as published by the Free Software *
10 * Foundation; either version 2 of the License, or (at your option) any later *
11 * version. In addition, you may distribute versions of this program linked to *
12 * Motif or Open Motif. See README for details. *
14 * This software is distributed in the hope that it will be useful, but WITHOUT *
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
19 * You should have received a copy of the GNU General Public License along with *
20 * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
21 * Place, Suite 330, Boston, MA 02111-1307 USA *
23 * Nirvana Text Editor *
26 *******************************************************************************/
28 #ifndef NEDIT_RBTREE_H_INCLUDED
29 #define NEDIT_RBTREE_H_INCLUDED
31 typedef struct rbTreeNode
{
32 struct rbTreeNode
*left
; /* left child */
33 struct rbTreeNode
*right
; /* right child */
34 struct rbTreeNode
*parent
; /* parent */
35 int color
; /* node color (rbTreeNodeBlack, rbTreeNodeRed) */
38 typedef int (*rbTreeCompareNodeCB
)(rbTreeNode
*left
, rbTreeNode
*right
);
39 typedef rbTreeNode
*(*rbTreeAllocateNodeCB
)(rbTreeNode
*src
);
40 typedef rbTreeNode
*(*rbTreeAllocateEmptyNodeCB
)(void);
41 typedef void (*rbTreeDisposeNodeCB
)(rbTreeNode
*src
);
42 typedef int (*rbTreeCopyToNodeCB
)(rbTreeNode
*dst
, rbTreeNode
*src
);
44 rbTreeNode
*rbTreeBegin(rbTreeNode
*base
);
45 rbTreeNode
*rbTreeReverseBegin(rbTreeNode
*base
);
46 rbTreeNode
*rbTreeFind(rbTreeNode
*base
, rbTreeNode
*searchNode
,
47 rbTreeCompareNodeCB compareRecords
);
48 rbTreeNode
*rbTreeInsert(rbTreeNode
*base
, rbTreeNode
*searchNode
,
49 rbTreeCompareNodeCB compareRecords
,
50 rbTreeAllocateNodeCB allocateNode
,
51 rbTreeCopyToNodeCB copyToNode
);
52 rbTreeNode
*rbTreeUnlinkNode(rbTreeNode
*base
, rbTreeNode
*z
);
53 void rbTreeDeleteNode(rbTreeNode
*base
, rbTreeNode
*foundNode
,
54 rbTreeDisposeNodeCB disposeNode
);
55 int rbTreeDelete(rbTreeNode
*base
, rbTreeNode
*searchNode
,
56 rbTreeCompareNodeCB compareRecords
,
57 rbTreeDisposeNodeCB disposeNode
);
58 rbTreeNode
*rbTreeNext(rbTreeNode
*x
);
59 rbTreeNode
*rbTreePrevious(rbTreeNode
*x
);
60 int rbTreeSize(rbTreeNode
*base
);
61 rbTreeNode
*rbTreeNew(rbTreeAllocateEmptyNodeCB allocateEmptyNode
);
62 void rbTreeDispose(rbTreeNode
*base
, rbTreeDisposeNodeCB disposeNode
);
64 #endif /* NEDIT_RBTREE_H_INCLUDED */