SNAP Library 2.4, Developer Reference  2015-05-11 19:40:56
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>

Collaboration diagram for TCache< TKey, TDat, THashFunc >:

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 967 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 969 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 969 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 970 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 978 of file hash.h.

978 {}
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 980 of file hash.h.

980  :
981  MxMemUsed(_MxMemUsed), CurMemUsed(0),
982  KeyDatH(Ports), TimeKeyL(), RefToBs(_RefToBs){}
TKeyL TimeKeyL
Definition: hash.h:974
void * RefToBs
Definition: hash.h:975
int64 MxMemUsed
Definition: hash.h:971
int64 CurMemUsed
Definition: hash.h:972
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:973

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

References TPair< TVal1, TVal2 >::Val1, and TPair< TVal1, TVal2 >::Val2.

1063  {
1064  int KeyId=KeyDatH.GetKeyId(Key);
1065  if (KeyId!=-1){
1066  TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1067  TKeyLN KeyLN=KeyLNDatPr.Val1;
1068  TDat& Dat=KeyLNDatPr.Val2;
1069  if (DoEventCall){
1070  Dat->OnDelFromCache(Key, RefToBs);}
1071  CurMemUsed-=int64(Key.GetMemUsed()+Dat->GetMemUsed());
1072  Dat=NULL;
1073  TimeKeyL.Del(KeyLN);
1074  KeyDatH.DelKeyId(KeyId);
1075  }
1076 }
TKeyL TimeKeyL
Definition: hash.h:974
void * RefToBs
Definition: hash.h:975
int64 CurMemUsed
Definition: hash.h:972
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:970
TLstNd< TKey > * TKeyLN
Definition: hash.h:969
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:973
void Del(const TVal &Val)
Definition: ds.h:2728
long long int64
Definition: bd.h:27
template<class TKey , class TDat , class THashFunc >
void * TCache< TKey, TDat, THashFunc >::FFirstKeyDat ( )

Definition at line 1102 of file hash.h.

1102  {
1103  return TimeKeyL.First();
1104 }
TKeyL TimeKeyL
Definition: hash.h:974
PLstNd First() const
Definition: ds.h:2611
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::Flush ( )

Definition at line 1079 of file hash.h.

References TPair< TVal1, TVal2 >::Val2.

1079  {
1080  printf("To flush: %d\n", KeyDatH.Len());
1081  int KeyId=KeyDatH.FFirstKeyId(); int Done = 0;
1082  while (KeyDatH.FNextKeyId(KeyId)){
1083  if (Done%10000==0){printf("%d\r", Done);}
1084  const TKey& Key=KeyDatH.GetKey(KeyId);
1085  TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1086  TDat Dat=KeyLNDatPr.Val2;
1087  Dat->OnDelFromCache(Key, RefToBs);
1088  Done++;
1089  }
1090  printf("Done %d\n", KeyDatH.Len());
1091 }
void * RefToBs
Definition: hash.h:975
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:970
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:973
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::FlushAndClr ( )

Definition at line 1094 of file hash.h.

1094  {
1095  Flush();
1096  CurMemUsed=0;
1097  KeyDatH.Clr();
1098  TimeKeyL.Clr();
1099 }
TKeyL TimeKeyL
Definition: hash.h:974
int64 CurMemUsed
Definition: hash.h:972
void Flush()
Definition: hash.h:1079
void Clr()
Definition: ds.h:2604
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:973
template<class TKey , class TDat , class THashFunc >
bool TCache< TKey, TDat, THashFunc >::FNextKeyDat ( void *&  KeyDatP,
TKey &  Key,
TDat &  Dat 
)

Definition at line 1107 of file hash.h.

References TLstNd< TVal >::GetVal(), and TLstNd< TVal >::Next().

1107  {
1108  if (KeyDatP==NULL){
1109  return false;
1110  } else {
1111  Key=TKeyLN(KeyDatP)->GetVal(); Dat=KeyDatH.GetDat(Key).Val2;
1112  KeyDatP=TKeyLN(KeyDatP)->Next(); return true;
1113  }
1114 }
TLstNd< TKey > * TKeyLN
Definition: hash.h:969
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:973
TVal & GetVal()
Definition: ds.h:2581
TLstNd * Next() const
Definition: ds.h:2580

Here is the call graph for this function:

template<class TKey , class TDat , class THashFunc >
bool TCache< TKey, TDat, THashFunc >::Get ( const TKey &  Key,
TDat &  Dat 
)

Definition at line 1052 of file hash.h.

