BTreeNodeAccessor.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/btree/BTreeNodeAccessor.h#16 $
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_BTreeNodeAccessor_Included
00025 #define Fennel_BTreeNodeAccessor_Included
00026 
00027 #include "fennel/tuple/TupleDescriptor.h"
00028 #include "fennel/tuple/TupleAccessor.h"
00029 #include "fennel/tuple/TupleData.h"
00030 #include "fennel/btree/BTreeNode.h"
00031 
00032 FENNEL_BEGIN_NAMESPACE
00033 
00054 class FENNEL_BTREE_EXPORT BTreeNodeAccessor
00055 {
00056 public:
00060     TupleDescriptor tupleDescriptor;
00061 
00066     TupleAccessor tupleAccessor;
00067 
00072     TupleData tupleData;
00073 
00074     virtual ~BTreeNodeAccessor();
00075 
00087     inline uint getKeyCount(BTreeNode const &node) const;
00088 
00097     virtual void clearNode(BTreeNode &node,uint cbPage);
00098 
00110     virtual PBuffer allocateEntry(
00111         BTreeNode &node,uint iEntry,uint cbEntry) = 0;
00112 
00120     virtual void deallocateEntry(
00121         BTreeNode &node,uint iEntry) = 0;
00122 
00132     virtual PConstBuffer getEntryForRead(
00133         BTreeNode const &node,uint iEntry) = 0;
00134 
00135     // NOTE jvs 10-Feb-2006:  This is commented out to indicate that subclasses
00136     // need to implement a corresponding inline to be usable with
00137     // BTreeKeyedNodeAccessor; avoid declaring it virtual to make sure the
00138     // compiler doesn't get confused about whether it should be inlined.
00139     /*
00140     virtual PConstBuffer getEntryForReadInline(
00141         BTreeNode const &node,uint iEntry) = 0;
00142     */
00143 
00148     virtual void onInit();
00149 
00159     void dumpNode(std::ostream &os,BTreeNode const &node,PageId pageId);
00160 
00166     virtual bool hasFixedWidthEntries() const = 0;
00167 
00175     virtual void accessTuple(BTreeNode const &node,uint iEntry) = 0;
00176 
00197     virtual uint binarySearch(
00198         BTreeNode const &node,
00199         TupleDescriptor const &keyDescriptor,
00200         TupleData const &searchKey,
00201         DuplicateSeek dupSeek,
00202         bool leastUpper,
00203         TupleData &scratchKey,
00204         bool &found) = 0;
00205 
00219     virtual int compareFirstKey(
00220         BTreeNode const &node,
00221         TupleDescriptor const &keyDescriptor,
00222         TupleData const &searchKey,
00223         TupleData &scratchKey) = 0;
00224 
00232     virtual void accessTupleInline(BTreeNode const &node, uint iEntry) = 0;
00233 
00238     enum Capacity {
00242         CAN_FIT,
00246         CAN_FIT_WITH_COMPACTION,
00247 
00251         CAN_NOT_FIT
00252     };
00253 
00263     virtual Capacity calculateCapacity(
00264         BTreeNode const &node,uint cbEntry) = 0;
00265 
00273     virtual uint getEntryByteCount(uint cbTuple) = 0;
00274 
00280     virtual void unmarshalKey(TupleData &keyData) = 0;
00281 
00289     virtual void compactNode(BTreeNode &node,BTreeNode &scratchNode);
00290 
00304     virtual void splitNode(
00305         BTreeNode &node,BTreeNode &newNode,uint cbNewTuple,bool monotonic);
00306 };
00307 
00308 inline uint BTreeNodeAccessor::getKeyCount(BTreeNode const &node) const
00309 {
00310     if (node.height && (node.rightSibling == NULL_PAGE_ID)) {
00311         // For non-leaf nodes on the rightmost fringe, we pretend the last
00312         // key is +infinity, and ignore whatever's actually stored
00313         // there (except for its child PageId).
00314         assert(node.nEntries);
00315         return node.nEntries - 1;
00316     }
00317     return node.nEntries;
00318 }
00319 
00320 FENNEL_END_NAMESPACE
00321 
00322 #endif
00323 
00324 // End BTreeNodeAccessor.h

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