00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "fennel/common/CommonPreamble.h"
00025 #include "fennel/btree/BTreeHeapNodeAccessor.h"
00026
00027 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/btree/BTreeHeapNodeAccessor.cpp#9 $");
00028
00029 BTreeHeapNodeAccessor::BTreeHeapNodeAccessor()
00030 {
00031 }
00032
00033 void BTreeHeapNodeAccessor::clearNode(BTreeNode &node,uint cbPage)
00034 {
00035 BTreeNodeAccessor::clearNode(node,cbPage);
00036 node.cbCompactFree = node.cbTotalFree;
00037 }
00038
00039 PBuffer BTreeHeapNodeAccessor::allocateEntry(
00040 BTreeNode &node,uint iEntry,uint cbEntry)
00041 {
00042 uint cbEntryWithOverhead = getEntrySizeWithOverhead(cbEntry);
00043 assert(iEntry < node.nEntries + 1);
00044 assert(node.cbCompactFree >= cbEntryWithOverhead);
00045
00046 EntryOffset *pFirstEntryOffset = getEntryOffsetPointer(node,0);
00047
00048
00049
00050 PBuffer pAllocation =
00051 reinterpret_cast<PBuffer>(pFirstEntryOffset + node.nEntries)
00052 + node.cbCompactFree - cbEntry;
00053
00054
00055 EntryOffset *pEntryOffset = pFirstEntryOffset + iEntry;
00056 memmove(
00057 pEntryOffset + 1,
00058 pEntryOffset,
00059 getEntryOffsetArrayByteSize(node.nEntries - iEntry));
00060
00061 *pEntryOffset = pAllocation - reinterpret_cast<PBuffer>(&node);
00062
00063
00064 node.nEntries++;
00065 node.cbTotalFree -= cbEntryWithOverhead;
00066 node.cbCompactFree -= cbEntryWithOverhead;
00067
00068 return pAllocation;
00069 }
00070
00071 void BTreeHeapNodeAccessor::deallocateEntry(
00072 BTreeNode &node,uint iEntry)
00073 {
00074 tupleAccessor.setCurrentTupleBuf(getEntryForReadInline(node,iEntry));
00075 uint cbEntry = tupleAccessor.getCurrentByteCount();
00076
00077
00078 if (iEntry != node.nEntries - 1) {
00079
00080 EntryOffset *pEntryOffset = getEntryOffsetPointer(node,iEntry);
00081 memmove(
00082 pEntryOffset,
00083 pEntryOffset + 1,
00084 getEntryOffsetArrayByteSize(node.nEntries - (iEntry + 1)));
00085 }
00086
00087
00088 node.nEntries--;
00089 node.cbTotalFree += getEntrySizeWithOverhead(cbEntry);
00090 }
00091
00092 bool BTreeHeapNodeAccessor::hasFixedWidthEntries() const
00093 {
00094 return false;
00095
00096
00097
00098 #if 0
00099 return tupleAccessor.isFixedWidth();
00100 #endif
00101 }
00102
00103 BTreeNodeAccessor::Capacity
00104 BTreeHeapNodeAccessor::calculateCapacity(BTreeNode const &node,uint cbEntry)
00105 {
00106 uint cbEntryWithOverhead = getEntrySizeWithOverhead(cbEntry);
00107 if (cbEntryWithOverhead <= node.cbCompactFree) {
00108 return CAN_FIT;
00109 }
00110 if (cbEntryWithOverhead <= node.cbTotalFree) {
00111 return CAN_FIT_WITH_COMPACTION;
00112 }
00113 return CAN_NOT_FIT;
00114 }
00115
00116 uint BTreeHeapNodeAccessor::getEntryByteCount(uint cb)
00117 {
00118 return getEntrySizeWithOverhead(cb);
00119 }
00120
00121 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/btree/BTreeHeapNodeAccessor.cpp#9 $");
00122
00123