00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00136
00137
00138
00139
00140
00141
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
00312
00313
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