SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TCache< TKey, TDat, THashFunc > Class Template Reference

#include <hash.h>

Public Member Functions

 TCache ()
 
 TCache (const TCache &)
 
 TCache (const int64 &_MxMemUsed, const int &Ports, void *_RefToBs)
 
TCacheoperator= (const TCache &)
 
int64 GetMemUsed () const
 
int64 GetMxMemUsed () 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
 

Detailed Description

template<class TKey, class TDat, class THashFunc = TDefaultHashFunc<TKey>>
class TCache< TKey, TDat, THashFunc >

Definition at line 1065 of file hash.h.

Member Typedef Documentation

template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
typedef TLst<TKey> TCache< TKey, TDat, THashFunc >::TKeyL
private

Definition at line 1067 of file hash.h.

template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
typedef TLstNd<TKey>* TCache< TKey, TDat, THashFunc >::TKeyLN
private

Definition at line 1067 of file hash.h.

template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
typedef TPair<TKeyLN, TDat> TCache< TKey, TDat, THashFunc >::TKeyLNDatPr
private

Definition at line 1068 of file hash.h.

Constructor & Destructor Documentation

template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
TCache< TKey, TDat, THashFunc >::TCache ( )
inline

Definition at line 1076 of file hash.h.

1076 {}
template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
TCache< TKey, TDat, THashFunc >::TCache ( const TCache< TKey, TDat, THashFunc > &  )
template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
TCache< TKey, TDat, THashFunc >::TCache ( const int64 _MxMemUsed,
const int &  Ports,
void *  _RefToBs 
)
inline

Definition at line 1078 of file hash.h.

1078  :
1079  MxMemUsed(_MxMemUsed), CurMemUsed(0),
1080  KeyDatH(Ports), TimeKeyL(), RefToBs(_RefToBs){}
TKeyL TimeKeyL
Definition: hash.h:1072
void * RefToBs
Definition: hash.h:1073
int64 MxMemUsed
Definition: hash.h:1069
int64 CurMemUsed
Definition: hash.h:1070
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:1071

Member Function Documentation

template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::Del ( const TKey &  Key,
const bool &  DoEventCall = true 
)

Definition at line 1161 of file hash.h.

1161  {
1162  int KeyId=KeyDatH.GetKeyId(Key);
1163  if (KeyId!=-1){
1164  TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1165  TKeyLN KeyLN=KeyLNDatPr.Val1;
1166  TDat& Dat=KeyLNDatPr.Val2;
1167  if (DoEventCall){
1168  Dat->OnDelFromCache(Key, RefToBs);}
1169  CurMemUsed-=int64(Key.GetMemUsed()+Dat->GetMemUsed());
1170  Dat=NULL;
1171  TimeKeyL.Del(KeyLN);
1172  KeyDatH.DelKeyId(KeyId);
1173  }
1174 }
TKeyL TimeKeyL
Definition: hash.h:1072
void * RefToBs
Definition: hash.h:1073
int64 CurMemUsed
Definition: hash.h:1070
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:1068
TLstNd< TKey > * TKeyLN
Definition: hash.h:1067
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:1071
void Del(const TVal &Val)
Definition: ds.h:2842
long long int64
Definition: bd.h:27
template<class TKey , class TDat , class THashFunc >
void * TCache< TKey, TDat, THashFunc >::FFirstKeyDat ( )

Definition at line 1200 of file hash.h.

1200  {
1201  return TimeKeyL.First();
1202 }
TKeyL TimeKeyL
Definition: hash.h:1072
PLstNd First() const
Definition: ds.h:2725
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::Flush ( )

Definition at line 1177 of file hash.h.

1177  {
1178  printf("To flush: %d\n", KeyDatH.Len());
1179  int KeyId=KeyDatH.FFirstKeyId(); int Done = 0;
1180  while (KeyDatH.FNextKeyId(KeyId)){
1181  if (Done%10000==0){printf("%d\r", Done);}
1182  const TKey& Key=KeyDatH.GetKey(KeyId);
1183  TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1184  TDat Dat=KeyLNDatPr.Val2;
1185  Dat->OnDelFromCache(Key, RefToBs);
1186  Done++;
1187  }
1188  printf("Done %d\n", KeyDatH.Len());
1189 }
void * RefToBs
Definition: hash.h:1073
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:1068
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:1071
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::FlushAndClr ( )

Definition at line 1192 of file hash.h.

1192  {
1193  Flush();
1194  CurMemUsed=0;
1195  KeyDatH.Clr();
1196  TimeKeyL.Clr();
1197 }
TKeyL TimeKeyL
Definition: hash.h:1072
int64 CurMemUsed
Definition: hash.h:1070
void Flush()
Definition: hash.h:1177
void Clr()
Definition: ds.h:2718
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:1071
template<class TKey , class TDat , class THashFunc >
bool TCache< TKey, TDat, THashFunc >::FNextKeyDat ( void *&  KeyDatP,
TKey &  Key,
TDat &  Dat 
)

Definition at line 1205 of file hash.h.

1205  {
1206  if (KeyDatP==NULL){
1207  return false;
1208  } else {
1209  Key=TKeyLN(KeyDatP)->GetVal(); Dat=KeyDatH.GetDat(Key).Val2;
1210  KeyDatP=TKeyLN(KeyDatP)->Next(); return true;
1211  }
1212 }
TLstNd< TKey > * TKeyLN
Definition: hash.h:1067
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:1071
TVal & GetVal()
Definition: ds.h:2695
TLstNd * Next() const
Definition: ds.h:2694
template<class TKey , class TDat , class THashFunc >
bool TCache< TKey, TDat, THashFunc >::Get ( const TKey &  Key,
TDat &  Dat 
)

