LinearViewSegment.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/segment/LinearViewSegment.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/segment/LinearViewSegment.h"
00026 
00027 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/segment/LinearViewSegment.cpp#9 $");
00028 
00029 LinearViewSegment::LinearViewSegment(
00030     SharedSegment delegateSegment,
00031     PageId firstPageId)
00032     : DelegatingSegment(delegateSegment)
00033 {
00034     while (firstPageId != NULL_PAGE_ID) {
00035         // TODO:  something more efficient
00036         pageTable.push_back(firstPageId);
00037         firstPageId = DelegatingSegment::getPageSuccessor(firstPageId);
00038     }
00039 }
00040 
00041 LinearViewSegment::~LinearViewSegment()
00042 {
00043 }
00044 
00045 BlockId LinearViewSegment::translatePageId(PageId pageId)
00046 {
00047     assert(isPageIdAllocated(pageId));
00048     BlockNum blockNum = getLinearBlockNum(pageId);
00049     PageId underlyingPageId = pageTable[blockNum];
00050     return DelegatingSegment::translatePageId(underlyingPageId);
00051 }
00052 
00053 PageId LinearViewSegment::translateBlockId(BlockId blockId)
00054 {
00055     assert(!pageTable.empty());
00056     PageId underlyingPageId =
00057         DelegatingSegment::translateBlockId(blockId);
00058     std::vector<PageId>::const_iterator pFound;
00059     pFound = std::find(pageTable.begin(),pageTable.end(),underlyingPageId);
00060     assert(pFound != pageTable.end());
00061     return getLinearPageId(pFound - pageTable.begin());
00062 }
00063 
00064 BlockNum LinearViewSegment::getAllocatedSizeInPages()
00065 {
00066     return pageTable.size();
00067 }
00068 
00069 PageId LinearViewSegment::allocatePageId(PageOwnerId ownerId)
00070 {
00071     PageId underlyingPageId = DelegatingSegment::allocatePageId(ownerId);
00072     if (underlyingPageId == NULL_PAGE_ID) {
00073         return underlyingPageId;
00074     }
00075     if (!pageTable.empty()) {
00076         DelegatingSegment::setPageSuccessor(
00077             pageTable.back(),underlyingPageId);
00078     }
00079     PageId pageId = getLinearPageId(pageTable.size());
00080     pageTable.push_back(underlyingPageId);
00081     return pageId;
00082 }
00083 
00084 void LinearViewSegment::deallocatePageRange(PageId startPageId,PageId endPageId)
00085 {
00086     // TODO:  support truncation with startPageId != NULL_PAGE_ID
00087     assert(startPageId == NULL_PAGE_ID);
00088     assert(endPageId == NULL_PAGE_ID);
00089     pageTable.clear();
00090 }
00091 
00092 bool LinearViewSegment::isPageIdAllocated(PageId pageId)
00093 {
00094     return isLinearPageIdAllocated(pageId);
00095 }
00096 
00097 PageId LinearViewSegment::getFirstPageId() const
00098 {
00099     if (pageTable.empty()) {
00100         return NULL_PAGE_ID;
00101     } else {
00102         return pageTable.front();
00103     }
00104 }
00105 
00106 PageId LinearViewSegment::getPageSuccessor(PageId pageId)
00107 {
00108     return getLinearPageSuccessor(pageId);
00109 }
00110 
00111 void LinearViewSegment::setPageSuccessor(PageId pageId,PageId successorId)
00112 {
00113     setLinearPageSuccessor(pageId,successorId);
00114 }
00115 
00116 Segment::AllocationOrder LinearViewSegment::getAllocationOrder() const
00117 {
00118     return LINEAR_ALLOCATION;
00119 }
00120 
00121 PageId LinearViewSegment::updatePage(PageId pageId, bool needsTranslation)
00122 {
00123     assert(isPageIdAllocated(pageId));
00124     BlockNum blockNum = getLinearBlockNum(pageId);
00125     PageId underlyingPageId = pageTable[blockNum];
00126     return DelegatingSegment::updatePage(underlyingPageId, needsTranslation);
00127 }
00128 
00129 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/segment/LinearViewSegment.cpp#9 $");
00130 
00131 // End LinearViewSegment.cpp

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