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 <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, ( maxSize));
00039 this->seq = NEW_CONSTR(CISeq, ( maxSize));
00040 }
00041
00042 bool GLNodeBuffer::Delete(CacheEntry::Index ci, GLNode &node) throw ()
00043 {
00044 GLNodeKids nodeKids;
00045 bool res;
00046 if ((res = this->tbl->Delete(IntKey(ci), 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
00055 if (this->tbl->Size() >= this->maxSize) {
00056
00057 CacheEntry::Index ci;
00058 GLNodeKids nodeKids;
00059
00060
00061
00062 do {
00063 ci = this->seq->remlo();
00064 } while (!(this->tbl->Delete(IntKey(ci), nodeKids)));
00065
00066
00067 GLNode del(ci, nodeKids.kids, nodeKids.refs);
00068 del.Write(ofs);
00069 this->flushedCnt++;
00070 }
00071
00072
00073 GLNodeKids nodeKids(node.kids, node.refs);
00074 bool inTbl = this->tbl->Put(IntKey(node.ci), nodeKids);
00075 assert(!inTbl);
00076
00077
00078 this->seq->addhi(node.ci);
00079 }