00001 #ifndef MMANN_GLIBTREE_H
00002 #define MMANN_GLIBTREE_H
00003
00011
00012 #include <iostream.h>
00013 #include "RedBlackTree.h"
00014 #include "GLIBNode.h"
00015
00020 template <class Data, class ConfigData>
00021 class GLIBTree : public AGenericTree<Data, ConfigData>
00022 {
00023 public:
00025 GLIBTree(ACompareNodesAlgorithm<Data, ConfigData>* Compare, DeleteTreeDataEnum DeleteTreeData = NO_DELETE_TREE_ITEM,
00026 ConfigData* pConfigData = NULL);
00027
00029 virtual ~GLIBTree();
00030
00036 virtual Data* Search(Data* NodeData, bool* NodeInserted);
00037
00042 virtual Data* Find(Data* NodeData);
00043
00048 Data* Delete(Data* NodeData);
00049
00053 void Insert(Data* NodeData);
00054
00058 int GetHeight();
00059
00063 int GetNumberOfNodes();
00064
00065 private:
00067 GLIBTreeNode<Data, ConfigData> *m_Root;
00068 };
00069
00070 template <class Data, class ConfigData>
00071 GLIBTree<Data, ConfigData>::GLIBTree(ACompareNodesAlgorithm<Data, ConfigData>* Compare, DeleteTreeDataEnum DeleteTreeData,
00072 ConfigData* pConfigData) : AGenericTree<Data, ConfigData>(Compare, DeleteTreeData, pConfigData)
00073 {
00074 m_Root = NULL;
00075 }
00076
00077 template <class Data, class ConfigData>
00078 GLIBTree<Data, ConfigData>::~GLIBTree()
00079 {
00080 if (m_Root != NULL)
00081 GLIBTreeNode<Data, ConfigData>::DeleteAllGLIBTreeNodes(m_Root, m_DeleteTreeData);
00082 }
00083
00084
00085 template <class Data, class ConfigData>
00086 void GLIBTree<Data, ConfigData>::Insert(Data* NodeData)
00087 {
00088 bool Inserted = false;
00089
00090 m_Root = GLIBTreeNode<Data, ConfigData>::Insert(m_Root, m_CompareNodes, NodeData, &Inserted);
00091 }
00092
00093
00094 template <class Data, class ConfigData>
00095 Data* GLIBTree<Data, ConfigData>::Delete(Data* NodeData)
00096 {
00097 m_Root = GLIBTreeNode<Data, ConfigData>::Remove(m_Root, m_CompareNodes, NodeData);
00098 return NodeData;
00099 }
00100
00101
00102 template <class Data, class ConfigData>
00103 Data* GLIBTree<Data, ConfigData>::Find(Data* NodeData)
00104 {
00105 return GLIBTreeNode<Data, ConfigData>::Lookup(m_Root, m_CompareNodes, NodeData);
00106 }
00107
00108 template <class Data, class ConfigData>
00109 Data* GLIBTree<Data, ConfigData>::Search(Data* NodeData, bool* NodeInserted)
00110 {
00111 *NodeInserted = false;
00112 if (m_Root != NULL)
00113 {
00114 Data *Temp = GLIBTreeNode<Data, ConfigData>::Search(m_Root, m_CompareNodes, NodeData);
00115 if (Temp == NULL)
00116 {
00117 *NodeInserted = true;
00118 Insert(NodeData);
00119 }
00120
00121 return Temp;
00122 }
00123
00124 *NodeInserted = true;
00125 Insert(NodeData);
00126 return NULL;
00127 }
00128
00129 template <class Data, class ConfigData>
00130 int GLIBTree<Data, ConfigData>::GetHeight()
00131 {
00132 if (m_Root != NULL)
00133 return GLIBTreeNode<Data, ConfigData>::GetHeight(m_Root);
00134 else
00135 return 0;
00136 }
00137
00138 template <class Data, class ConfigData>
00139 int GLIBTree<Data, ConfigData>::GetNumberOfNodes()
00140 {
00141 if (m_Root != NULL)
00142 return GLIBTreeNode<Data, ConfigData>::GetNodeCount(m_Root);
00143 else
00144 return 0;
00145 }
00146
00147 #endif