Definition at line 1150 of file hash.h.

1150  {
1151  int KeyId=KeyDatH.GetKeyId(Key);
1152  if (KeyId==-1){
1153  return false;
1154  } else {
1155  Dat=KeyDatH[KeyId].Val2;
1156  return true;
1157  }
1158 }
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:1071
template<class TKey , class TDat , class THashFunc >
int64 TCache< TKey, TDat, THashFunc >::GetMemUsed ( ) const

Definition at line 1109 of file hash.h.

1109  {
1110  int64 MemUsed=0;
1111  int KeyId=KeyDatH.FFirstKeyId();
1112  while (KeyDatH.FNextKeyId(KeyId)){
1113  const TKey& Key=KeyDatH.GetKey(KeyId);
1114  const TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1115  TDat Dat=KeyLNDatPr.Val2;
1116  MemUsed+=int64(Key.GetMemUsed()+Dat->GetMemUsed());
1117  }
1118  return MemUsed;
1119 }
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:1068
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:1071
long long int64
Definition: bd.h:27
template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
int64 TCache< TKey, TDat, THashFunc >::GetMxMemUsed ( ) const
inline

Definition at line 1084 of file hash.h.

1084 { return MxMemUsed; }
int64 MxMemUsed
Definition: hash.h:1069
template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
void* TCache< TKey, TDat, THashFunc >::GetRefToBs ( )
inline

Definition at line 1096 of file hash.h.

1096 {return RefToBs;}
void * RefToBs
Definition: hash.h:1073
template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
TCache& TCache< TKey, TDat, THashFunc >::operator= ( const TCache< TKey, TDat, THashFunc > &  )
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::Purge ( const int64 MemToPurge)
private

Definition at line 1100 of file hash.h.

1100  {
1101  const int64 StartMemUsed = CurMemUsed;
1102  while (!TimeKeyL.Empty()&&(StartMemUsed-CurMemUsed<MemToPurge)){
1103  TKey Key=TimeKeyL.Last()->GetVal();
1104  Del(Key);
1105  }
1106 }
TKeyL TimeKeyL
Definition: hash.h:1072
int64 CurMemUsed
Definition: hash.h:1070
bool Empty() const
Definition: ds.h:2723
void Del(const TKey &Key, const bool &DoEventCall=true)
Definition: hash.h:1161
PLstNd Last() const
Definition: ds.h:2726
long long int64
Definition: bd.h:27
TVal & GetVal()
Definition: ds.h:2695
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::Put ( const TKey &  Key,
const TDat &  Dat 
)

Definition at line 1132 of file hash.h.

1132  {
1133  int KeyId=KeyDatH.GetKeyId(Key);
1134  if (KeyId==-1){
1135  int64 KeyDatMem=int64(Key.GetMemUsed()+Dat->GetMemUsed());
1136  if (CurMemUsed+KeyDatMem>MxMemUsed){Purge(KeyDatMem);}
1137  CurMemUsed+=KeyDatMem;
1138  TKeyLN KeyLN=TimeKeyL.AddFront(Key);
1139  TKeyLNDatPr KeyLNDatPr(KeyLN, Dat);
1140  KeyDatH.AddDat(Key, KeyLNDatPr);
1141  } else {
1142  TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1143  TKeyLN KeyLN=KeyLNDatPr.Val1;
1144  KeyLNDatPr.Val2=Dat;
1145  TimeKeyL.PutFront(KeyLN);
1146  }
1147 }
TKeyL TimeKeyL
Definition: hash.h:1072
int64 MxMemUsed
Definition: hash.h:1069
int64 CurMemUsed
Definition: hash.h:1070
void Purge(const int64 &MemToPurge)
Definition: hash.h:1100
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:1068
PLstNd AddFront(const TVal &Val)
Definition: ds.h:2766
void PutFront(const PLstNd &Nd)
Definition: ds.h:2803
TLstNd< TKey > * TKeyLN
Definition: hash.h:1067
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:1071
long long int64
Definition: bd.h:27
template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
void TCache< TKey, TDat, THashFunc >::PutRefToBs ( void *  _RefToBs)
inline

Definition at line 1095 of file hash.h.

1095 {RefToBs=_RefToBs;}
void * RefToBs
Definition: hash.h:1073
template<class TKey , class TDat , class THashFunc >
bool TCache< TKey, TDat, THashFunc >::RefreshMemUsed ( )

Definition at line 1122 of file hash.h.

1122  {
1124  if (CurMemUsed>MxMemUsed){
1126  return true;
1127  }
1128  return false;
1129 }
int64 MxMemUsed
Definition: hash.h:1069
int64 CurMemUsed
Definition: hash.h:1070
void Purge(const int64 &MemToPurge)
Definition: hash.h:1100
int64 GetMemUsed() const
Definition: hash.h:1109

Member Data Documentation

template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
int64 TCache< TKey, TDat, THashFunc >::CurMemUsed
private

Definition at line 1070 of file hash.h.

template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
THash<TKey, TKeyLNDatPr, THashFunc> TCache< TKey, TDat, THashFunc >::KeyDatH
private

Definition at line 1071 of file hash.h.

template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
int64 TCache< TKey, TDat, THashFunc >::MxMemUsed
private

Definition at line 1069 of file hash.h.

template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
void* TCache< TKey, TDat, THashFunc >::RefToBs
private

Definition at line 1073 of file hash.h.

template<class TKey , class TDat , class THashFunc = TDefaultHashFunc<TKey>>
TKeyL TCache< TKey, TDat, THashFunc >::TimeKeyL
private

Definition at line 1072 of file hash.h.


The documentation for this class was generated from the following file: