SNAP Library, User Reference  2012-10-15 15:06:59
SNAP, a general purpose network analysis and graph mining library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
dt.h File Reference

Go to the source code of this file.

Classes

class  TRnd
class  TMemIn
class  TMemOut
class  TChA
class  TChAIn
class  TRStr
class  TStr
class  TStrIn
class  TDbStr
class  TVoid
class  TBool
class  TCh
class  TUCh
class  TSInt
class  TInt
class  TUInt
class  TUInt64
class  TFlt
class  TAscFlt
class  TSFlt
class  TLFlt
class  TFltRect

Typedefs

typedef TVec< TStrTStrV

Functions

 ClassHdTP (TXmlTok, PXmlTok)
void Resize (const int &_MxBfL)
bool DoFitLen (const int &LBfL) const
 TMem (const int &_MxBfL=0)
static PMem New (const int &MxBfL=0)
 TMem (const void *_Bf, const int &_BfL)
static PMem New (const void *Bf, const int &BfL)
 TMem (const TMem &Mem)
static PMem New (const TMem &Mem)
static PMem New (const PMem &Mem)
 TMem (const TStr &Str)
static PMem New (const TStr &Str)
 ~TMem ()
 TMem (TSIn &SIn)
void Save (TSOut &SOut) const
void LoadXml (const PXmlTok &XmlTok, const TStr &Nm)
void SaveXml (TSOut &SOut, const TStr &Nm) const
TMemoperator= (const TMem &Mem)
char * operator() () const
TMemoperator+= (const char &Ch)
TMemoperator+= (const TMem &Mem)
TMemoperator+= (const TStr &Str)
TMemoperator+= (const PSIn &SIn)
char & operator[] (const int &ChN) const
int GetMemUsed () const
void Gen (const int &_BfL)
void GenZeros (const int &_BfL)
void Reserve (const int &_MxBfL, const bool &DoClr=true)
void Del (const int &BChN, const int &EChN)
void Clr (const bool &DoDel=true)
int Len () const
bool Empty () const
void Trunc (const int &_BfL)
void Push (const char &Ch)
char Pop ()
bool DoFitStr (const TStr &Str) const
void AddBf (const void *Bf, const int &BfL)
char * GetBf () const
TStr GetAsStr (const char &NewNullCh='\0') const
PSIn GetSIn () const
static void LoadMem (const PSIn &SIn, TMem &Mem)
static void LoadMem (const PSIn &SIn, const PMem &Mem)
void SaveMem (const PSOut &SOut) const
void Resize (uint _MxBfL)
 TStrPool (uint MxBfLen=0, uint _GrowBy=16 *1024 *1024)
 TStrPool (TSIn &SIn, bool LoadCompact=true)
 TStrPool (const TStrPool &Pool)
 ~TStrPool ()
static PStrPool New (uint _MxBfLen=0, uint _GrowBy=16 *1024 *1024)
static PStrPool New (TSIn &SIn)
static PStrPool Load (TSIn &SIn, bool LoadCompacted=true)
void Save (const TStr &FNm)
uint Size () const
TStrPooloperator= (const TStrPool &Pool)
uint AddStr (const char *Str, uint Len)
uint AddStr (const char *Str)
uint AddStr (const TStr &Str)
TStr GetStr (uint Offset) const
const char * GetCStr (uint Offset) const
void Clr (bool DoDel=false)
int Cmp (uint Offset, const char *Str) const
static int GetPrimHashCd (const char *CStr)
static int GetSecHashCd (const char *CStr)
int GetPrimHashCd (uint Offset)
int GetSecHashCd (uint Offset)
void Resize (const ::TSize &_MxBfL)
 TStrPool64 (::TSize _MxBfL=0,::TSize _GrowBy=16 *1024 *1024)
 TStrPool64 (const TStrPool64 &StrPool)
 TStrPool64 (TSIn &SIn, bool LoadCompact=true)
 ~TStrPool64 ()
