00001 /* 00002 // $Id: //open/dev/fennel/btree/BTreeBuildLevel.h#9 $ 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_BTreeBuildLevel_Included 00025 #define Fennel_BTreeBuildLevel_Included 00026 00027 #include "fennel/btree/BTreeBuilder.h" 00028 #include "fennel/btree/BTreeNode.h" 00029 00030 #include <boost/scoped_array.hpp> 00031 00032 FENNEL_BEGIN_NAMESPACE 00033 00034 // TODO: doc internals 00035 00040 class FENNEL_BTREE_EXPORT BTreeBuildLevel 00041 { 00042 friend class BTreeBuilder; 00043 00044 protected: 00048 BTreeBuilder &builder; 00049 00053 BTreeNodeAccessor &nodeAccessor; 00054 00058 uint iLevel; 00059 00063 RecordNum iNode; 00064 00068 RecordNum nEntriesTotal; 00069 00073 BTreePageLock pageLock; 00074 00078 PageId pageId; 00079 00085 uint nEntriesPerNode; 00086 00092 RecordNum nEntriesProcessed; 00093 00098 uint cbReserved; 00099 00100 bool isFinished() const; 00101 00102 void processInput(ByteInputStream &sortedInputStream); 00103 00104 void unmarshalLastKey(); 00105 00106 BTreeNode *allocateAndLinkNewNode(); 00107 00108 BTreeNode &allocatePage(); 00109 00110 explicit BTreeBuildLevel( 00111 BTreeBuilder &builderInit, 00112 BTreeNodeAccessor &nodeAccessorInit); 00113 00114 virtual bool isNodeFull(BTreeNode const &node,uint cbTuple); 00115 00116 virtual void indexLastKey(bool finalize) = 0; 00117 00118 public: 00119 virtual ~BTreeBuildLevel(); 00120 00121 void indexLastChild(); 00122 }; 00123 00124 class FENNEL_BTREE_EXPORT FixedBuildLevel 00125 : public BTreeBuildLevel 00126 { 00127 friend class BTreeBuilder; 00128 00129 explicit FixedBuildLevel( 00130 BTreeBuilder &builderInit, 00131 BTreeNodeAccessor &nodeAccessorInit); 00132 00133 // implement the BTreeBuildLevel interface 00134 virtual void indexLastKey(bool finalize); 00135 virtual bool isNodeFull(BTreeNode const &node,uint cbTuple); 00136 }; 00137 00138 class FENNEL_BTREE_EXPORT VariableBuildLevel 00139 : public BTreeBuildLevel 00140 { 00141 friend class BTreeBuilder; 00142 00143 SharedSegOutputStream pParentKeyStream; 00144 00145 explicit VariableBuildLevel( 00146 BTreeBuilder &builderInit, 00147 BTreeNodeAccessor &nodeAccessorInit); 00148 00149 SharedSegInputStream getParentKeyStream(); 00150 00151 // implement the BTreeBuildLevel interface 00152 virtual void indexLastKey(bool finalize); 00153 00154 public: 00155 virtual ~VariableBuildLevel(); 00156 }; 00157 00158 class FENNEL_BTREE_EXPORT DynamicBuildLevel 00159 : public BTreeBuildLevel 00160 { 00161 friend class BTreeBuilder; 00162 00163 explicit DynamicBuildLevel( 00164 BTreeBuilder &builderInit, 00165 BTreeNodeAccessor &nodeAccessorInit); 00166 00167 // implement the BTreeBuildLevel interface 00168 virtual void indexLastKey(bool finalize); 00169 }; 00170 00171 FENNEL_END_NAMESPACE 00172 00173 #endif 00174 00175 // End BTreeBuildLevel.h