SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
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 834 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:836
::TSize BfL
Definition: dt.h:836
uint64 AddStr(const TStr &Str)
Definition: dt.cpp:1796
::TSize GrowBy
Definition: dt.h:836
char * Bf
Definition: dt.h:837
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:836
::TSize BfL
Definition: dt.h:836
::TSize GrowBy
Definition: dt.h:836
char * Bf
Definition: dt.h:837
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:836
virtual 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:836
virtual char GetCh()=0
::TSize GrowBy
Definition: dt.h:836
char * Bf
Definition: dt.h:837
TStrPool64::~TStrPool64 ( )
inline

Definition at line 844 of file dt.h.

844 { 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:490
::TSize MxBfL
Definition: dt.h:836
unsigned long long uint64
Definition: bd.h:38
size_t TSize
Definition: bd.h:58
::TSize BfL
Definition: dt.h:836
uint64 Len() const
Definition: dt.h:857
void Resize(const ::TSize &_MxBfL)
Definition: dt.cpp:1730
char * CStr()
Definition: dt.h:479
char * Bf
Definition: dt.h:837
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:836
::TSize BfL
Definition: dt.h:836
char * Bf
Definition: dt.h:837
int TStrPool64::Cmp ( uint64  Offset,
const char *  Str 
) const
inline

Definition at line 860 of file dt.h.

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

Definition at line 856 of file dt.h.

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

Definition at line 854 of file dt.h.

854 { return 3*sizeof(::TSize) + uint64(MxBfL); }
::TSize MxBfL
Definition: dt.h:836
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:837
uint64 TStrPool64::Len ( ) const
inline

Definition at line 857 of file dt.h.

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

Definition at line 849 of file dt.h.

849  {
850  return PStrPool64(new TStrPool64(SIn, LoadCompact)); }
TPt< TStrPool64 > PStrPool64
Definition: dt.h:834
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 847 of file dt.h.

847  {
848  return PStrPool64(new TStrPool64(MxBfL, GrowBy)); }
TPt< TStrPool64 > PStrPool64
Definition: dt.h:834
TStrPool64(::TSize _MxBfL=0,::TSize _GrowBy=16 *1024 *1024)
Definition: dt.cpp:1746
::TSize MxBfL
Definition: dt.h:836
::TSize GrowBy
Definition: dt.h:836
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:836
::TSize BfL
Definition: dt.h:836
::TSize GrowBy
Definition: dt.h:836
char * Bf
Definition: dt.h:837
uint64 TStrPool64::Reserved ( ) const
inline

Definition at line 858 of file dt.h.

858 { return MxBfL; }
::TSize MxBfL
Definition: dt.h:836
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:836
size_t TSize
Definition: bd.h:58
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
::TSize GrowBy
Definition: dt.h:836
char * Bf
Definition: dt.h:837
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:836
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:836
void Save(const bool &Bool)
Definition: fl.h:173
::TSize GrowBy
Definition: dt.h:836
char * Bf
Definition: dt.h:837

Friends And Related Function Documentation

friend class TPt< TStrPool64 >
friend

Definition at line 834 of file dt.h.

Member Data Documentation

char* TStrPool64::Bf
private

Definition at line 837 of file dt.h.

::TSize TStrPool64::BfL
private

Definition at line 836 of file dt.h.

TCRef TStrPool64::CRef
private

Definition at line 834 of file dt.h.

::TSize TStrPool64::GrowBy
private

Definition at line 836 of file dt.h.

::TSize TStrPool64::MxBfL
private

Definition at line 836 of file dt.h.


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