static PStrPool64 New (::TSize MxBfL=0,::TSize GrowBy=16 *1024 *1024)
TStrPool64operator= (const TStrPool64 &StrPool)
uint64 Reserved () const
int Cmp (uint64 Offset, const char *Str) const
TStr GetStr (const uint64 &StrId) const

Variables

ClassTP(TMem, PMem) private char * Bf

Typedef Documentation

typedef TVec<TStr> TStrV

Definition at line 394 of file dt.h.


Function Documentation

void TMem::AddBf ( const void *  Bf,
const int &  BfL 
)

Definition at line 279 of file dt.cpp.

                                                {
        IAssert((_BfL>=0) && (_Bf != NULL));
  Reserve(Len() + _BfL, false);
  memcpy(Bf + BfL, _Bf, _BfL);  
   BfL+=_BfL;
  //char* ChBf=(char*)Bf;
  //for (int BfC=0; BfC<BfL; BfC++){
  //  char Ch=ChBf[BfC];
  //  operator+=(Ch);
  //}
}
int TBigStrPool::AddStr ( const char *  Str,
uint  Len 
)

Definition at line 1680 of file dt.cpp.

                                               {
  IAssertR(Len > 0, "String too short (length includes the null character)");  //J: if (! Len) return -1;
  if (Len == 1 && BfL > 0) { return 0; } // empty string
  Assert(Str);  Assert(Len > 0);
  if (BfL + Len > MxBfL) Resize(BfL + Len);
  memcpy(Bf + BfL, Str, Len);
  uint Pos = BfL;  BfL += Len;  return Pos;
}
uint AddStr ( const char *  Str)

Definition at line 790 of file dt.h.

{ return AddStr(Str, uint(strlen(Str)) + 1); }
uint64 AddStr ( const TStr Str)

Definition at line 791 of file dt.h.

{ return AddStr(Str.CStr(), Str.Len() + 1); }
ClassHdTP ( TXmlTok  ,
PXmlTok   
)
void Clr ( const bool &  DoDel = true)

Definition at line 121 of file dt.h.

                                  {
    if (DoDel){if (Bf!=NULL){delete[] Bf;} MxBfL=0; BfL=0; Bf=NULL;}
    else {BfL=0;}}
void Clr ( bool  DoDel = false)

Definition at line 800 of file dt.h.

{ BfL = 0; if (DoDel && Bf) { free(Bf); Bf = 0; MxBfL = 0; } }
int Cmp ( uint  Offset,
const char *  Str 
) const

Definition at line 801 of file dt.h.

                                              { Assert(Offset < BfL);
    if (Offset != 0) return strcmp(Bf + Offset, Str); else return strcmp("", Str); }
int Cmp ( uint64  Offset,
const char *  Str 
) const

Definition at line 840 of file dt.h.

                                                { Assert(Offset < BfL);
    if (Offset != 0) return strcmp(Bf + Offset, Str); else return strcmp("", Str); }
void Del ( const int &  BChN,
const int &  EChN 
)
bool DoFitLen ( const int &  LBfL) const

Definition at line 72 of file dt.h.

{return BfL+LBfL<=MxBfL;}
bool TMem::DoFitStr ( const TStr Str) const

Definition at line 235 of file dt.cpp.

                                         {
  return DoFitLen(Str.Len()+1);
}
bool Empty ( ) const

Definition at line 125 of file dt.h.

{return BfL==0;}
void Gen ( const int &  _BfL)

Definition at line 113 of file dt.h.

                           {
    Clr(); Resize(_BfL); BfL=_BfL;}
void GenZeros ( const int &  _BfL)

Definition at line 115 of file dt.h.

                                {
    Clr(false); Resize(_BfL); BfL=_BfL;
    if (BfL > 0) memset(Bf, 0, BfL);}
TStr GetAsStr ( const char &  NewNullCh = '\0') const
char* GetBf ( ) const

Definition at line 134 of file dt.h.

{return Bf;}
const char* GetCStr ( uint  Offset) const

Definition at line 795 of file dt.h.

                                         { Assert(Offset < BfL);
    if (Offset == 0) return TStr::GetNullStr().CStr(); else return Bf + Offset; }
int GetMemUsed ( ) const

