Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

GLNodeBuffer.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Created on Tue Mar 11 14:32:26 PST 1997 by heydon
00020 
00021 // Last modified on Sat Apr 30 16:37:07 EDT 2005 by ken@xorian.net
00022 //      modified on Tue Dec 16 00:41:13 PST 1997 by heydon
00023 
00024 #include <Basics.H>
00025 #include <IntKey.H>
00026 #include <FS.H>
00027 #include <Table.H>
00028 #include <Sequence.H>
00029 #include <CacheIndex.H>
00030 #include "GLNode.H"
00031 #include "GLNodeBuffer.H"
00032 
00033 using std::ostream;
00034 
00035 GLNodeBuffer::GLNodeBuffer(int maxSize) throw ()
00036   : maxSize(maxSize)
00037 {
00038   this->tbl = NEW_CONSTR(GLNodeTbl, (/*sizeHint=*/ maxSize));
00039   this->seq = NEW_CONSTR(CISeq, (/*sizeHint=*/ maxSize));
00040 }
00041 
00042 bool GLNodeBuffer::Delete(CacheEntry::Index ci, /*OUT*/ GLNode &node) throw ()
00043 {
00044     GLNodeKids nodeKids;
00045     bool res;
00046     if ((res = this->tbl->Delete(IntKey(ci), /*OUT*/ nodeKids))) {
00047         node.ci = ci; node.kids = nodeKids.kids; node.refs = nodeKids.refs;
00048     }
00049     return res;
00050 }
00051 
00052 void GLNodeBuffer::Put(const GLNode &node, ostream &ofs) throw (FS::Failure)
00053 {
00054     // evict a node if necessary
00055     if (this->tbl->Size() >= this->maxSize) {
00056         // find the oldest node in the table & remove it
00057         CacheEntry::Index ci;
00058         GLNodeKids nodeKids;
00059         /* We have to loop here until we find a "ci" that is actually in
00060            "tbl", since many entries in the "this->seq" queue may have
00061            been deleted from "tbl" by calls to the "Delete" method above. */
00062         do {
00063             ci = this->seq->remlo();
00064         } while (!(this->tbl->Delete(IntKey(ci), /*OUT*/ nodeKids)));
00065 
00066         // write the node to "ofs"
00067         GLNode del(ci, nodeKids.kids, nodeKids.refs);
00068         del.Write(ofs);
00069         this->flushedCnt++;
00070     }
00071 
00072     // add the new node to the table
00073     GLNodeKids nodeKids(node.kids, node.refs);
00074     bool inTbl = this->tbl->Put(IntKey(node.ci), nodeKids);
00075     assert(!inTbl);
00076 
00077     // add this node to the sequence
00078     this->seq->addhi(node.ci);
00079 }

Generated on Mon May 8 00:48:59 2006 for Vesta by  doxygen 1.4.2