SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 993 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 995 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 995 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 996 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 1004 of file hash.h.

1004 {}
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 1006 of file hash.h.

1006  :
1007  MxMemUsed(_MxMemUsed), CurMemUsed(0),
1008  KeyDatH(Ports), TimeKeyL(), RefToBs(_RefToBs){}
TKeyL TimeKeyL
Definition: hash.h:1000
void * RefToBs
Definition: hash.h:1001
int64 MxMemUsed
Definition: hash.h:997
int64 CurMemUsed
Definition: hash.h:998
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:999

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 1089 of file hash.h.

1089  {
1090  int KeyId=KeyDatH.GetKeyId(Key);
1091  if (KeyId!=-1){
1092  TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1093  TKeyLN KeyLN=KeyLNDatPr.Val1;
1094  TDat& Dat=KeyLNDatPr.Val2;
1095  if (DoEventCall){
1096  Dat->OnDelFromCache(Key, RefToBs);}
1097  CurMemUsed-=int64(Key.GetMemUsed()+Dat->GetMemUsed());
1098  Dat=NULL;
1099  TimeKeyL.Del(KeyLN);
1100  KeyDatH.DelKeyId(KeyId);
1101  }
1102 }
TKeyL TimeKeyL
Definition: hash.h:1000
void * RefToBs
Definition: hash.h:1001
int64 CurMemUsed
Definition: hash.h:998
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:996
TLstNd< TKey > * TKeyLN
Definition: hash.h:995
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:999
void Del(const TVal &Val)
Definition: ds.h:2776
long long int64
Definition: bd.h:27
template<class TKey , class TDat , class THashFunc >
void * TCache< TKey, TDat, THashFunc >::FFirstKeyDat ( )

Definition at line 1128 of file hash.h.

1128  {
1129  return TimeKeyL.First();
1130 }
TKeyL TimeKeyL
Definition: hash.h:1000
PLstNd First() const
Definition: ds.h:2659
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::Flush ( )

Definition at line 1105 of file hash.h.

1105  {
1106  printf("To flush: %d\n", KeyDatH.Len());
1107  int KeyId=KeyDatH.FFirstKeyId(); int Done = 0;
1108  while (KeyDatH.FNextKeyId(KeyId)){
1109  if (Done%10000==0){printf("%d\r", Done);}
1110  const TKey& Key=KeyDatH.GetKey(KeyId);
1111  TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1112  TDat Dat=KeyLNDatPr.Val2;
1113  Dat->OnDelFromCache(Key, RefToBs);
1114  Done++;
1115  }
1116  printf("Done %d\n", KeyDatH.Len());
1117 }
void * RefToBs
Definition: hash.h:1001
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:996
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:999
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::FlushAndClr ( )

Definition at line 1120 of file hash.h.

1120  {
1121  Flush();
1122  CurMemUsed=0;
1123  KeyDatH.Clr();
1124  TimeKeyL.Clr();
1125 }
TKeyL TimeKeyL
Definition: hash.h:1000
int64 CurMemUsed
Definition: hash.h:998
void Flush()
Definition: hash.h:1105
void Clr()
Definition: ds.h:2652
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:999
template<class TKey , class TDat , class THashFunc >
bool TCache< TKey, TDat, THashFunc >::FNextKeyDat ( void *&  KeyDatP,
TKey &  Key,
TDat &  Dat 
)

Definition at line 1133 of file hash.h.

1133  {
1134  if (KeyDatP==NULL){
1135  return false;
1136  } else {
1137  Key=TKeyLN(KeyDatP)->GetVal(); Dat=KeyDatH.GetDat(Key).Val2;
1138  KeyDatP=TKeyLN(KeyDatP)->Next(); return true;
1139  }
1140 }
TLstNd< TKey > * TKeyLN
Definition: hash.h:995
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:999
TVal & GetVal()
Definition: ds.h:2629
TLstNd * Next() const
Definition: ds.h:2628
template<class TKey , class TDat , class THashFunc >
bool TCache< TKey, TDat, THashFunc >::Get ( const TKey &  Key,
TDat &  Dat 
)