Definition at line 111 of file dt.h.

{return 2*sizeof(int)+sizeof(char*)+MxBfL;}
static int GetPrimHashCd ( const char *  CStr) [static]
int GetPrimHashCd ( uint  Offset)

Definition at line 806 of file dt.h.

                                 { Assert(Offset < BfL);
    if (Offset != 0) return GetPrimHashCd(Bf + Offset); else return GetPrimHashCd(""); }
static int GetSecHashCd ( const char *  CStr) [static]
int GetSecHashCd ( uint  Offset)

Definition at line 808 of file dt.h.

                                { Assert(Offset < BfL);
    if (Offset != 0) return GetSecHashCd(Bf + Offset); else return GetSecHashCd(""); }
PSIn GetSIn ( ) const

Definition at line 136 of file dt.h.

                      {
    TMOut MOut(BfL); MOut.SaveBf(Bf, BfL); return MOut.GetSIn();}
TStr GetStr ( uint  Offset) const

Definition at line 793 of file dt.h.

                                 { Assert(Offset < BfL);
    if (Offset == 0) return TStr::GetNullStr(); else return TStr(Bf + Offset); }
TStr GetStr ( const uint64 StrId) const
uint64 Len ( ) const

Definition at line 124 of file dt.h.

{return BfL;}
static PStrPool64 Load ( TSIn SIn,
bool  LoadCompacted = true 
) [static]

Definition at line 779 of file dt.h.

{ return PStrPool(new TStrPool(SIn, LoadCompacted)); }
static void LoadMem ( const PSIn SIn,
TMem Mem 
) [static]

Definition at line 139 of file dt.h.

                                                 {
    Mem.Clr(); Mem.Gen(SIn->Len()); SIn->GetBf(Mem.Bf, SIn->Len());}
static void LoadMem ( const PSIn SIn,
const PMem &  Mem 
) [static]

Definition at line 141 of file dt.h.

                                                       {
    Mem->Clr(); Mem->Gen(SIn->Len()); SIn->GetBf(Mem->Bf, SIn->Len());}
void LoadXml ( const PXmlTok XmlTok,
const TStr Nm 
)
static PMem New ( const int &  MxBfL = 0) [static]

Definition at line 77 of file dt.h.

{return new TMem(MxBfL);}
static PMem New ( const void *  Bf,
const int &  BfL 
) [static]

Definition at line 81 of file dt.h.

{return new TMem(Bf, BfL);}
static PMem New ( const TMem Mem) [static]

Definition at line 85 of file dt.h.

{return new TMem(Mem);}
static PMem New ( const PMem &  Mem) [static]

Definition at line 86 of file dt.h.

{return new TMem(*Mem);}
static PStrPool New ( const TStr Str) [static]

Definition at line 88 of file dt.h.

{return new TMem(Str);}
static PStrPool New ( uint  _MxBfLen = 0,
uint  _GrowBy = 16*1024*1024 
) [static]

Definition at line 776 of file dt.h.

{ return PStrPool(new TStrPool(_MxBfLen, _GrowBy)); }
static PStrPool New ( TSIn SIn) [static]

Definition at line 777 of file dt.h.

{ return new TStrPool(SIn); }
static PStrPool64 New ( ::TSize  MxBfL = 0,
::TSize  GrowBy = 16*1024*1024 
) [static]

Definition at line 827 of file dt.h.

                                                                      { 
      return PStrPool64(new TStrPool64(MxBfL, GrowBy)); }
char * operator() ( ) const

Definition at line 104 of file dt.h.

{return Bf;}
TMem& operator+= ( const char &  Ch)
TMem& operator+= ( const TMem Mem)
TMem& operator+= ( const TStr Str)
TMem& operator+= ( const PSIn SIn)
TMem& operator= ( const TMem Mem)

Definition at line 98 of file dt.h.

                                  {
    if (this!=&Mem){
      if (Bf!=NULL){delete[] Bf;}
      MxBfL=Mem.MxBfL; BfL=Mem.BfL; Bf=NULL;
      if (MxBfL>0){Bf=new char[MxBfL]; memcpy(Bf, Mem.Bf, BfL);}}
    return *this;}
