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 <fds.h>
Public Member Functions | |
TFHash (const TStr &HashFNm, const TFAccess &_Access, const int &Ports, const int &MxMemUsed) | |
~TFHash () | |
TFHash (TSIn &) | |
void | Save (TSOut &) |
TFHash & | operator= (const TFHash &) |
int | GetMemUsed () |
void | CacheFlushAndClr () |
bool | Empty () const |
int | Len () const |
TBlobPt | AddFDat (const TKey &Key, const TFDat &FDat) |
TBlobPt | AddVDat (const TKey &Key, const TVDat &VDat) |
TBlobPt | AddFVDat (const TKey &Key, const TFDat &FDat, const TVDat &VDat) |
void | DelKey (const TKey &Key) |
void | DelKeyId (const TBlobPt &KeyId) |
void | GetKey (const TBlobPt &KeyId, TKey &Key) |
TBlobPt | GetKeyId (const TKey &Key) |
bool | IsKey (const TKey &Key) |
bool | IsKey (const TKey &Key, TBlobPt &KeyId) |
TBlobPt | GetFDat (const TKey &Key, TFDat &FDat) |
TBlobPt | GetVDat (const TKey &Key, TVDat &VDat) |
TBlobPt | GetFVDat (const TKey &Key, TFDat &FDat, TVDat &VDat) |
void | GetKeyFDat (const TBlobPt &KeyId, TKey &Key, TFDat &FDat) |
void | GetKeyFVDat (const TBlobPt &KeyId, TKey &Key, TFDat &FDat, TVDat &VDat) |
TBlobPt | FFirstKeyId () |
bool | FNextKeyId (TBlobPt &TrvBlobPt, TBlobPt &KeyId) |
Static Public Member Functions | |
static PFHash | Load (TSIn &) |
Private Types | |
typedef TPt< TFHash< TKey, TFDat, TVDat > > | PFHash |
typedef TFHashKey< TKey, TFDat, TVDat > | THashKey |
typedef TPt< THashKey > | PHashKey |
Private Member Functions | |
void * | GetVoidThis () const |
PBlobBs | GetHashBBs () |
PHashKey | GetFHashKey (const TBlobPt &KeyId) |
void | GetKeyInfo (const TKey &Key, int &PortN, TBlobPt &PrevKeyId, TBlobPt &KeyId, PHashKey &FHashKey) |
void | GetKeyInfo (const TKey &Key, TBlobPt &KeyId, PHashKey &FHashKey) |
TBlobPt | AddKey (const TKey &Key, const bool &ChangeFDat, const TFDat &FDat, const bool &ChangeVDatBPt, const TBlobPt &VDatBPt) |
TBlobPt | AddDat (const TKey &Key, const bool &ChangeFDat, const TFDat &FDat, const bool &ChangeVDat, const TVDat &VDat) |
Private Attributes | |
TCRef | CRef |
TFAccess | Access |
PBlobBs | HashBBs |
TBlobPtV | PortV |
TInt | Keys |
TCache< TBlobPt, PHashKey > | FHashKeyCache |
Friends | |
class | TFHashKey< TKey, TFDat, TVDat > |
class | TPt< TFHash< TKey, TFDat, TVDat > > |
TFHash< TKey, TFDat, TVDat >::TFHash | ( | const TStr & | HashFNm, |
const TFAccess & | _Access, | ||
const int & | Ports, | ||
const int & | MxMemUsed | ||
) |
Definition at line 180 of file fds.h.
: Access(_Access), HashBBs(), PortV(), Keys(0), FHashKeyCache(MxMemUsed, 100003, GetVoidThis()){ if (Access==faCreate){ IAssert(Ports>0); // create blob-base HashBBs=PBlobBs(new TGBlobBs(HashFNm, faCreate)); // save initial no. of keys and port-vector PortV.Gen(Ports); TMOut HdSOut; Keys.Save(HdSOut); PortV.Save(HdSOut); HashBBs->PutBlob(HdSOut.GetSIn()); } else { IAssert((Access==faUpdate)||(Access==faRdOnly)); IAssert(Ports==-1); // open blob-base HashBBs=PBlobBs(new TGBlobBs(HashFNm, Access)); // load initial no. of keys and port-vector TBlobPt HdBPt=HashBBs->GetFirstBlobPt(); PSIn HdSIn=HashBBs->GetBlob(HdBPt); Keys=TInt(*HdSIn); PortV=TBlobPtV(*HdSIn); } }
TBlobPt TFHash< TKey, TFDat, TVDat >::AddDat | ( | const TKey & | Key, |
const bool & | ChangeFDat, | ||
const TFDat & | FDat, | ||
const bool & | ChangeVDat, | ||
const TVDat & | VDat | ||
) | [private] |
Definition at line 258 of file fds.h.
{ // prepare key info TBlobPt KeyId; PHashKey FHashKey; GetKeyInfo(Key, KeyId, FHashKey); // prepare new variable-data blob-pointer TBlobPt VDatBPt; if (ChangeVDat){ // save variable-data TMOut VDatMOut; TInt(int(fhbtVDat)).Save(VDatMOut); VDat.Save(VDatMOut); if (KeyId.Empty()){ VDatBPt=HashBBs->PutBlob(VDatMOut.GetSIn()); } else { VDatBPt=HashBBs->PutBlob(FHashKey->VDatBPt, VDatMOut.GetSIn()); } } // save the data KeyId=AddKey(Key, ChangeFDat, FDat, ChangeVDat, VDatBPt); return KeyId; }
TBlobPt TFHash< TKey, TFDat, TVDat >::AddKey | ( | const TKey & | Key, |
const bool & | ChangeFDat, | ||
const TFDat & | FDat, | ||
const bool & | ChangeVDatBPt, | ||
const TBlobPt & | VDatBPt | ||
) | [private] |
Definition at line 219 of file fds.h.
{ // prepare key info int PortN=-1; TBlobPt PrevKeyId; TBlobPt KeyId; PHashKey FHashKey; GetKeyInfo(Key, PortN, PrevKeyId, KeyId, FHashKey); if (KeyId.Empty()){ // generate key FHashKey=PHashKey(new THashKey(TBlobPt(), Key, FDat, VDatBPt)); // save key to blob-base TMOut FHashKeyMOut; TInt(int(fhbtKey)).Save(FHashKeyMOut); FHashKey->Save(FHashKeyMOut); TBlobPt FHashKeyBPt=HashBBs->PutBlob(FHashKeyMOut.GetSIn()); // save key to key-cache FHashKeyCache.Put(FHashKeyBPt, FHashKey); FHashKey->PutModified(false); // connect key to the structure KeyId=FHashKeyBPt; Keys++; if (PrevKeyId.Empty()){ PortV[PortN]=KeyId; } else { PHashKey PrevFHashKey=GetFHashKey(PrevKeyId); PrevFHashKey->Next=KeyId; PrevFHashKey->PutModified(true); } } else { // update the data if (ChangeFDat){FHashKey->FDat=FDat;} if (ChangeVDatBPt){FHashKey->VDatBPt=VDatBPt;} if (ChangeFDat||ChangeVDatBPt){ FHashKey->PutModified(true);} } return KeyId; }
void TFHash< TKey, TFDat, TVDat >::CacheFlushAndClr | ( | ) | [inline] |
Definition at line 119 of file fds.h.
{FHashKeyCache.FlushAndClr();}
void TFHash< TKey, TFDat, TVDat >::DelKey | ( | const TKey & | Key | ) |
Definition at line 285 of file fds.h.
{ // prepare key info int PortN=-1; TBlobPt PrevKeyId; TBlobPt KeyId; PHashKey FHashKey; GetKeyInfo(Key, PortN, PrevKeyId, KeyId, FHashKey); // disconnect key IAssert(!KeyId.Empty()); if (PrevKeyId.Empty()){ PortV[PortN]=FHashKey->Next; } else { PHashKey PrevFHashKey=GetFHashKey(PrevKeyId); PrevFHashKey->Next=FHashKey->Next; PrevFHashKey->PutModified(true); } // delete variable data if (!FHashKey->VDatBPt.Empty()){ HashBBs->DelBlob(FHashKey->VDatBPt);} // delete key/fixed data HashBBs->DelBlob(KeyId); FHashKeyCache.Del(KeyId, false); }
TBlobPt TFHash< TKey, TFDat, TVDat >::FFirstKeyId | ( | ) |
Definition at line 372 of file fds.h.
{ return HashBBs->FFirstBlobPt(); }
bool TFHash< TKey, TFDat, TVDat >::FNextKeyId | ( | TBlobPt & | TrvBlobPt, |
TBlobPt & | KeyId | ||
) |
Definition at line 377 of file fds.h.
{ PSIn SIn; while (HashBBs->FNextBlobPt(TrvBlobPt, KeyId, SIn)){ TFHashBlobType Type=TFHashBlobType(int(TInt(*SIn))); if (Type==fhbtKey){return true;} } return false; }
TBlobPt TFHash< TKey, TFDat, TVDat >::GetFDat | ( | const TKey & | Key, |
TFDat & | FDat | ||
) |
Definition at line 308 of file fds.h.
{ // prepare key info TBlobPt KeyId; PHashKey FHashKey; GetKeyInfo(Key, KeyId, FHashKey); // get fixed data FDat=FHashKey->FDat; return KeyId; }
PHashKey TFHash< TKey, TFDat, TVDat >::GetFHashKey | ( | const TBlobPt & | KeyId | ) | [inline, private] |
Definition at line 84 of file fds.h.
{ PHashKey FHashKey; if (!FHashKeyCache.Get(KeyId, FHashKey)){ // if the key is in cache // read the key from blob-base PSIn SIn=HashBBs->GetBlob(KeyId); TFHashBlobType Type=TFHashBlobType(int(TInt(*SIn))); IAssert(Type==fhbtKey); FHashKey=PHashKey(new THashKey(*SIn)); } FHashKeyCache.Put(KeyId, FHashKey); // refresh/put key in cache return FHashKey; }
TBlobPt TFHash< TKey, TFDat, TVDat >::GetFVDat | ( | const TKey & | Key, |
TFDat & | FDat, | ||
TVDat & | VDat | ||
) |
Definition at line 331 of file fds.h.
{ // prepare key info TBlobPt KeyId; PHashKey FHashKey; GetKeyInfo(Key, KeyId, FHashKey); // get fixed data FDat=FHashKey->FDat; // get variable data PSIn SIn=HashBBs->GetBlob(FHashKey->VDatBPt); TFHashBlobType Type=TFHashBlobType(int(TInt(*SIn))); IAssert(Type==fhbtVDat); VDat=TVDat(*SIn); return KeyId; }
PBlobBs TFHash< TKey, TFDat, TVDat >::GetHashBBs | ( | ) | [inline, private] |
void TFHash< TKey, TFDat, TVDat >::GetKey | ( | const TBlobPt & | KeyId, |
TKey & | Key | ||
) | [inline] |
Definition at line 135 of file fds.h.
{ PHashKey FHashKey=GetFHashKey(KeyId); Key=FHashKey->Key;}
void TFHash< TKey, TFDat, TVDat >::GetKeyFDat | ( | const TBlobPt & | KeyId, |
TKey & | Key, | ||
TFDat & | FDat | ||
) |
Definition at line 346 of file fds.h.
{ // prepare key info PHashKey FHashKey=GetFHashKey(KeyId); // get key Key=FHashKey->Key; // get fixed data FDat=FHashKey->FDat; }
void TFHash< TKey, TFDat, TVDat >::GetKeyFVDat | ( | const TBlobPt & | KeyId, |
TKey & | Key, | ||
TFDat & | FDat, | ||
TVDat & | VDat | ||
) |
Definition at line 357 of file fds.h.
{ // prepare key info PHashKey FHashKey=GetFHashKey(KeyId); // get key Key=FHashKey->Key; // get fixed data FDat=FHashKey->FDat; // get variable data PSIn SIn=HashBBs->GetBlob(FHashKey->VDatBPt); TFHashBlobType Type=TFHashBlobType(int(TInt(*SIn))); IAssert(Type==fhbtVDat); VDat=TVDat(*SIn); }
TBlobPt TFHash< TKey, TFDat, TVDat >::GetKeyId | ( | const TKey & | Key | ) | [inline] |
Definition at line 137 of file fds.h.
{ TBlobPt KeyId; PHashKey FHashKey; GetKeyInfo(Key, KeyId, FHashKey); return KeyId;}
void TFHash< TKey, TFDat, TVDat >::GetKeyInfo | ( | const TKey & | Key, |
int & | PortN, | ||
TBlobPt & | PrevKeyId, | ||
TBlobPt & | KeyId, | ||
PHashKey & | FHashKey | ||
) | [private] |
Definition at line 160 of file fds.h.
{ // prepare key data PortN=abs(Key.GetPrimHashCd())%PortV.Len(); PrevKeyId.Clr(); KeyId=PortV[PortN]; // test if the key exists if (!KeyId.Empty()){ FHashKey=GetFHashKey(KeyId); while ((!KeyId.Empty())&&(FHashKey->Key!=Key)){ PrevKeyId=KeyId; KeyId=FHashKey->Next; if (!KeyId.Empty()){FHashKey=GetFHashKey(KeyId);} } } }
void TFHash< TKey, TFDat, TVDat >::GetKeyInfo | ( | const TKey & | Key, |
TBlobPt & | KeyId, | ||
PHashKey & | FHashKey | ||
) | [inline, private] |
Definition at line 97 of file fds.h.
{ int PortN=-1; TBlobPt PrevKeyId; GetKeyInfo(Key, PortN, PrevKeyId, KeyId, FHashKey);}
int TFHash< TKey, TFDat, TVDat >::GetMemUsed | ( | ) | [inline] |
Definition at line 117 of file fds.h.
{ return PortV.GetMemUsed()+(int)FHashKeyCache.GetMemUsed();} //TODO:64bit
TBlobPt TFHash< TKey, TFDat, TVDat >::GetVDat | ( | const TKey & | Key, |
TVDat & | VDat | ||
) |
Definition at line 319 of file fds.h.
{ // prepare key info TBlobPt KeyId; PHashKey FHashKey; GetKeyInfo(Key, KeyId, FHashKey); // get variable data PSIn SIn=HashBBs->GetBlob(FHashKey->VDatBPt); TFHashBlobType Type=TFHashBlobType(int(TInt(*SIn))); IAssert(Type==fhbtVDat); VDat=TVDat(*SIn); return KeyId; }
void* TFHash< TKey, TFDat, TVDat >::GetVoidThis | ( | ) | const [inline, private] |
friend class TFHashKey< TKey, TFDat, TVDat > [friend] |
TCache<TBlobPt, PHashKey> TFHash< TKey, TFDat, TVDat >::FHashKeyCache [private] |