00001 /* 00002 // $Id: //open/dev/fennel/btree/BTreeCompactNodeAccessor.cpp#10 $ 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/BTreeCompactNodeAccessor.h" 00026 00027 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/btree/BTreeCompactNodeAccessor.cpp#10 $"); 00028 00029 BTreeCompactNodeAccessor::BTreeCompactNodeAccessor() 00030 { 00031 cbEntry = MAXU; 00032 } 00033 00034 void BTreeCompactNodeAccessor::onInit() 00035 { 00036 BTreeNodeAccessor::onInit(); 00037 cbEntry = tupleAccessor.getMaxByteCount(); 00038 } 00039 00040 PBuffer BTreeCompactNodeAccessor::allocateEntry( 00041 BTreeNode &node,uint iEntry,uint) 00042 { 00043 assert(iEntry < node.nEntries + 1); 00044 assert(node.cbTotalFree >= cbEntry); 00045 00046 // shift everything over to make room for the new entry 00047 PBuffer pBuffer = node.getDataForWrite() + iEntry*cbEntry; 00048 memmove( 00049 pBuffer + cbEntry, 00050 pBuffer, 00051 (node.nEntries - iEntry)*cbEntry); 00052 00053 // update node control info 00054 node.nEntries++; 00055 node.cbTotalFree -= cbEntry; 00056 return pBuffer; 00057 } 00058 00059 void BTreeCompactNodeAccessor::deallocateEntry( 00060 BTreeNode &node,uint iEntry) 00061 { 00062 assert(iEntry < node.nEntries); 00063 00064 // NOTE: this test is to avoid passing an address beyond the end of the 00065 // page to memmove. It should be unnecessary, since in that case the 00066 // number of bytes to be moved is 0, but paranoid memmove 00067 // implementations might complain. 00068 if (iEntry != node.nEntries - 1) { 00069 // shift over everything after the entry to delete it 00070 PBuffer pBuffer = node.getDataForWrite() + iEntry*cbEntry; 00071 memmove( 00072 pBuffer, 00073 pBuffer + cbEntry, 00074 (node.nEntries - (iEntry + 1))*cbEntry); 00075 } 00076 00077 // update node control info 00078 node.nEntries--; 00079 node.cbTotalFree += cbEntry; 00080 } 00081 00082 bool BTreeCompactNodeAccessor::hasFixedWidthEntries() const 00083 { 00084 return true; 00085 } 00086 00087 BTreeNodeAccessor::Capacity 00088 BTreeCompactNodeAccessor::calculateCapacity(BTreeNode const &node,uint cbEntry) 00089 { 00090 if (node.cbTotalFree >= cbEntry) { 00091 return CAN_FIT; 00092 } else { 00093 return CAN_NOT_FIT; 00094 } 00095 } 00096 00097 uint BTreeCompactNodeAccessor::getEntryByteCount(uint cb) 00098 { 00099 return cb; 00100 } 00101 00102 void BTreeCompactNodeAccessor::compactNode(BTreeNode &,BTreeNode &) 00103 { 00104 // Since we never return CAN_FIT_WITH_COMPACTION, no one should ever ask us 00105 // to do this. 00106 permAssert(false); 00107 } 00108 00109 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/btree/BTreeCompactNodeAccessor.cpp#10 $"); 00110 00111 // End BTreeCompactNodeAccessor.cpp