SNAP Library 2.3, Developer Reference  2014-06-16 11:58:46
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
TStrPool Class Reference

#include <dt.h>

Collaboration diagram for TStrPool:

Public Member Functions

 TStrPool (const uint &MxBfLen=0, const uint &_GrowBy=16 *1024 *1024)
 
 TStrPool (TSIn &SIn, bool LoadCompact=true)
 
 TStrPool (const TStrPool &Pool)
 
 ~TStrPool ()
 
void Save (TSOut &SOut) const
 
void Save (const TStr &FNm)
 
uint Len () const
 
uint Size () const
 
bool Empty () const
 
char * operator() () const
 
TStrPooloperator= (const TStrPool &Pool)
 
uint AddStr (const char *Str, const uint &Len)
 
uint AddStr (const char *Str)
 
uint AddStr (const TStr &Str)
 
TStr GetStr (const uint &Offset) const
 
const char * GetCStr (const uint &Offset) const
 
void Clr (bool DoDel=false)
 
int Cmp (const uint &Offset, const char *Str) const
 
int GetPrimHashCd (const uint &Offset)
 
int GetSecHashCd (const uint &Offset)
 

Static Public Member Functions

static PStrPool New (const uint &_MxBfLen=0, const uint &_GrowBy=16 *1024 *1024)
 
static PStrPool New (TSIn &SIn)
 
static PStrPool New (const TStr &fileName)
 
static PStrPool Load (TSIn &SIn, bool LoadCompacted=true)
 
static int GetPrimHashCd (const char *CStr)
 
static int GetSecHashCd (const char *CStr)
 

Private Member Functions

void Resize (const uint &_MxBfL)
 

Private Attributes

TCRef CRef
 
uint MxBfL
 
uint BfL
 
uint GrowBy
 
char * Bf
 

Friends

class TPt< TStrPool >
 

Detailed Description

Definition at line 779 of file dt.h.

Constructor & Destructor Documentation

TStrPool::TStrPool ( const uint MxBfLen = 0,
const uint _GrowBy = 16*1024*1024 
)

Definition at line 1679 of file dt.cpp.

References AddStr(), Bf, TStr::Fmt(), IAssertR, and MxBfL.

1679  : MxBfL(MxBfLen), BfL(0), GrowBy(_GrowBy), Bf(0) {
1680  //IAssert(MxBfL >= 0); IAssert(GrowBy >= 0);
1681  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()); }
1682  AddStr(""); // add an empty string at the beginning for fast future access
1683 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
uint MxBfL
Definition: dt.h:781
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * Bf
Definition: dt.h:782
uint GrowBy
Definition: dt.h:781
uint AddStr(const char *Str, const uint &Len)
Definition: dt.cpp:1711
uint BfL
Definition: dt.h:781

Here is the call graph for this function:

TStrPool::TStrPool ( TSIn SIn,
bool  LoadCompact = true 
)

Definition at line 1685 of file dt.cpp.

References Bf, BfL, TStr::Fmt(), GrowBy, IAssertR, TSIn::Load(), TSIn::LoadBf(), TSIn::LoadCs(), and MxBfL.

1685  : MxBfL(0), BfL(0), GrowBy(0), Bf(0) {
1686  SIn.Load(MxBfL); SIn.Load(BfL); SIn.Load(GrowBy);
1687  //IAssert(MxBfL >= BfL); IAssert(BfL >= 0); IAssert(GrowBy >= 0);
1688  if (LoadCompact) MxBfL = BfL;
1689  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()); }
1690  if (BfL > 0) SIn.LoadBf(Bf, BfL);
1691  SIn.LoadCs();
1692 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
uint MxBfL
Definition: dt.h:781
void LoadCs()
Definition: fl.cpp:28
void Load(bool &Bool)
Definition: fl.h:84
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * Bf
Definition: dt.h:782
void LoadBf(const void *Bf, const TSize &BfL)
Definition: fl.h:81
uint GrowBy
Definition: dt.h:781
uint BfL
Definition: dt.h:781

Here is the call graph for this function:

TStrPool::TStrPool ( const TStrPool Pool)
inline

Definition at line 788 of file dt.h.

References TStr::Fmt(), and IAssertR.

788  : MxBfL(Pool.MxBfL), BfL(Pool.BfL), GrowBy(Pool.GrowBy) {
789  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); }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
uint MxBfL
Definition: dt.h:781
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * Bf
Definition: dt.h:782
uint GrowBy
Definition: dt.h:781
uint BfL
Definition: dt.h:781

Here is the call graph for this function:

TStrPool::~TStrPool ( )
inline