TStrPool& operator= ( const TStrPool Pool)
TStrPool64& operator= ( const TStrPool64 StrPool)
char * operator[] ( const int &  ChN) const

Definition at line 109 of file dt.h.

                                         {
    Assert((0<=ChN)&&(ChN<BfL)); return Bf[ChN];}
char Pop ( )

Definition at line 129 of file dt.h.

{IAssert(BfL>0); BfL--; return Bf[BfL];}
void Push ( const char &  Ch)

Definition at line 128 of file dt.h.

{operator+=(Ch);}
void Reserve ( const int &  _MxBfL,
const bool &  DoClr = true 
)

Definition at line 118 of file dt.h.

                                                           {
          if (DoClr){ Clr(); } Resize(_MxBfL);}
uint64 Reserved ( ) const

Definition at line 838 of file dt.h.

{ return MxBfL; }
void Resize ( const int &  _MxBfL)
void Resize ( uint  _MxBfL) [private]
void Resize ( const ::TSize _MxBfL) [private]
void Save ( TSOut SOut) const

Definition at line 93 of file dt.h.

                               {
    SOut.Save(MxBfL); SOut.Save(BfL); SOut.SaveBf(Bf, BfL);}
void Save ( const TStr FNm)

Definition at line 781 of file dt.h.

{PSOut SOut=TFOut::New(FNm); Save(*SOut);}
void SaveMem ( const PSOut SOut) const

Definition at line 143 of file dt.h.

{SOut->SaveBf(Bf, Len());}
void SaveXml ( TSOut SOut,
const TStr Nm 
) const
uint Size ( ) const

Definition at line 784 of file dt.h.

{ return MxBfL; }
TMem ( const int &  _MxBfL = 0)

Definition at line 74 of file dt.h.

                           :
    MxBfL(_MxBfL), BfL(0), Bf(NULL){ IAssert(BfL>=0);
    if (MxBfL>0){Bf=new char[MxBfL]; IAssert(Bf!=NULL);}}
TMem ( const void *  _Bf,
const int &  _BfL 
)

Definition at line 78 of file dt.h.

                                        :
    MxBfL(_BfL), BfL(_BfL), Bf(NULL){ IAssert(BfL>=0);
    if (BfL>0){Bf=new char[BfL]; IAssert(Bf!=NULL); memcpy(Bf, _Bf, BfL);}}
TMem ( const TMem Mem)

Definition at line 82 of file dt.h.

                       :
    MxBfL(Mem.MxBfL), BfL(Mem.BfL), Bf(NULL){
    if (MxBfL>0){Bf=new char[MxBfL]; memcpy(Bf, Mem.Bf, BfL);}}
TMem::TMem ( const TStr Str)

Definition at line 222 of file dt.cpp.

                         :
  MxBfL(Str.Len()), BfL(MxBfL), Bf(NULL){
  if (MxBfL>0){
    Bf=new char[MxBfL];
    if (BfL>0){memcpy(Bf, Str.CStr(), BfL);}
  }
}
TMem ( TSIn SIn) [explicit]

Definition at line 90 of file dt.h.

                          {
    SIn.Load(MxBfL); SIn.Load(BfL);
    Bf=new char[MxBfL=BfL]; SIn.LoadBf(Bf, BfL);}
void Trunc ( const int &  _BfL)

Definition at line 126 of file dt.h.

                             {
    if ((0<=_BfL)&&(_BfL<=BfL)){BfL=_BfL;}}
TStrPool::TStrPool ( uint  MxBfLen = 0,
uint  _GrowBy = 16*1024*1024 
)

Definition at line 1648 of file dt.cpp.

                                             : MxBfL(MxBfLen), BfL(0), GrowBy(_GrowBy), Bf(0) {
  //IAssert(MxBfL >= 0); IAssert(GrowBy >= 0);
  if (MxBfL > 0) { Bf = (char *) malloc(MxBfL);  IAssertR(Bf, TStr::Fmt("Can not resize buffer to %u bytes. [Program failed to allocate more memory. Solution: Get a bigger machine.]", MxBfL).CStr()); }
  AddStr(""); // add an empty string at the beginning for fast future access
}
TStrPool::TStrPool ( TSIn SIn,
bool  LoadCompact = true 
)

