SNAP Library 2.2, Developer Reference  2014-03-11 19:15:55
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TCache< TKey, TDat, THashFunc > Class Template Reference

#include <hash.h>

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

List of all members.

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 966 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 968 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 968 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 969 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 977 of file hash.h.

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

                                                                   :
    MxMemUsed(_MxMemUsed), CurMemUsed(0),
    KeyDatH(Ports), TimeKeyL(), RefToBs(_RefToBs){}

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 1062 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);
  }
}
template<class TKey , class TDat , class THashFunc >
void * TCache< TKey, TDat, THashFunc >::FFirstKeyDat ( )

Definition at line 1101 of file hash.h.

                                                 {
  return TimeKeyL.First();
}
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::Flush ( )

Definition at line 1078 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());
}
template<class TKey , class TDat , class THashFunc >
void TCache< TKey, TDat, THashFunc >::FlushAndClr ( )

Definition at line 1093 of file hash.h.

Referenced by TFHash< TKey, TFDat, TVDat >::CacheFlushAndClr().

Here is the caller graph for this function:

template<class TKey, class TDat, class THashFunc >
bool TCache< TKey, TDat, THashFunc >::FNextKeyDat ( void *&  KeyDatP,
TKey &  Key,
TDat &  Dat 
)

Definition at line 1106 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;
  }
}

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

Referenced by TFHash< TKey, TFDat, TVDat >::GetFHashKey().

                                                                 {
  int KeyId=KeyDatH.GetKeyId(Key);
  if (KeyId==-1){
    return false;
  } else {
    Dat=KeyDatH[KeyId].Val2;
    return true;
  }
}

Here is the caller graph for this function:

template<class TKey , class TDat , class THashFunc >
int64 TCache< TKey, TDat, THashFunc >::GetMemUsed ( ) const

Definition at line 1010 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;
}

Here is the caller graph for this function:

template<class TKey, class TDat, class THashFunc = TDefaultHashFunc<TKey>>
int64 TCache< TKey, TDat, THashFunc >::GetMxMemUsed ( ) const [inline]

Definition at line 985 of file hash.h.

{ return MxMemUsed; }
template<class TKey, class TDat, class THashFunc = TDefaultHashFunc<TKey>>
void* TCache< TKey, TDat, THashFunc >::GetRefToBs ( ) [inline]

Definition at line 997 of file hash.h.

{return RefToBs;}
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 1001 of file hash.h.

                                                                {
  const int64 StartMemUsed = CurMemUsed;
  while (!TimeKeyL.Empty()&&(StartMemUsed-CurMemUsed<MemToPurge)){
    TKey Key=TimeKeyL.Last()->GetVal();
    Del(Key);
  }
}
template<class TKey, class TDat, class THashFunc >
void TCache< TKey, TDat, THashFunc >::Put ( const TKey &  Key,
const TDat &  Dat 
)

Definition at line 1033 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);
  }
}

Here is the caller graph for this function:

template<class TKey, class TDat, class THashFunc = TDefaultHashFunc<TKey>>
void TCache< TKey, TDat, THashFunc >::PutRefToBs ( void *  _RefToBs) [inline]

Definition at line 996 of file hash.h.

{RefToBs=_RefToBs;}
template<class TKey , class TDat , class THashFunc >
bool TCache< TKey, TDat, THashFunc >::RefreshMemUsed ( )

Definition at line 1023 of file hash.h.

                                                  {
  CurMemUsed=GetMemUsed();
  if (CurMemUsed>MxMemUsed){
    Purge(CurMemUsed-MxMemUsed);
    return true;
  }
  return false;
}

Member Data Documentation

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

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

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

Definition at line 970 of file hash.h.

Referenced by TCache< TBlobPt, PHashKey >::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 973 of file hash.h.


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