Definition at line 790 of file dt.h.

References TStr::Fmt(), and IAssertR.

Referenced by TUniChDb::Load().

790 { if (Bf) free(Bf); else IAssertR(MxBfL == 0, TStr::Fmt("size: %u, expected size: 0", MxBfL).CStr()); Bf = 0; MxBfL = 0; BfL = 0; }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
uint MxBfL
Definition: dt.h:781
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * Bf
Definition: dt.h:782
uint BfL
Definition: dt.h:781

Here is the call graph for this function:

Here is the caller graph for this function:

Member Function Documentation

uint TStrPool::AddStr ( const char *  Str,
const uint Len 
)

Definition at line 1711 of file dt.cpp.

References Assert, Bf, BfL, IAssertR, Len(), MxBfL, and Resize().

Referenced by TUniChDb::LoadTxt(), and TStrPool().

1711  {
1712  IAssertR(Len > 0, "String too short (length includes the null character)"); //J: if (! Len) return -1;
1713  if (Len == 1 && BfL > 0) { return 0; } // empty string
1714  Assert(Str); Assert(Len > 0);
1715  if (BfL + Len > MxBfL) Resize(BfL + Len);
1716  memcpy(Bf + BfL, Str, Len);
1717  uint Pos = BfL; BfL += Len; return Pos;
1718 }
void Resize(const uint &_MxBfL)
Definition: dt.cpp:1662
#define IAssertR(Cond, Reason)
Definition: bd.h:265
unsigned int uint
Definition: bd.h:11
uint MxBfL
Definition: dt.h:781
#define Assert(Cond)
Definition: bd.h:251
char * Bf
Definition: dt.h:782
uint Len() const
Definition: dt.h:799
uint BfL
Definition: dt.h:781

Here is the call graph for this function:

Here is the caller graph for this function:

uint TStrPool::AddStr ( const char *  Str)
inline

Definition at line 806 of file dt.h.

References AddStr().

Referenced by AddStr().

806 { return AddStr(Str, uint(strlen(Str)) + 1); }
unsigned int uint
Definition: bd.h:11
uint AddStr(const char *Str, const uint &Len)
Definition: dt.cpp:1711

Here is the call graph for this function:

Here is the caller graph for this function:

uint TStrPool::AddStr ( const TStr Str)
inline

Definition at line 807 of file dt.h.

References AddStr(), TStr::CStr(), and TStr::Len().

Referenced by AddStr().

807 { return AddStr(Str.CStr(), Str.Len() + 1); }
int Len() const
Definition: dt.h:487
char * CStr()
Definition: dt.h:476
uint AddStr(const char *Str, const uint &Len)
Definition: dt.cpp:1711

Here is the call graph for this function:

Here is the caller graph for this function:

void TStrPool::Clr ( bool  DoDel = false)
inline

Definition at line 816 of file dt.h.

Referenced by TUniChDb::Clr().

816 { BfL = 0; if (DoDel && Bf) { free(Bf); Bf = 0; MxBfL = 0; } }
uint MxBfL
Definition: dt.h:781
char * Bf
Definition: dt.h:782
uint BfL
Definition: dt.h:781

Here is the caller graph for this function:

int TStrPool::Cmp ( const uint Offset,
const char *  Str 
) const
inline

Definition at line 817 of file dt.h.

References Assert.

817  { Assert(Offset < BfL);
818  if (Offset != 0) return strcmp(Bf + Offset, Str); else return strcmp("", Str); }
#define Assert(Cond)
Definition: bd.h:251
char * Bf
Definition: dt.h:782
uint BfL
Definition: dt.h:781
bool TStrPool::Empty ( ) const
inline

Definition at line 801 of file dt.h.

801 { return ! Len(); }
uint Len() const
Definition: dt.h:799
const char* TStrPool::GetCStr ( const uint Offset) const
inline

Definition at line 811 of file dt.h.

References Assert, TStr::CStr(), and TStr::GetNullStr().

Referenced by TUniChDb::GetCharName().

811  { Assert(Offset < BfL);
812  if (Offset == 0) return TStr::GetNullStr().CStr(); else return Bf + Offset; }
#define Assert(Cond)
Definition: bd.h:251
static TStr GetNullStr()
Definition: dt.cpp:1626
char * Bf
Definition: dt.h:782
char * CStr()
Definition: dt.h:476
uint BfL
Definition: dt.h:781

Here is the call graph for this function:

Here is the caller graph for this function:

int TStrPool::GetPrimHashCd ( const char *  CStr)
static

Definition at line 1720 of file dt.cpp.

References TStrHashF_DJB::GetPrimHashCd().

1720  {
1721  return TStrHashF_DJB::GetPrimHashCd(CStr);
1722 }
static int GetPrimHashCd(const char *p)
Definition: hash.h:1155

Here is the call graph for this function:

int TStrPool::GetPrimHashCd ( const uint Offset)
inline

Definition at line 822 of file dt.h.

References Assert.

822  { Assert(Offset < BfL);
823  if (Offset != 0) return GetPrimHashCd(Bf + Offset); else return GetPrimHashCd(""); }
static int GetPrimHashCd(const char *CStr)
Definition: dt.cpp:1720
#define Assert(Cond)
Definition: bd.h:251
char * Bf
Definition: dt.h:782
uint BfL
Definition: dt.h:781
int TStrPool::GetSecHashCd ( const char *  CStr)
static

Definition at line 1724 of file dt.cpp.

References TStrHashF_DJB::GetSecHashCd().

1724  {
1725  return TStrHashF_DJB::GetSecHashCd(CStr);
1726 }
static int GetSecHashCd(const char *p)
Definition: hash.h:1158

Here is the call graph for this function:

int TStrPool::GetSecHashCd ( const uint Offset)
inline

Definition at line 824 of file dt.h.

References Assert.

824  { Assert(Offset < BfL);
825  if (Offset != 0) return GetSecHashCd(Bf + Offset); else return GetSecHashCd(""); }
static int GetSecHashCd(const char *CStr)
Definition: dt.cpp:1724
#define Assert(Cond)
Definition: bd.h:251
char * Bf
Definition: dt.h:782
uint BfL
Definition: dt.h:781
TStr TStrPool::GetStr ( const uint Offset) const
inline

Definition at line 809 of file dt.h.

References Assert, and TStr::GetNullStr().

809  { Assert(Offset < BfL);
810  if (Offset == 0) return TStr::GetNullStr(); else return TStr(Bf + Offset); }
#define Assert(Cond)
Definition: bd.h:251
static TStr GetNullStr()
Definition: dt.cpp:1626
Definition: dt.h:412
char * Bf
Definition: dt.h:782
uint BfL
Definition: dt.h:781

Here is the call graph for this function:

uint TStrPool::Len ( ) const
inline

Definition at line 799 of file dt.h.

Referenced by AddStr().

799 { return BfL; }
uint BfL
Definition: dt.h:781

Here is the caller graph for this function:

static PStrPool TStrPool::Load ( TSIn SIn,
bool  LoadCompacted = true 
)
inlinestatic

Definition at line 795 of file dt.h.

795 { return PStrPool(new TStrPool(SIn, LoadCompacted)); }
TPt< TStrPool > PStrPool
Definition: dt.h:779
TStrPool(const uint &MxBfLen=0, const uint &_GrowBy=16 *1024 *1024)
Definition: dt.cpp:1679
static PStrPool TStrPool::New ( const uint _MxBfLen = 0,
const uint _GrowBy = 16*1024*1024 
)
inlinestatic

Definition at line 792 of file dt.h.

792 { return PStrPool(new TStrPool(_MxBfLen, _GrowBy)); }
TPt< TStrPool > PStrPool
Definition: dt.h:779
TStrPool(const uint &MxBfLen=0, const uint &_GrowBy=16 *1024 *1024)
Definition: dt.cpp:1679
static PStrPool TStrPool::New ( TSIn SIn)
inlinestatic

Definition at line 793 of file dt.h.

793 { return new TStrPool(SIn); }
TStrPool(const uint &MxBfLen=0, const uint &_GrowBy=16 *1024 *1024)
Definition: dt.cpp:1679
static PStrPool TStrPool::New ( const TStr fileName)
inlinestatic

Definition at line 794 of file dt.h.

References TFIn::New().

794 { PSIn SIn = TFIn::New(fileName); return new TStrPool(*SIn); }
static PSIn New(const TStr &FNm)
Definition: fl.cpp:290
Definition: bd.h:196
TStrPool(const uint &MxBfLen=0, const uint &_GrowBy=16 *1024 *1024)
Definition: dt.cpp:1679

Here is the call graph for this function:

char* TStrPool::operator() ( ) const
inline

Definition at line 802 of file dt.h.

802 { return Bf; }
char * Bf
Definition: dt.h:782
TStrPool & TStrPool::operator= ( const TStrPool Pool)

Definition at line 1700 of file dt.cpp.

References Bf, BfL, TStr::Fmt(), GrowBy, IAssertR, and MxBfL.

