UNIXworkcode

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