SNAP Library 2.1, User Reference  2013-09-25 10:47:25
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
TStrPool64 Class Reference

#include <dt.h>

List of all members.

Public Member Functions

 TStrPool64 (::TSize _MxBfL=0,::TSize _GrowBy=16 *1024 *1024)
 TStrPool64 (const TStrPool64 &StrPool)
 TStrPool64 (TSIn &SIn, bool LoadCompact=true)
 ~TStrPool64 ()
void Save (TSOut &SOut) const
TStrPool64operator= (const TStrPool64 &StrPool)
uint64 GetMemUsed () const
bool Empty () const
uint64 Len () const
uint64 Reserved () const
void Clr (bool DoDel=false)
int Cmp (uint64 Offset, const char *Str) const
uint64 AddStr (const TStr &Str)
TStr GetStr (const uint64 &StrId) const

Static Public Member Functions

static PStrPool64 New (::TSize MxBfL=0,::TSize GrowBy=16 *1024 *1024)
static PStrPool64 Load (TSIn &SIn, bool LoadCompact=true)

Private Member Functions

void Resize (const ::TSize &_MxBfL)

Private Attributes

TCRef CRef
::TSize MxBfL
::TSize BfL
::TSize GrowBy
char * Bf

Friends

class TPt< TStrPool64 >

Detailed Description

Definition at line 830 of file dt.h.


Constructor & Destructor Documentation

TStrPool64::TStrPool64 ( ::TSize  _MxBfL = 0,
::TSize  _GrowBy = 16*1024*1024 
)

Definition at line 1746 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 1753 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 1760 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();
}

Definition at line 840 of file dt.h.

{ Clr(true); }

Member Function Documentation

uint64 TStrPool64::AddStr ( const TStr Str)

Definition at line 1796 of file dt.cpp.

                                         {
  const int Len = Str.Len() + 1;
  if (BfL + Len > MxBfL) { Resize(BfL + Len); }
  memcpy(Bf + BfL, Str.CStr(), Len);
  ::TSize Offset = BfL;  BfL += Len;
  return uint64(Offset);
}
void TStrPool64::Clr ( bool  DoDel = false)

Definition at line 1788 of file dt.cpp.

                               { 
  BfL = 0; 
  if (DoDel && (Bf!=NULL)) { 
    free(Bf); 
    Bf = NULL; MxBfL = 0; 
  } 
}
int TStrPool64::Cmp ( uint64  Offset,
const char *  Str 
) const [inline]

Definition at line 856 of file dt.h.

                                                { Assert(Offset < BfL);
    if (Offset != 0) return strcmp(Bf + Offset, Str); else return strcmp("", Str); }
bool TStrPool64::Empty ( ) const [inline]

Definition at line 852 of file dt.h.

{ return (BfL == 0); }
uint64 TStrPool64::GetMemUsed ( ) const [inline]

Definition at line 850 of file dt.h.

{ return 3*sizeof(::TSize) + uint64(MxBfL); }
TStr TStrPool64::GetStr ( const uint64 StrId) const

Definition at line 1804 of file dt.cpp.

                                                 {
  ::TSize Offset = (::TSize)StrId;
  return TStr(Bf + Offset);
}
uint64 TStrPool64::Len ( ) const [inline]

Definition at line 853 of file dt.h.

{return BfL;}
static PStrPool64 TStrPool64::Load ( TSIn SIn,
bool  LoadCompact = true 
) [inline, static]

Definition at line 845 of file dt.h.

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

Definition at line 843 of file dt.h.

                                                                      { 
      return PStrPool64(new TStrPool64(MxBfL, GrowBy)); }
TStrPool64 & TStrPool64::operator= ( const TStrPool64 StrPool)

Definition at line 1778 of file dt.cpp.

                                                           {
  if (this != &StrPool) {
  GrowBy = StrPool.GrowBy;  MxBfL = StrPool.MxBfL;  BfL = StrPool.BfL;
  if (Bf != NULL) { free(Bf); } else { IAssert(MxBfL == 0); }
  Bf = (char*)malloc(MxBfL); IAssert(Bf != NULL); 
  memcpy(Bf, StrPool.Bf, BfL);
  }
  return *this;
}
uint64 TStrPool64::Reserved ( ) const [inline]

Definition at line 854 of file dt.h.

{ return MxBfL; }
void TStrPool64::Resize ( const ::TSize _MxBfL) [private]

Definition at line 1730 of file dt.cpp.

                                           {
  ::TSize newSize = MxBfL;
  while (newSize < _MxBfL) {
    if (newSize >= GrowBy && GrowBy > 0) newSize += GrowBy;
    else if (newSize > 0) newSize *= 2;
    else newSize = (GrowBy > ::TSize(1024)) ? ::TSize(1024) : GrowBy;
    IAssert(newSize >= MxBfL); // assert we are growing
  }
  if (newSize > MxBfL) {
    Bf = (char *) realloc(Bf, newSize);
    IAssertR(Bf, TStr::Fmt("old Bf size: %u, new size: %u", MxBfL, newSize).CStr());
    MxBfL = newSize;
  }
  IAssert(MxBfL >= _MxBfL);
}
void TStrPool64::Save ( TSOut SOut) const

Definition at line 1771 of file dt.cpp.

                                       {
  uint64 _GrowBy = GrowBy, _MxBfL = MxBfL, _BfL = BfL;
  SOut.Save(_GrowBy);  SOut.Save(_MxBfL);  SOut.Save(_BfL);
  for (::TSize BfN = 0; BfN < _BfL; BfN++) { SOut.PutCh(Bf[BfN]); }
  SOut.SaveCs();
}

Friends And Related Function Documentation

friend class TPt< TStrPool64 > [friend]

Definition at line 830 of file dt.h.


Member Data Documentation

char* TStrPool64::Bf [private]

Definition at line 833 of file dt.h.

::TSize TStrPool64::BfL [private]

Definition at line 832 of file dt.h.

Definition at line 830 of file dt.h.

Definition at line 832 of file dt.h.

::TSize TStrPool64::MxBfL [private]

Definition at line 832 of file dt.h.


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