BTreeHeapNodeAccessor.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/btree/BTreeHeapNodeAccessor.cpp#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 #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     // calculate the end of the compact free space, and subtract off
00049     // the entry size to determine where the entry should be stored
00050     PBuffer pAllocation =
00051         reinterpret_cast<PBuffer>(pFirstEntryOffset + node.nEntries)
00052         + node.cbCompactFree - cbEntry;
00053 
00054     // make room in the offset array
00055     EntryOffset *pEntryOffset = pFirstEntryOffset + iEntry;
00056     memmove(
00057         pEntryOffset + 1,
00058         pEntryOffset,
00059         getEntryOffsetArrayByteSize(node.nEntries - iEntry));
00060     // and write the new offset into the slot just vacated
00061     *pEntryOffset = pAllocation - reinterpret_cast<PBuffer>(&node);
00062 
00063     // update node control info
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     // see comments in BTreeCompactNodeAccessor::deallocateEntry
00078     if (iEntry != node.nEntries - 1) {
00079         // delete the entry from the offset array
00080         EntryOffset *pEntryOffset = getEntryOffsetPointer(node,iEntry);
00081         memmove(
00082             pEntryOffset,
00083             pEntryOffset + 1,
00084             getEntryOffsetArrayByteSize(node.nEntries - (iEntry + 1)));
00085     }
00086 
00087     // update node control info
00088     node.nEntries--;
00089     node.cbTotalFree += getEntrySizeWithOverhead(cbEntry);
00090 }
00091 
00092 bool BTreeHeapNodeAccessor::hasFixedWidthEntries() const
00093 {
00094     return false;
00095 
00096     // REVIEW:  we might choose to store fixed-width entries in a heap just to
00097     // save on memmmove cost
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 // End BTreeHeapNodeAccessor.cpp

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