BTreeBuilder.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/btree/BTreeBuilder.h#11 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #ifndef Fennel_BTreeBuilder_Included
00025 #define Fennel_BTreeBuilder_Included
00026 
00027 #include "fennel/btree/BTreeAccessBase.h"
00028 
00029 #include <vector>
00030 
00031 FENNEL_BEGIN_NAMESPACE
00032 
00033 class BTreeBuildLevel;
00034 typedef boost::shared_ptr<BTreeBuildLevel> SharedBTreeBuildLevel;
00035 
00036 // TODO:  doc internals
00037 
00049 class FENNEL_BTREE_EXPORT BTreeBuilder
00050     : public BTreeAccessBase
00051 {
00052     // TODO:  something better
00053     friend class BTreeBuildLevel;
00054     friend class FixedBuildLevel;
00055     friend class VariableBuildLevel;
00056     friend class DynamicBuildLevel;
00057 
00058     std::vector<SharedBTreeBuildLevel> levels;
00059 
00060     SharedSegment pTempSegment;
00061 
00062 // ----------------------------------------------------------------------
00063 // internal helper methods
00064 // ----------------------------------------------------------------------
00065 
00066     static uint calculateChildEntriesPerNode(
00067         RecordNum parentLevelTotalEntries,
00068         RecordNum childLevelTotalEntries,
00069         RecordNum parentLevelProcessedEntries);
00070 
00071     static uint calculateNodesOnLevel(
00072         uint nChildEntries,uint nEntriesPerChildNode);
00073 
00074     uint getRootHeight()
00075     {
00076         return levels.size() - 1;
00077     }
00078 
00079     void buildBalanced(
00080         ByteInputStream &sortedStream,
00081         uint iInputLevel,
00082         RecordNum nEntriesTotal,
00083         double fillFactor);
00084 
00085     void buildTwoPass(
00086         ByteInputStream &sortedStream,
00087         RecordNum nEntries,
00088         double fillFactor);
00089 
00090     void buildUnbalanced(
00091         ByteInputStream &sortedStream,
00092         RecordNum nEntries,
00093         double fillFactor);
00094 
00095     void processInput(
00096         ByteInputStream &sortedStream);
00097 
00098     inline BTreeBuildLevel &getLevel(uint i);
00099 
00100     void growTree();
00101 
00102     void swapRoot();
00103 
00104     void truncateChildren(BTreeNode const &node);
00105     void truncateExternal(TupleProjection const &leafPageIdProj);
00106 
00107 public:
00119     explicit BTreeBuilder(
00120         BTreeDescriptor const &descriptor,
00121         SharedSegment pTempSegment = SharedSegment());
00122     virtual ~BTreeBuilder();
00123 
00136     void build(
00137         ByteInputStream &sortedStream,
00138         RecordNum nEntries,
00139         double fillFactor = 1.0);
00140 
00146     void createEmptyRoot();
00147 
00159     void truncate(
00160         bool rootless,
00161         TupleProjection const *pLeafPageIdProj = NULL);
00162 };
00163 
00164 inline BTreeBuildLevel &BTreeBuilder::getLevel(uint i)
00165 {
00166     return *(levels[i]);
00167 }
00168 
00169 FENNEL_END_NAMESPACE
00170 
00171 #endif
00172 
00173 // End BTreeBuilder.h

Generated on Mon Jun 22 04:00:13 2009 for Fennel by  doxygen 1.5.1