|
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 <hash.h>

Public Member Functions | |
| TCache () | |
| TCache (const TCache &) | |
| TCache (const int64 &_MxMemUsed, const int &Ports, void *_RefToBs) | |
| TCache & | operator= (const TCache &) |
| int64 | GetMemUsed () const |
| bool | RefreshMemUsed () |
| void | Put (const TKey &Key, const TDat &Dat) |
| bool | Get (const TKey &Key, TDat &Dat) |
| void | Del (const TKey &Key, const bool &DoEventCall=true) |
| void | Flush () |
| void | FlushAndClr () |
| void * | FFirstKeyDat () |
| bool | FNextKeyDat (void *&KeyDatP, TKey &Key, TDat &Dat) |
| void | PutRefToBs (void *_RefToBs) |
| void * | GetRefToBs () |
Private Types | |
| typedef TLst< TKey > | TKeyL |
| typedef TLstNd< TKey > * | TKeyLN |
| typedef TPair< TKeyLN, TDat > | TKeyLNDatPr |
Private Member Functions | |
| void | Purge (const int64 &MemToPurge) |
Private Attributes | |
| int64 | MxMemUsed |
| int64 | CurMemUsed |
| THash< TKey, TKeyLNDatPr, THashFunc > | KeyDatH |
| TKeyL | TimeKeyL |
| void * | RefToBs |
typedef TPair<TKeyLN, TDat> TCache< TKey, TDat, THashFunc >::TKeyLNDatPr [private] |
| TCache< TKey, TDat, THashFunc >::TCache | ( | const TCache< TKey, TDat, THashFunc > & | ) |
| void TCache< TKey, TDat, THashFunc >::Del | ( | const TKey & | Key, |
| const bool & | DoEventCall = true |
||
| ) |
Definition at line 1059 of file hash.h.
References TPair< TVal1, TVal2 >::Val1, and TPair< TVal1, TVal2 >::Val2.
{
int KeyId=KeyDatH.GetKeyId(Key);
if (KeyId!=-1){
TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
TKeyLN KeyLN=KeyLNDatPr.Val1;
TDat& Dat=KeyLNDatPr.Val2;
if (DoEventCall){
Dat->OnDelFromCache(Key, RefToBs);}
CurMemUsed-=int64(Key.GetMemUsed()+Dat->GetMemUsed());
Dat=NULL;
TimeKeyL.Del(KeyLN);
KeyDatH.DelKeyId(KeyId);
}
}
| void * TCache< TKey, TDat, THashFunc >::FFirstKeyDat | ( | ) |
| void TCache< TKey, TDat, THashFunc >::Flush | ( | ) |
Definition at line 1075 of file hash.h.
References TPair< TVal1, TVal2 >::Val2.
{
printf("To flush: %d\n", KeyDatH.Len());
int KeyId=KeyDatH.FFirstKeyId(); int Done = 0;
while (KeyDatH.FNextKeyId(KeyId)){
if (Done%10000==0){printf("%d\r", Done);}
const TKey& Key=KeyDatH.GetKey(KeyId);
TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
TDat Dat=KeyLNDatPr.Val2;
Dat->OnDelFromCache(Key, RefToBs);
Done++;
}
printf("Done %d\n", KeyDatH.Len());
}
| void TCache< TKey, TDat, THashFunc >::FlushAndClr | ( | ) |
Definition at line 1090 of file hash.h.
Referenced by TFHash< TKey, TFDat, TVDat >::CacheFlushAndClr().

| bool TCache< TKey, TDat, THashFunc >::FNextKeyDat | ( | void *& | KeyDatP, |
| TKey & | Key, | ||
| TDat & | Dat | ||
| ) |
Definition at line 1103 of file hash.h.
References TLstNd< TVal >::GetVal(), and TLstNd< TVal >::Next().
{
if (KeyDatP==NULL){
return false;
} else {
Key=TKeyLN(KeyDatP)->GetVal(); Dat=KeyDatH.GetDat(Key).Val2;
KeyDatP=TKeyLN(KeyDatP)->Next(); return true;
}
}

| int64 TCache< TKey, TDat, THashFunc >::GetMemUsed | ( | ) | const |
Definition at line 1007 of file hash.h.
References TPair< TVal1, TVal2 >::Val2.
Referenced by TFHash< TKey, TFDat, TVDat >::GetMemUsed().
{
int64 MemUsed=0;
int KeyId=KeyDatH.FFirstKeyId();
while (KeyDatH.FNextKeyId(KeyId)){
const TKey& Key=KeyDatH.GetKey(KeyId);
const TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
TDat Dat=KeyLNDatPr.Val2;
MemUsed+=int64(Key.GetMemUsed()+Dat->GetMemUsed());
}
return MemUsed;
}

| void* TCache< TKey, TDat, THashFunc >::GetRefToBs | ( | ) | [inline] |
| TCache& TCache< TKey, TDat, THashFunc >::operator= | ( | const TCache< TKey, TDat, THashFunc > & | ) |
| void TCache< TKey, TDat, THashFunc >::Put | ( | const TKey & | Key, |
| const TDat & | Dat | ||
| ) |
Definition at line 1030 of file hash.h.
References TPair< TVal1, TVal2 >::Val1, and TPair< TVal1, TVal2 >::Val2.
Referenced by TFHash< TKey, TFDat, TVDat >::GetFHashKey().
{
int KeyId=KeyDatH.GetKeyId(Key);
if (KeyId==-1){
int64 KeyDatMem=int64(Key.GetMemUsed()+Dat->GetMemUsed());
if (CurMemUsed+KeyDatMem>MxMemUsed){Purge(KeyDatMem);}
CurMemUsed+=KeyDatMem;
TKeyLN KeyLN=TimeKeyL.AddFront(Key);
TKeyLNDatPr KeyLNDatPr(KeyLN, Dat);
KeyDatH.AddDat(Key, KeyLNDatPr);
} else {
TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
TKeyLN KeyLN=KeyLNDatPr.Val1;
KeyLNDatPr.Val2=Dat;
TimeKeyL.PutFront(KeyLN);
}
}

| void TCache< TKey, TDat, THashFunc >::PutRefToBs | ( | void * | _RefToBs | ) | [inline] |
| bool TCache< TKey, TDat, THashFunc >::RefreshMemUsed | ( | ) |
Definition at line 1020 of file hash.h.
{
CurMemUsed=GetMemUsed();
if (CurMemUsed>MxMemUsed){
Purge(CurMemUsed-MxMemUsed);
return true;
}
return false;
}
int64 TCache< TKey, TDat, THashFunc >::CurMemUsed [private] |
THash<TKey, TKeyLNDatPr, THashFunc> TCache< TKey, TDat, THashFunc >::KeyDatH [private] |
void* TCache< TKey, TDat, THashFunc >::RefToBs [private] |
Definition at line 972 of file hash.h.
Referenced by TCache< TBlobPt, PHashKey >::GetRefToBs(), and TCache< TBlobPt, PHashKey >::PutRefToBs().