Definition at line 1654 of file dt.cpp.

                                              : MxBfL(0), BfL(0), GrowBy(0), Bf(0) {
  SIn.Load(MxBfL);  SIn.Load(BfL);  SIn.Load(GrowBy);
  //IAssert(MxBfL >= BfL);  IAssert(BfL >= 0);  IAssert(GrowBy >= 0);
  if (LoadCompact) MxBfL = BfL;
  if (MxBfL > 0) { Bf = (char *) malloc(MxBfL); IAssertR(Bf, TStr::Fmt("Can not resize buffer to %u bytes. [Program failed to allocate more memory. Solution: Get a bigger machine.]", MxBfL).CStr()); }
  if (BfL > 0) SIn.LoadBf(Bf, BfL);
  SIn.LoadCs();
}
TStrPool ( const TStrPool Pool)

Definition at line 772 of file dt.h.

                                 : MxBfL(Pool.MxBfL), BfL(Pool.BfL), GrowBy(Pool.GrowBy) {
    Bf = (char *) malloc(Pool.MxBfL); IAssertR(Bf, TStr::Fmt("Can not resize buffer to %u bytes. [Program failed to allocate more memory. Solution: Get a bigger machine.]", MxBfL).CStr()); memcpy(Bf, Pool.Bf, Pool.BfL); }
TStrPool64::TStrPool64 ( ::TSize  _MxBfL = 0,
::TSize  _GrowBy = 16*1024*1024 
)

Definition at line 1715 of file dt.cpp.

                                                 :
        MxBfL(_MxBfL), BfL(0), GrowBy(_GrowBy), Bf(NULL) {

    if (MxBfL > 0) { Bf = (char*)malloc(MxBfL); IAssert(Bf != NULL); }
    AddStr("");
}
TStrPool64::TStrPool64 ( const TStrPool64 StrPool)

Definition at line 1722 of file dt.cpp.

                                               : 
  MxBfL(StrPool.MxBfL), BfL(StrPool.BfL), GrowBy(StrPool.GrowBy) {
    if (Bf != NULL) { free(Bf); } else { IAssert(MxBfL == 0); }
    Bf = (char*)malloc(StrPool.MxBfL); IAssert(Bf != NULL); 
    memcpy(Bf, StrPool.Bf, BfL);
}
TStrPool64::TStrPool64 ( TSIn SIn,
bool  LoadCompact = true 
)

Definition at line 1729 of file dt.cpp.

                                                 : 
  MxBfL(0), BfL(0), GrowBy(0), Bf(0) {
    uint64 _GrowBy, _MxBfL, _BfL;
    SIn.Load(_GrowBy); SIn.Load(_MxBfL); SIn.Load(_BfL);
    GrowBy = (::TSize)_GrowBy; MxBfL = (::TSize)_MxBfL; BfL = (::TSize)_BfL;
    if (LoadCompact) { MxBfL = BfL; }
    if (MxBfL > 0) { Bf = (char*)malloc(MxBfL); IAssert(Bf != NULL); }
    for (::TSize BfN = 0; BfN < _BfL; BfN++) { Bf[BfN] = SIn.GetCh(); }
    SIn.LoadCs();
}
~TMem ( )

Definition at line 89 of file dt.h.

{if (Bf!=NULL){delete[] Bf;}}
~TStrPool ( )

Definition at line 774 of file dt.h.

{ if (Bf) free(Bf); else IAssertR(MxBfL == 0, TStr::Fmt("size: %u, expected size: 0", MxBfL).CStr());  Bf = 0; MxBfL = 0; BfL = 0; }
~TStrPool64 ( )

Definition at line 824 of file dt.h.

{ Clr(true); }

Variable Documentation

ClassTP (TStrPool64, PStrPool64) private char* Bf

Definition at line 67 of file dt.h.