Definition at line 1078 of file hash.h.

1078  {
1079  int KeyId=KeyDatH.GetKeyId(Key);
1080  if (KeyId==-1){
1081  return false;
1082  } else {
1083  Dat=KeyDatH[KeyId].Val2;
1084  return true;
1085  }
1086 }
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:999
template<class TKey , class TDat , class THashFunc >
int64 TCache< TKey, TDat, THashFunc >::GetMemUsed ( ) const

Definition at line 1037 of file hash.h.

1037  {
1038  int64 MemUsed=0;
1039  int KeyId=KeyDatH.FFirstKeyId();
1040  while (KeyDatH.FNextKeyId(KeyId)){
1041  const TKey& Key=KeyDatH.GetKey(KeyId);
1042  const TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1043  TDat Dat=KeyLNDatPr.Val2;
1044  MemUsed+=int64(Key.GetMemUsed()+Dat->GetMemUsed());
1045  }
1046  return MemUsed;
1047 }
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:996
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:999
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 1012 of file hash.h.

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

Definition at line 1024 of file hash.h.

1024 {return RefToBs;}
void * RefToBs
Definition: hash.h:1001
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 1028 of file hash.h.

1028  {
1029  const int64 StartMemUsed = CurMemUsed;
1030  while (!TimeKeyL.Empty()&&(StartMemUsed-CurMemUsed<MemToPurge)){
1031  TKey Key=TimeKeyL.Last()->GetVal();
1032  Del(Key);
1033  }
1034 }
TKeyL TimeKeyL
Definition: hash.h:1000
int64 CurMemUsed
Definition: hash.h:998
bool Empty() const
Definition: ds.h:2657
void Del(const TKey &Key, const bool &DoEventCall=true)
Definition: hash.h:1089
PLstNd Last() const
Definition: ds.h:2660
long long int64
Definition: bd.h:27
TVal & GetVal()
Definition: ds.h:2629
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::Put ( const TKey &  Key,
const TDat &  Dat 
)

Definition at line 1060 of file hash.h.

1060  {
1061  int KeyId=KeyDatH.GetKeyId(Key);
1062  if (KeyId==-1){
1063  int64 KeyDatMem=int64(Key.GetMemUsed()+Dat->GetMemUsed());
1064  if (CurMemUsed+KeyDatMem>MxMemUsed){Purge(KeyDatMem);}
1065  CurMemUsed+=KeyDatMem;
1066  TKeyLN KeyLN=TimeKeyL.AddFront(Key);
1067  TKeyLNDatPr KeyLNDatPr(KeyLN, Dat);
1068  KeyDatH.AddDat(Key, KeyLNDatPr);
1069  } else {
1070  TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1071  TKeyLN KeyLN=KeyLNDatPr.Val1;
1072  KeyLNDatPr.Val2=Dat;
1073  TimeKeyL.PutFront(KeyLN);
1074  }
1075 }
TKeyL TimeKeyL
Definition: hash.h:1000
int64 MxMemUsed
Definition: hash.h:997
int64 CurMemUsed
Definition: hash.h:998
void Purge(const int64 &MemToPurge)
Definition: hash.h:1028
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:996
PLstNd AddFront(const TVal &Val)
Definition: ds.h:2700
void PutFront(const PLstNd &Nd)
Definition: ds.h:2737
TLstNd< TKey > * TKeyLN
Definition: hash.h:995
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:999
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 1023 of file hash.h.

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

Definition at line 1050 of file hash.h.

1050  {
1052  if (CurMemUsed>MxMemUsed){
1054  return true;
1055  }
1056  return false;
1057 }
int64 MxMemUsed
Definition: hash.h:997
int64 CurMemUsed
Definition: hash.h:998
void Purge(const int64 &MemToPurge)
Definition: hash.h:1028
int64 GetMemUsed() const
Definition: hash.h:1037

Member Data Documentation

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

Definition at line 998 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 999 of file hash.h.

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

Definition at line 997 of file hash.h.

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

Definition at line 1001 of file hash.h.

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

Definition at line 1000 of file hash.h.


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