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
TStrPool64 Class Reference

#include <dt.h>

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.

1746  :
1747  MxBfL(_MxBfL), BfL(0), GrowBy(_GrowBy), Bf(NULL) {
1748 
1749  if (MxBfL > 0) { Bf = (char*)malloc(MxBfL); IAssert(Bf != NULL); }
1750  AddStr("");
1751 }
#define IAssert(Cond)
Definition: bd.h:262
::TSize MxBfL
Definition: dt.h:832
::TSize BfL
Definition: dt.h:832
uint64 AddStr(const TStr &Str)
Definition: dt.cpp:1796
::TSize GrowBy
Definition: dt.h:832
char * Bf
Definition: dt.h:833
TStrPool64::TStrPool64 ( const TStrPool64 StrPool)

Definition at line 1753 of file dt.cpp.

1753  :
1754  MxBfL(StrPool.MxBfL), BfL(StrPool.BfL), GrowBy(StrPool.GrowBy) {
1755  if (Bf != NULL) { free(Bf); } else { IAssert(MxBfL == 0); }
1756  Bf = (char*)malloc(StrPool.MxBfL); IAssert(Bf != NULL);
1757  memcpy(Bf, StrPool.Bf, BfL);
1758 }
#define IAssert(Cond)
Definition: bd.h:262
::TSize MxBfL
Definition: dt.h:832
::TSize BfL
Definition: dt.h:832
::TSize GrowBy
Definition: dt.h:832
char * Bf
Definition: dt.h:833
TStrPool64::TStrPool64 ( TSIn SIn,
bool  LoadCompact = true 
)

Definition at line 1760 of file dt.cpp.

1760  :
1761  MxBfL(0), BfL(0), GrowBy(0), Bf(0) {
1762  uint64 _GrowBy, _MxBfL, _BfL;
1763  SIn.Load(_GrowBy); SIn.Load(_MxBfL); SIn.Load(_BfL);
1764  GrowBy = (::TSize)_GrowBy; MxBfL = (::TSize)_MxBfL; BfL = (::TSize)_BfL;
1765  if (LoadCompact) { MxBfL = BfL; }
1766  if (MxBfL > 0) { Bf = (char*)malloc(MxBfL); IAssert(Bf != NULL); }
1767  for (::TSize BfN = 0; BfN < _BfL; BfN++) { Bf[BfN] = SIn.GetCh(); }
1768  SIn.LoadCs();
1769 }
#define IAssert(Cond)
Definition: bd.h:262
::TSize MxBfL
Definition: dt.h:832
void LoadCs()
Definition: fl.cpp:28
unsigned long long uint64
Definition: bd.h:38
void Load(bool &Bool)
Definition: fl.h:84
size_t TSize
Definition: bd.h:58
::TSize BfL
Definition: dt.h:832
virtual char GetCh()=0
::TSize GrowBy
Definition: dt.h:832
char * Bf
Definition: dt.h:833
TStrPool64::~TStrPool64 ( )
inline

Definition at line 840 of file dt.h.

840 { Clr(true); }
void Clr(bool DoDel=false)
Definition: dt.cpp:1788

Member Function Documentation

uint64 TStrPool64::AddStr ( const TStr Str)

Definition at line 1796 of file dt.cpp.

1796  {
1797  const int Len = Str.Len() + 1;
1798  if (BfL + Len > MxBfL) { Resize(BfL + Len); }
1799  memcpy(Bf + BfL, Str.CStr(), Len);
1800  ::TSize Offset = BfL; BfL += Len;
1801  return uint64(Offset);
1802 }
int Len() const
Definition: dt.h:487
::TSize MxBfL
Definition: dt.h:832
unsigned long long uint64
Definition: bd.h:38
size_t TSize
Definition: bd.h:58
::TSize BfL
Definition: dt.h:832
uint64 Len() const
Definition: dt.h:853
void Resize(const ::TSize &_MxBfL)
Definition: dt.cpp:1730
char * CStr()
Definition: dt.h:476
char * Bf
Definition: dt.h:833
void TStrPool64::Clr ( bool  DoDel = false)

Definition at line 1788 of file dt.cpp.

1788  {
1789  BfL = 0;
1790  if (DoDel && (Bf!=NULL)) {
1791  free(Bf);
1792  Bf = NULL; MxBfL = 0;
1793  }
1794 }
::TSize MxBfL
Definition: dt.h:832
::TSize BfL
Definition: dt.h:832
char * Bf
Definition: dt.h:833
int TStrPool64::Cmp ( uint64  Offset,
const char *  Str 
) const
inline

Definition at line 856 of file dt.h.

856  { Assert(Offset < BfL);
857  if (Offset != 0) return strcmp(Bf + Offset, Str); else return strcmp("", Str); }
#define Assert(Cond)
Definition: bd.h:251
::TSize BfL
Definition: dt.h:832
char * Bf
Definition: dt.h:833
bool TStrPool64::Empty ( ) const
inline

Definition at line 852 of file dt.h.

852 { return (BfL == 0); }
::TSize BfL
Definition: dt.h:832
uint64 TStrPool64::GetMemUsed ( ) const
inline

Definition at line 850 of file dt.h.