1052  {
1053  int KeyId=KeyDatH.GetKeyId(Key);
1054  if (KeyId==-1){
1055  return false;
1056  } else {
1057  Dat=KeyDatH[KeyId].Val2;
1058  return true;
1059  }
1060 }
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:973
template<class TKey , class TDat , class THashFunc >
int64 TCache< TKey, TDat, THashFunc >::GetMemUsed ( ) const

Definition at line 1011 of file hash.h.

References TPair< TVal1, TVal2 >::Val2.

1011  {
1012  int64 MemUsed=0;
1013  int KeyId=KeyDatH.FFirstKeyId();
1014  while (KeyDatH.FNextKeyId(KeyId)){
1015  const TKey& Key=KeyDatH.GetKey(KeyId);
1016  const TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1017  TDat Dat=KeyLNDatPr.Val2;
1018  MemUsed+=int64(Key.GetMemUsed()+Dat->GetMemUsed());
1019  }
1020  return MemUsed;
1021 }
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:970
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:973
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 986 of file hash.h.

References TCache< TKey, TDat, THashFunc >::MxMemUsed.

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

Definition at line 998 of file hash.h.

References TCache< TKey, TDat, THashFunc >::RefToBs.

998 {return RefToBs;}
void * RefToBs
Definition: hash.h:975
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 1002 of file hash.h.

1002  {
1003  const int64 StartMemUsed = CurMemUsed;
1004  while (!TimeKeyL.Empty()&&(StartMemUsed-CurMemUsed<MemToPurge)){
1005  TKey Key=TimeKeyL.Last()->GetVal();
1006  Del(Key);
1007  }
1008 }
TKeyL TimeKeyL
Definition: hash.h:974
int64 CurMemUsed
Definition: hash.h:972
bool Empty() const
Definition: ds.h:2609
void Del(const TKey &Key, const bool &DoEventCall=true)
Definition: hash.h:1063
PLstNd Last() const
Definition: ds.h:2612
long long int64
Definition: bd.h:27
TVal & GetVal()
Definition: ds.h:2581
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::Put ( const TKey &  Key,
const TDat &  Dat 
)

Definition at line 1034 of file hash.h.

References TPair< TVal1, TVal2 >::Val1, and TPair< TVal1, TVal2 >::Val2.

1034  {
1035  int KeyId=KeyDatH.GetKeyId(Key);
1036  if (KeyId==-1){
1037  int64 KeyDatMem=int64(Key.GetMemUsed()+Dat->GetMemUsed());
1038  if (CurMemUsed+KeyDatMem>MxMemUsed){Purge(KeyDatMem);}
1039  CurMemUsed+=KeyDatMem;
1040  TKeyLN KeyLN=TimeKeyL.AddFront(Key);
1041  TKeyLNDatPr KeyLNDatPr(KeyLN, Dat);
1042  KeyDatH.AddDat(Key, KeyLNDatPr);
1043  } else {
1044  TKeyLNDatPr& KeyLNDatPr=KeyDatH[KeyId];
1045  TKeyLN KeyLN=KeyLNDatPr.Val1;
1046  KeyLNDatPr.Val2=Dat;
1047  TimeKeyL.PutFront(KeyLN);
1048  }
1049 }
TKeyL TimeKeyL
Definition: hash.h:974
int64 MxMemUsed
Definition: hash.h:971
int64 CurMemUsed
Definition: hash.h:972
void Purge(const int64 &MemToPurge)
Definition: hash.h:1002
TPair< TKeyLN, TDat > TKeyLNDatPr
Definition: hash.h:970
PLstNd AddFront(const TVal &Val)
Definition: ds.h:2652
void PutFront(const PLstNd &Nd)
Definition: ds.h:2689
TLstNd< TKey > * TKeyLN
Definition: hash.h:969
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
Definition: hash.h:973
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 997 of file hash.h.

References TCache< TKey, TDat, THashFunc >::RefToBs.

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

Definition at line 1024 of file hash.h.

1024  {
1026  if (CurMemUsed>MxMemUsed){
1028  return true;
1029  }
1030  return false;
1031 }
int64 MxMemUsed
Definition: hash.h:971
int64 CurMemUsed
Definition: hash.h:972
void Purge(const int64 &MemToPurge)
Definition: hash.h:1002
int64 GetMemUsed() const
Definition: hash.h:1011

Member Data Documentation

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

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

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

Definition at line 971 of file hash.h.

Referenced by TCache< TKey, TDat, THashFunc >::GetMxMemUsed().

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

Definition at line 974 of file hash.h.


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