00001 /* BEGIN_COPYRIGHT */ 00002 /* */ 00003 /* Open Diameter: Open-source software for the Diameter and */ 00004 /* Diameter related protocols */ 00005 /* */ 00006 /* Copyright (C) 2002-2004 Open Diameter Project */ 00007 /* */ 00008 /* This library is free software; you can redistribute it and/or modify */ 00009 /* it under the terms of the GNU Lesser General Public License as */ 00010 /* published by the Free Software Foundation; either version 2.1 of the */ 00011 /* License, or (at your option) any later version. */ 00012 /* */ 00013 /* This library is distributed in the hope that it will be useful, */ 00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ 00016 /* Lesser General Public License for more details. */ 00017 /* */ 00018 /* You should have received a copy of the GNU Lesser General Public */ 00019 /* License along with this library; if not, write to the Free Software */ 00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 */ 00021 /* USA. */ 00022 /* */ 00023 /* In addition, when you copy and redistribute some or the entire part of */ 00024 /* the source code of this software with or without modification, you */ 00025 /* MUST include this copyright notice in each copy. */ 00026 /* */ 00027 /* If you make any changes that are appeared to be useful, please send */ 00028 /* sources that include the changed part to */ 00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your */ 00030 /* changes to one unified version of this software. */ 00031 /* */ 00032 /* END_COPYRIGHT */ 00033 00034 #ifndef __UTL_RBTREE_H__ 00035 #define __UTL_RBTREE_H__ 00036 00037 typedef enum { 00038 RBTREE_CLR_BLACK, 00039 RBTREE_CLR_RED 00040 } RbTreeNodeColor; 00041 00042 class RbTreeData { 00043 public: 00044 // constructor 00045 RbTreeData() { payload = this; }; 00046 virtual ~RbTreeData() {}; 00047 00048 // exposed functions 00049 void *payload; 00050 00051 // methods 00052 virtual int operator < (RbTreeData &cmp) = 0; 00053 virtual int operator == (RbTreeData &cmp) = 0; 00054 virtual void clear(void *userData = 0) = 0; 00055 00056 // debugging only 00057 virtual void Dump(void *userData) {}; 00058 }; 00059 00060 class RbTreeNode { 00061 public: 00062 // constructor 00063 RbTreeNode(); 00064 00065 // exposed members 00066 RbTreeNode *left; 00067 RbTreeNode *right; 00068 RbTreeNode *parent; 00069 RbTreeNodeColor color; 00070 RbTreeData *data; 00071 00072 // methods 00073 RbTreeNode &operator=(RbTreeNode &source); 00074 }; 00075 00076 class RbTreeTree { 00077 public: 00078 // constructor 00079 RbTreeTree() { root = &nil; }; 00080 00081 // methods 00082 RbTreeData *Insert(RbTreeData *data); 00083 RbTreeData *Find(RbTreeData *data); 00084 RbTreeData *Remove(RbTreeData *data); 00085 void Clear(void *userData = 0); 00086 00087 // debugging only 00088 void Dump(RbTreeNode *x = 0, void *userData = 0); 00089 00090 private: 00091 RbTreeNode *root; 00092 RbTreeNode nil; 00093 00094 void FixupInsert(RbTreeNode *x); 00095 void FixupRemove(RbTreeNode *x); 00096 void RotateLeft(RbTreeNode *x); 00097 void RotateRight(RbTreeNode *x); 00098 }; 00099 00100 #endif /* __UTL_RBTREE_H__ */