850 { return 3*sizeof(::TSize) + uint64(MxBfL); }
::TSize MxBfL
Definition: dt.h:832
unsigned long long uint64
Definition: bd.h:38
size_t TSize
Definition: bd.h:58
TStr TStrPool64::GetStr ( const uint64 StrId) const

Definition at line 1804 of file dt.cpp.

1804  {
1805  ::TSize Offset = (::TSize)StrId;
1806  return TStr(Bf + Offset);
1807 }
size_t TSize
Definition: bd.h:58
Definition: dt.h:412
char * Bf
Definition: dt.h:833
uint64 TStrPool64::Len ( ) const
inline

Definition at line 853 of file dt.h.

853 {return BfL;}
::TSize BfL
Definition: dt.h:832
static PStrPool64 TStrPool64::Load ( TSIn SIn,
bool  LoadCompact = true 
)
inlinestatic

Definition at line 845 of file dt.h.

845  {
846  return PStrPool64(new TStrPool64(SIn, LoadCompact)); }
TPt< TStrPool64 > PStrPool64
Definition: dt.h:830
TStrPool64(::TSize _MxBfL=0,::TSize _GrowBy=16 *1024 *1024)
Definition: dt.cpp:1746
static PStrPool64 TStrPool64::New ( ::TSize  MxBfL = 0,
::TSize  GrowBy = 16*1024*1024 
)
inlinestatic

Definition at line 843 of file dt.h.

843  {
844  return PStrPool64(new TStrPool64(MxBfL, GrowBy)); }
TPt< TStrPool64 > PStrPool64
Definition: dt.h:830
TStrPool64(::TSize _MxBfL=0,::TSize _GrowBy=16 *1024 *1024)
Definition: dt.cpp:1746
::TSize MxBfL
Definition: dt.h:832
::TSize GrowBy
Definition: dt.h:832
TStrPool64 & TStrPool64::operator= ( const TStrPool64 StrPool)

Definition at line 1778 of file dt.cpp.

1778  {
1779  if (this != &StrPool) {
1780  GrowBy = StrPool.GrowBy; MxBfL = StrPool.MxBfL; BfL = StrPool.BfL;
1781  if (Bf != NULL) { free(Bf); } else { IAssert(MxBfL == 0); }
1782  Bf = (char*)malloc(MxBfL); IAssert(Bf != NULL);
1783  memcpy(Bf, StrPool.Bf, BfL);
1784  }
1785  return *this;
1786 }
#define IAssert(Cond)
Definition: bd.h:262
::TSize MxBfL
Definition: dt.h:832
::TSize BfL
Definition: dt.h:832
::TSize GrowBy
Definition: dt.h:832
char * Bf
Definition: dt.h:833
uint64 TStrPool64::Reserved ( ) const
inline

Definition at line 854 of file dt.h.

854 { return MxBfL; }
::TSize MxBfL
Definition: dt.h:832
void TStrPool64::Resize ( const ::TSize _MxBfL)
private

Definition at line 1730 of file dt.cpp.

1730  {
1731  ::TSize newSize = MxBfL;
1732  while (newSize < _MxBfL) {
1733  if (newSize >= GrowBy && GrowBy > 0) newSize += GrowBy;
1734  else if (newSize > 0) newSize *= 2;
1735  else newSize = (GrowBy > ::TSize(1024)) ? ::TSize(1024) : GrowBy;
1736  IAssert(newSize >= MxBfL); // assert we are growing
1737  }
1738  if (newSize > MxBfL) {
1739  Bf = (char *) realloc(Bf, newSize);
1740  IAssertR(Bf, TStr::Fmt("old Bf size: %u, new size: %u", MxBfL, newSize).CStr());
1741  MxBfL = newSize;
1742  }
1743  IAssert(MxBfL >= _MxBfL);
1744 }
#define IAssert(Cond)
Definition: bd.h:262
#define IAssertR(Cond, Reason)
Definition: bd.h:265
::TSize MxBfL
Definition: dt.h:832
size_t TSize
Definition: bd.h:58
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
::TSize GrowBy
Definition: dt.h:832
char * Bf
Definition: dt.h:833
void TStrPool64::Save ( TSOut SOut) const

Definition at line 1771 of file dt.cpp.

1771  {
1772  uint64 _GrowBy = GrowBy, _MxBfL = MxBfL, _BfL = BfL;
1773  SOut.Save(_GrowBy); SOut.Save(_MxBfL); SOut.Save(_BfL);
1774  for (::TSize BfN = 0; BfN < _BfL; BfN++) { SOut.PutCh(Bf[BfN]); }
1775  SOut.SaveCs();
1776 }
virtual int PutCh(const char &Ch)=0
::TSize MxBfL
Definition: dt.h:832
void SaveCs()
Definition: fl.h:171
unsigned long long uint64
Definition: bd.h:38
size_t TSize
Definition: bd.h:58
::TSize BfL
Definition: dt.h:832
void Save(const bool &Bool)
Definition: fl.h:173
::TSize GrowBy
Definition: dt.h:832
char * Bf
Definition: dt.h:833

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.

TCRef TStrPool64::CRef
private

Definition at line 830 of file dt.h.

::TSize TStrPool64::GrowBy
private

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: