SNAP Library 2.0, Developer Reference
2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <dt.h>
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 |
TStrPool & | operator= (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 > |
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.
: 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 1685 of file dt.cpp.
References Bf, BfL, TStr::Fmt(), GrowBy, IAssertR, TSIn::Load(), TSIn::LoadBf(), TSIn::LoadCs(), and MxBfL.
: 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::TStrPool | ( | const TStrPool & | Pool | ) | [inline] |
Definition at line 788 of file dt.h.
References TStr::Fmt(), and IAssertR.
: 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); }
TStrPool::~TStrPool | ( | ) | [inline] |
Definition at line 790 of file dt.h.
References TStr::Fmt(), and IAssertR.
Referenced by TUniChDb::Load().
{ if (Bf) free(Bf); else IAssertR(MxBfL == 0, TStr::Fmt("size: %u, expected size: 0", MxBfL).CStr()); Bf = 0; MxBfL = 0; BfL = 0; }
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().
{ 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 TStrPool::AddStr | ( | const char * | Str | ) | [inline] |
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().
void TStrPool::Clr | ( | bool | DoDel = false | ) | [inline] |
int TStrPool::Cmp | ( | const uint & | Offset, |
const char * | Str | ||
) | const [inline] |
bool TStrPool::Empty | ( | ) | const [inline] |
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().
{ Assert(Offset < BfL); if (Offset == 0) return TStr::GetNullStr().CStr(); else return Bf + Offset; }
int TStrPool::GetPrimHashCd | ( | const char * | CStr | ) | [static] |
Definition at line 1720 of file dt.cpp.
{ return TStrHashF_DJB::GetPrimHashCd(CStr); }
int TStrPool::GetPrimHashCd | ( | const uint & | Offset | ) | [inline] |
Definition at line 822 of file dt.h.
References Assert.
{ Assert(Offset < BfL); if (Offset != 0) return GetPrimHashCd(Bf + Offset); else return GetPrimHashCd(""); }
int TStrPool::GetSecHashCd | ( | const char * | CStr | ) | [static] |
Definition at line 1724 of file dt.cpp.
{ return TStrHashF_DJB::GetSecHashCd(CStr); }
int TStrPool::GetSecHashCd | ( | const uint & | Offset | ) | [inline] |
Definition at line 824 of file dt.h.
References Assert.
{ Assert(Offset < BfL); if (Offset != 0) return GetSecHashCd(Bf + Offset); else return GetSecHashCd(""); }
TStr TStrPool::GetStr | ( | const uint & | Offset | ) | const [inline] |
Definition at line 809 of file dt.h.
References Assert, and TStr::GetNullStr().
{ Assert(Offset < BfL); if (Offset == 0) return TStr::GetNullStr(); else return TStr(Bf + Offset); }
uint TStrPool::Len | ( | ) | const [inline] |
static PStrPool TStrPool::Load | ( | TSIn & | SIn, |
bool | LoadCompacted = true |
||
) | [inline, static] |
static PStrPool TStrPool::New | ( | const uint & | _MxBfLen = 0 , |
const uint & | _GrowBy = 16*1024*1024 |
||
) | [inline, static] |
static PStrPool TStrPool::New | ( | TSIn & | SIn | ) | [inline, static] |
static PStrPool TStrPool::New | ( | const TStr & | fileName | ) | [inline, static] |
Definition at line 1700 of file dt.cpp.
References Bf, BfL, TStr::Fmt(), GrowBy, IAssertR, and MxBfL.
{ if (this != &Pool) { GrowBy = Pool.GrowBy; MxBfL = Pool.MxBfL; BfL = Pool.BfL; if (Bf) free(Bf); else IAssertR(MxBfL == 0, TStr::Fmt("size: %u, expected size: 0", MxBfL).CStr()); 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); } return *this; }
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().
{ uint newSize = MxBfL; while (newSize < _MxBfL) { if (newSize >= GrowBy && GrowBy > 0) newSize += GrowBy; else if (newSize > 0) newSize *= 2; else newSize = TInt::GetMn(GrowBy, 1024); // check for overflow at 4GB IAssertR(newSize >= MxBfL, TStr::Fmt("TStrPool::Resize: %u, %u [Size larger than 4Gb, which is not supported by TStrPool]", newSize, MxBfL).CStr()); } if (newSize > MxBfL) { Bf = (char *) realloc(Bf, newSize); IAssertR(Bf, TStr::Fmt("old Bf size: %u, new size: %u", MxBfL, newSize).CStr()); MxBfL = newSize; } IAssertR(MxBfL >= _MxBfL, TStr::Fmt("new size: %u, requested size: %u", MxBfL, _MxBfL).CStr()); }
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().
void TStrPool::Save | ( | const TStr & | FNm | ) | [inline] |
Definition at line 797 of file dt.h.
References TFOut::New(), and Save().
Referenced by Save().
{PSOut SOut=TFOut::New(FNm); Save(*SOut);}
uint TStrPool::Size | ( | ) | const [inline] |
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] |
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().