1700  {
1701  if (this != &Pool) {
1702  GrowBy = Pool.GrowBy; MxBfL = Pool.MxBfL; BfL = Pool.BfL;
1703  if (Bf) free(Bf); else IAssertR(MxBfL == 0, TStr::Fmt("size: %u, expected size: 0", MxBfL).CStr());
1704  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()); memcpy(Bf, Pool.Bf, BfL);
1705  }
1706  return *this;
1707 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
uint MxBfL
Definition: dt.h:781
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * Bf
Definition: dt.h:782
uint GrowBy
Definition: dt.h:781
uint BfL
Definition: dt.h:781

Here is the call graph for this function:

void TStrPool::Resize ( const uint _MxBfL)
private

Definition at line 1662 of file dt.cpp.

References Bf, TStr::Fmt(), TInt::GetMn(), GrowBy, IAssertR, and MxBfL.

Referenced by AddStr().

1662  {
1663  uint newSize = MxBfL;
1664  while (newSize < _MxBfL) {
1665  if (newSize >= GrowBy && GrowBy > 0) newSize += GrowBy;
1666  else if (newSize > 0) newSize *= 2;
1667  else newSize = TInt::GetMn(GrowBy, 1024);
1668  // check for overflow at 4GB
1669  IAssertR(newSize >= MxBfL, TStr::Fmt("TStrPool::Resize: %u, %u [Size larger than 4Gb, which is not supported by TStrPool]", newSize, MxBfL).CStr());
1670  }
1671  if (newSize > MxBfL) {
1672  Bf = (char *) realloc(Bf, newSize);
1673  IAssertR(Bf, TStr::Fmt("old Bf size: %u, new size: %u", MxBfL, newSize).CStr());
1674  MxBfL = newSize;
1675  }
1676  IAssertR(MxBfL >= _MxBfL, TStr::Fmt("new size: %u, requested size: %u", MxBfL, _MxBfL).CStr());
1677 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
unsigned int uint
Definition: bd.h:11
uint MxBfL
Definition: dt.h:781
static int GetMn(const int &Int1, const int &Int2)
Definition: dt.h:1087
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * Bf
Definition: dt.h:782
uint GrowBy
Definition: dt.h:781

Here is the call graph for this function:

Here is the caller graph for this function:

void TStrPool::Save ( TSOut SOut) const

Definition at line 1694 of file dt.cpp.

References Bf, BfL, GrowBy, MxBfL, TSOut::Save(), TSOut::SaveBf(), and TSOut::SaveCs().

Referenced by TUniChDb::Save().

1694  {
1695  SOut.Save(MxBfL); SOut.Save(BfL); SOut.Save(GrowBy);
1696  SOut.SaveBf(Bf, BfL);
1697  SOut.SaveCs();
1698 }
uint MxBfL
Definition: dt.h:781
void SaveCs()
Definition: fl.h:171
void SaveBf(const void *Bf, const TSize &BfL)
Definition: fl.h:172
void Save(const bool &Bool)
Definition: fl.h:173
char * Bf
Definition: dt.h:782
uint GrowBy
Definition: dt.h:781
uint BfL
Definition: dt.h:781

Here is the call graph for this function:

Here is the caller graph for this function:

void TStrPool::Save ( const TStr FNm)
inline

Definition at line 797 of file dt.h.

References TFOut::New(), and Save().

Referenced by Save().

797 {PSOut SOut=TFOut::New(FNm); Save(*SOut);}
static PSOut New(const TStr &FNm, const bool &Append=false)
Definition: fl.cpp:442
void Save(TSOut &SOut) const
Definition: dt.cpp:1694

Here is the call graph for this function:

Here is the caller graph for this function:

uint TStrPool::Size ( ) const
inline

Definition at line 800 of file dt.h.

800 { return MxBfL; }
uint MxBfL
Definition: dt.h:781

Friends And Related Function Documentation

friend class TPt< TStrPool >
friend

Definition at line 779 of file dt.h.

Member Data Documentation

char* TStrPool::Bf
private

Definition at line 782 of file dt.h.

Referenced by AddStr(), operator=(), Resize(), Save(), and TStrPool().

uint TStrPool::BfL
private

Definition at line 781 of file dt.h.

Referenced by AddStr(), operator=(), Save(), and TStrPool().

TCRef TStrPool::CRef
private

Definition at line 779 of file dt.h.

uint TStrPool::GrowBy
private

Definition at line 781 of file dt.h.

Referenced by operator=(), Resize(), Save(), and TStrPool().

uint TStrPool::MxBfL
private

Definition at line 781 of file dt.h.

Referenced by AddStr(), operator=(), Resize(), Save(), and TStrPool().


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