File indexing completed on 2024-07-21 08:05:24

0001 /***************************************************************************
0002  *   Copyright (C) 2004-2005 by Daniel Clarke                              *
0003  *   daniel.jc@gmail.com                                                   *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #ifndef BTREEBASE_H
0021 #define BTREEBASE_H
0022 #include "microbe.h"
0023 #include "btreenode.h"
0024 
0025 /**
0026 @short This holds a pointer to the start of the tree, and provides the traversal code.
0027 @author Daniel Clarke
0028 */
0029 class BTreeBase{
0030 public:
0031     BTreeBase();
0032     ~BTreeBase();
0033     
0034     /** Return a pointer to the root node of the tree */
0035     BTreeNode *root() const { return m_root; }
0036     
0037     /** Set the root node of the tree */
0038     void setRoot(BTreeNode *root){m_root = root; }
0039     
0040     /** Link the node into the tree. a.t.m all this really
0041     does it sets the parent/child relationship pointers, 
0042     but is used in case something needs to be changed in the future 
0043     Added to the left if left == true or the right if left == false */
0044     void addNode(BTreeNode *parent, BTreeNode *node, bool left);
0045 
0046     /** Deletes all nodes in tree and zeros pointer to root node */
0047     void deleteTree();
0048     
0049     /** Tidies the tree up; merging constants and removing redundant branches */
0050     void pruneTree(BTreeNode *root, bool conditionalRoot = true);
0051     
0052     /** Put a node in place of another, linking it correctly into the parent. */
0053     void replaceNode(BTreeNode *node, BTreeNode *replacement);
0054     
0055 protected:
0056     BTreeNode *m_root;    
0057 };
0058 
0059 #endif