SNAP Library , Developer Reference
2013-01-07 14:03:36
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.
References TFHash< TKey, TFDat, TVDat >::Access, faCreate, faRdOnly, faUpdate, TVec< TVal >::Gen(), TBlobBs::GetBlob(), TBlobBs::GetFirstBlobPt(), TMOut::GetSIn(), TFHash< TKey, TFDat, TVDat >::HashBBs, IAssert, TFHash< TKey, TFDat, TVDat >::Keys, TFHash< TKey, TFDat, TVDat >::PortV, TBlobBs::PutBlob(), TVec< TVal >::Save(), and TInt::Save().
: 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); } }
Definition at line 207 of file fds.h.
References faCreate, faUpdate, TMOut::GetSIn(), and TSOut::Save().
{ if ((Access==faCreate)||(Access==faUpdate)){ // flush hash-key cache FHashKeyCache.Flush(); // save port-vector TBlobPt HdBPt=HashBBs->GetFirstBlobPt(); TMOut HdSOut; Keys.Save(HdSOut); PortV.Save(HdSOut); HashBBs->PutBlob(HdBPt, HdSOut.GetSIn()); } }
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.
References TBlobPt::Empty(), fhbtVDat, TMOut::GetSIn(), and TInt::Save().
Referenced by TFHash< TKey, TFDat, TVDat >::AddFVDat(), and TFHash< TKey, TFDat, TVDat >::AddVDat().
{ // 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 >::AddFDat | ( | const TKey & | Key, |
const TFDat & | FDat | ||
) | [inline] |
Definition at line 124 of file fds.h.
References TFHash< TKey, TFDat, TVDat >::AddKey().
TBlobPt TFHash< TKey, TFDat, TVDat >::AddFVDat | ( | const TKey & | Key, |
const TFDat & | FDat, | ||
const TVDat & | VDat | ||
) | [inline] |
Definition at line 128 of file fds.h.
References TFHash< TKey, TFDat, TVDat >::AddDat().
{ return AddDat(Key, true, FDat, true, VDat);}
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.
References TBlobPt::Empty(), fhbtKey, TMOut::GetSIn(), TPt< TRec >::Save(), and TInt::Save().
Referenced by TFHash< TKey, TFDat, TVDat >::AddFDat().
{ // 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; }
TBlobPt TFHash< TKey, TFDat, TVDat >::AddVDat | ( | const TKey & | Key, |
const TVDat & | VDat | ||
) | [inline] |
Definition at line 126 of file fds.h.
References TFHash< TKey, TFDat, TVDat >::AddDat().
{ return AddDat(Key, false, TFDat(), true, VDat);}
void TFHash< TKey, TFDat, TVDat >::CacheFlushAndClr | ( | ) | [inline] |
Definition at line 119 of file fds.h.
References TFHash< TKey, TFDat, TVDat >::FHashKeyCache, and TCache< TKey, TDat, THashFunc >::FlushAndClr().
{FHashKeyCache.FlushAndClr();}
void TFHash< TKey, TFDat, TVDat >::DelKey | ( | const TKey & | Key | ) |
Definition at line 285 of file fds.h.
References TBlobPt::Empty(), TPt< TRec >::Empty(), and IAssert.
Referenced by TFHash< TKey, TFDat, TVDat >::DelKeyId().
{ // 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); }
void TFHash< TKey, TFDat, TVDat >::DelKeyId | ( | const TBlobPt & | KeyId | ) | [inline] |
Definition at line 132 of file fds.h.
References TFHash< TKey, TFDat, TVDat >::DelKey(), and TFHash< TKey, TFDat, TVDat >::GetKey().
bool TFHash< TKey, TFDat, TVDat >::Empty | ( | ) | const [inline] |
Definition at line 121 of file fds.h.
References TFHash< TKey, TFDat, TVDat >::Keys.
{return Keys==0;}
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.
References fhbtKey.
{ 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.
References TFHash< TKey, TFDat, TVDat >::FHashKeyCache, fhbtKey, TCache< TKey, TDat, THashFunc >::Get(), TBlobBs::GetBlob(), TFHash< TKey, TFDat, TVDat >::HashBBs, IAssert, and TCache< TKey, TDat, THashFunc >::Put().
Referenced by TFHash< TKey, TFDat, TVDat >::GetKey().
{ 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.
References fhbtVDat, and IAssert.
{ // 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] |
Definition at line 83 of file fds.h.
References TFHash< TKey, TFDat, TVDat >::HashBBs.
Referenced by TFHashKey< TKey, TFDat, TVDat >::OnDelFromCache().
{return HashBBs;}
void TFHash< TKey, TFDat, TVDat >::GetKey | ( | const TBlobPt & | KeyId, |
TKey & | Key | ||
) | [inline] |
Definition at line 135 of file fds.h.
References TFHash< TKey, TFDat, TVDat >::GetFHashKey().
Referenced by TFHash< TKey, TFDat, TVDat >::DelKeyId().
{ 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.
References fhbtVDat, and IAssert.
{ // 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.
References TFHash< TKey, TFDat, TVDat >::GetKeyInfo().
Referenced by TFHash< TKey, TFDat, TVDat >::IsKey().
{ 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.
References TBlobPt::Clr(), and TBlobPt::Empty().
Referenced by TFHash< TKey, TFDat, TVDat >::GetKeyId(), and TFHash< TKey, TFDat, TVDat >::GetKeyInfo().
{ // 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.
References TFHash< TKey, TFDat, TVDat >::GetKeyInfo().
{ 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.
References TFHash< TKey, TFDat, TVDat >::FHashKeyCache, TVec< TVal >::GetMemUsed(), TCache< TKey, TDat, THashFunc >::GetMemUsed(), and TFHash< TKey, TFDat, TVDat >::PortV.
{ 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.
References fhbtVDat, and IAssert.
{ // 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] |
bool TFHash< TKey, TFDat, TVDat >::IsKey | ( | const TKey & | Key | ) | [inline] |
Definition at line 140 of file fds.h.
References TBlobPt::Empty(), and TFHash< TKey, TFDat, TVDat >::GetKeyId().
bool TFHash< TKey, TFDat, TVDat >::IsKey | ( | const TKey & | Key, |
TBlobPt & | KeyId | ||
) | [inline] |
Definition at line 142 of file fds.h.
References TBlobPt::Empty(), and TFHash< TKey, TFDat, TVDat >::GetKeyId().
friend class TFHashKey< TKey, TFDat, TVDat > [friend] |
TFAccess TFHash< TKey, TFDat, TVDat >::Access [private] |
Definition at line 76 of file fds.h.
Referenced by TFHash< TKey, TFDat, TVDat >::TFHash().
TCache<TBlobPt, PHashKey> TFHash< TKey, TFDat, TVDat >::FHashKeyCache [private] |
Definition at line 80 of file fds.h.
Referenced by TFHash< TKey, TFDat, TVDat >::CacheFlushAndClr(), TFHash< TKey, TFDat, TVDat >::GetFHashKey(), and TFHash< TKey, TFDat, TVDat >::GetMemUsed().
PBlobBs TFHash< TKey, TFDat, TVDat >::HashBBs [private] |
Definition at line 77 of file fds.h.
Referenced by TFHash< TKey, TFDat, TVDat >::GetFHashKey(), TFHash< TKey, TFDat, TVDat >::GetHashBBs(), and TFHash< TKey, TFDat, TVDat >::TFHash().
Definition at line 79 of file fds.h.
Referenced by TFHash< TKey, TFDat, TVDat >::Empty(), TFHash< TKey, TFDat, TVDat >::Len(), and TFHash< TKey, TFDat, TVDat >::TFHash().
TBlobPtV TFHash< TKey, TFDat, TVDat >::PortV [private] |
Definition at line 78 of file fds.h.
Referenced by TFHash< TKey, TFDat, TVDat >::GetMemUsed(), and TFHash< TKey, TFDat, TVDat >::TFHash().