|
SNAP Library 2.0, User Reference
2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <blobbs.h>
Inherits TBlobBs.
Public Member Functions | |
| TGBlobBs (const TStr &BlobBsFNm, const TFAccess &_Access=faRdOnly, const int &_MxSegLen=-1) | |
| ~TGBlobBs () | |
| TGBlobBs & | operator= (const TGBlobBs &) |
| TStr | GetVersionStr () const |
| TBlobPt | PutBlob (const PSIn &SIn) |
| TBlobPt | PutBlob (const TBlobPt &BlobPt, const PSIn &SIn) |
| PSIn | GetBlob (const TBlobPt &BlobPt) |
| void | DelBlob (const TBlobPt &BlobPt) |
| TBlobPt | GetFirstBlobPt () |
| TBlobPt | FFirstBlobPt () |
| bool | FNextBlobPt (TBlobPt &TrvBlobPt, TBlobPt &BlobPt, PSIn &BlobSIn) |
Static Public Member Functions | |
| static PBlobBs | New (const TStr &BlobBsFNm, const TFAccess &Access=faRdOnly, const int &MxSegLen=-1) |
| static bool | Exists (const TStr &BlobBsFNm) |
Static Private Member Functions | |
| static TStr | GetNrBlobBsFNm (const TStr &BlobBsFNm) |
Private Attributes | |
| PFRnd | FBlobBs |
| TFAccess | Access |
| int | MxSegLen |
| TIntV | BlockLenV |
| TBlobPtV | FFreeBlobPtV |
| TBlobPt | FirstBlobPt |
| TGBlobBs::TGBlobBs | ( | const TStr & | BlobBsFNm, |
| const TFAccess & | _Access = faRdOnly, |
||
| const int & | _MxSegLen = -1 |
||
| ) |
Definition at line 220 of file blobbs.cpp.
: TBlobBs(), FBlobBs(), Access(_Access), MxSegLen(_MxSegLen), BlockLenV(), FFreeBlobPtV(TB4Def::B4Bits), FirstBlobPt(){ if (MxSegLen==-1){MxSegLen=MxBlobFLen;} TStr NrBlobBsFNm=GetNrBlobBsFNm(BlobBsFNm); switch (Access){ case faCreate: FBlobBs=TFRnd::New(NrBlobBsFNm, faCreate, true); break; case faUpdate: case faRdOnly: case faRestore: FBlobBs=TFRnd::New(NrBlobBsFNm, faUpdate, true); break; default: Fail; } if (FBlobBs->Empty()){ FBlobBs->SetFPos(0); PutVersionStr(FBlobBs); PutBlobBsStateStr(FBlobBs, bbsOpened); PutMxSegLen(FBlobBs, MxSegLen); GenBlockLenV(BlockLenV); PutBlockLenV(FBlobBs, BlockLenV); GenFFreeBlobPtV(BlockLenV, FFreeBlobPtV); PutFFreeBlobPtV(FBlobBs, FFreeBlobPtV); } else { FBlobBs->SetFPos(0); AssertVersionStr(FBlobBs); int FPos=FBlobBs->GetFPos(); if (Access!=faRestore){ AssertBlobBsStateStr(FBlobBs, bbsClosed);} if (Access!=faRdOnly){ FBlobBs->SetFPos(FPos); PutBlobBsStateStr(FBlobBs, bbsOpened); } MxSegLen=GetMxSegLen(FBlobBs); GetBlockLenV(FBlobBs, BlockLenV); GetFFreeBlobPtV(FBlobBs, FFreeBlobPtV); } FirstBlobPt=TBlobPt(FBlobBs->GetFPos()); FBlobBs->Flush(); }
Definition at line 262 of file blobbs.cpp.
{
if (Access!=faRdOnly){
FBlobBs->SetFPos(0);
PutVersionStr(FBlobBs);
PutBlobBsStateStr(FBlobBs, bbsClosed);
PutMxSegLen(FBlobBs, MxSegLen);
PutBlockLenV(FBlobBs, BlockLenV);
PutFFreeBlobPtV(FBlobBs, FFreeBlobPtV);
}
FBlobBs->Flush();
FBlobBs=NULL;
}
| void TGBlobBs::DelBlob | ( | const TBlobPt & | BlobPt | ) | [virtual] |
Implements TBlobBs.
Definition at line 353 of file blobbs.cpp.
{
EAssert((Access==faCreate)||(Access==faUpdate)||(Access==faRestore));
FBlobBs->SetFPos(BlobPt.GetAddr());
AssertBlobTag(FBlobBs, btBegin);
int MxBfL=FBlobBs->GetInt();
int FPos=FBlobBs->GetFPos();
AssertBlobState(FBlobBs, bsActive);
/*int BfL=*/FBlobBs->GetInt();
FBlobBs->SetFPos(FPos);
PutBlobState(FBlobBs, bsFree);
int _MxBfL; int FFreeBlobPtN;
GetAllocInfo(MxBfL, BlockLenV, _MxBfL, FFreeBlobPtN);
EAssert(MxBfL==_MxBfL);
FFreeBlobPtV[FFreeBlobPtN].SaveAddr(FBlobBs);
FFreeBlobPtV[FFreeBlobPtN]=BlobPt;
FBlobBs->PutCh(TCh::NullCh, MxBfL+sizeof(TCs));
AssertBlobTag(FBlobBs, btEnd);
FBlobBs->Flush();
}
| bool TGBlobBs::Exists | ( | const TStr & | BlobBsFNm | ) | [static] |
Definition at line 410 of file blobbs.cpp.
{
TStr NrBlobBsFNm=GetNrBlobBsFNm(BlobBsFNm);
return TFile::Exists(NrBlobBsFNm);
}
| TBlobPt TGBlobBs::FFirstBlobPt | ( | ) | [virtual] |
| bool TGBlobBs::FNextBlobPt | ( | TBlobPt & | TrvBlobPt, |
| TBlobPt & | BlobPt, | ||
| PSIn & | BlobSIn | ||
| ) | [virtual] |
Implements TBlobBs.
Definition at line 377 of file blobbs.cpp.
{
forever {
uint TrvBlobAddr=TrvBlobPt.GetAddr();
if (TrvBlobAddr>=uint(FBlobBs->GetFLen())){
TrvBlobPt.Clr(); BlobPt.Clr(); BlobSIn=NULL;
return false;
} else {
FBlobBs->SetFPos(TrvBlobAddr);
AssertBlobTag(FBlobBs, btBegin);
int MxBfL=FBlobBs->GetInt();
TBlobState BlobState=GetBlobState(FBlobBs);
switch (BlobState){
case bsActive:{
int BfL=FBlobBs->GetInt();
TCs BfCs; BlobSIn=FBlobBs->GetSIn(BfL, BfCs);
FBlobBs->MoveFPos(MxBfL-BfL);
TCs FCs=FBlobBs->GetCs();
AssertBlobTag(FBlobBs, btEnd);
AssertBfCsEqFlCs(BfCs, FCs);
BlobPt=TrvBlobPt;
TrvBlobPt=TBlobPt(FBlobBs->GetFPos());
return true;}
case bsFree:
FBlobBs->MoveFPos(sizeof(uint)+MxBfL+sizeof(TCs));
AssertBlobTag(FBlobBs, btEnd);
TrvBlobPt=TBlobPt(FBlobBs->GetFPos());
break;
default: Fail; return false;
}
}
}
}
| PSIn TGBlobBs::GetBlob | ( | const TBlobPt & | BlobPt | ) | [virtual] |
Implements TBlobBs.
Definition at line 339 of file blobbs.cpp.
{
FBlobBs->SetFPos(BlobPt.GetAddr());
AssertBlobTag(FBlobBs, btBegin);
int MxBfL=FBlobBs->GetInt();
AssertBlobState(FBlobBs, bsActive);
int BfL=FBlobBs->GetInt();
TCs BfCs; PSIn SIn=FBlobBs->GetSIn(BfL, BfCs);
FBlobBs->MoveFPos(MxBfL-BfL);
TCs FCs=FBlobBs->GetCs();
AssertBlobTag(FBlobBs, btEnd);
AssertBfCsEqFlCs(BfCs, FCs);
return SIn;
}
| TBlobPt TGBlobBs::GetFirstBlobPt | ( | ) | [inline, virtual] |
| TStr TGBlobBs::GetNrBlobBsFNm | ( | const TStr & | BlobBsFNm | ) | [static, private] |
Definition at line 213 of file blobbs.cpp.
| TStr TGBlobBs::GetVersionStr | ( | ) | const [inline, virtual] |
| static PBlobBs TGBlobBs::New | ( | const TStr & | BlobBsFNm, |
| const TFAccess & | Access = faRdOnly, |
||
| const int & | MxSegLen = -1 |
||
| ) | [inline, static] |
| TBlobPt TGBlobBs::PutBlob | ( | const PSIn & | SIn | ) | [virtual] |
Implements TBlobBs.
Definition at line 275 of file blobbs.cpp.
{
EAssert((Access==faCreate)||(Access==faUpdate)||(Access==faRestore));
int BfL=SIn->Len();
int MxBfL; int FFreeBlobPtN;
GetAllocInfo(BfL, BlockLenV, MxBfL, FFreeBlobPtN);
TBlobPt BlobPt; TCs Cs;
if (FFreeBlobPtV[FFreeBlobPtN].Empty()){
int FLen=FBlobBs->GetFLen();
if (FLen<=MxSegLen){
EAssert(FLen<=MxBlobFLen);
BlobPt=TBlobPt(FLen);
FBlobBs->SetFPos(BlobPt.GetAddr());
PutBlobTag(FBlobBs, btBegin);
FBlobBs->PutInt(MxBfL);
PutBlobState(FBlobBs, bsActive);
FBlobBs->PutInt(BfL);
FBlobBs->PutSIn(SIn, Cs);
FBlobBs->PutCh(TCh::NullCh, MxBfL-BfL);
FBlobBs->PutCs(Cs);
PutBlobTag(FBlobBs, btEnd);
}
} else {
BlobPt=FFreeBlobPtV[FFreeBlobPtN];
FBlobBs->SetFPos(BlobPt.GetAddr());
AssertBlobTag(FBlobBs, btBegin);
int MxBfL=FBlobBs->GetInt();
int FPos=FBlobBs->GetFPos();
AssertBlobState(FBlobBs, bsFree);
FFreeBlobPtV[FFreeBlobPtN]=TBlobPt::LoadAddr(FBlobBs);
FBlobBs->SetFPos(FPos);
PutBlobState(FBlobBs, bsActive);
FBlobBs->PutInt(BfL);
FBlobBs->PutSIn(SIn, Cs);
FBlobBs->PutCh(TCh::NullCh, MxBfL-BfL);
FBlobBs->PutCs(Cs);
AssertBlobTag(FBlobBs, btEnd);
}
FBlobBs->Flush();
return BlobPt;
}
| TBlobPt TGBlobBs::PutBlob | ( | const TBlobPt & | BlobPt, |
| const PSIn & | SIn | ||
| ) | [virtual] |
Implements TBlobBs.
Definition at line 316 of file blobbs.cpp.
{
EAssert((Access==faCreate)||(Access==faUpdate)||(Access==faRestore));
int BfL=SIn->Len();
FBlobBs->SetFPos(BlobPt.GetAddr());
AssertBlobTag(FBlobBs, btBegin);
int MxBfL=FBlobBs->GetInt();
AssertBlobState(FBlobBs, bsActive);
if (BfL>MxBfL){
DelBlob(BlobPt);
return PutBlob(SIn);
} else {
TCs Cs;
FBlobBs->PutInt(BfL);
FBlobBs->PutSIn(SIn, Cs);
FBlobBs->PutCh(TCh::NullCh, MxBfL-BfL);
FBlobBs->PutCs(Cs);
PutBlobTag(FBlobBs, btEnd);
FBlobBs->Flush();
return BlobPt;
}
}
TFAccess TGBlobBs::Access [private] |
TIntV TGBlobBs::BlockLenV [private] |
PFRnd TGBlobBs::FBlobBs [private] |
TBlobPtV TGBlobBs::FFreeBlobPtV [private] |
TBlobPt TGBlobBs::FirstBlobPt [private] |
int TGBlobBs::MxSegLen [private] |