|
SNAP Library , User Reference
2013-01-07 14:03:36
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 1648 of file dt.cpp.
: 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 1654 of file dt.cpp.
: 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] |
| TStrPool::~TStrPool | ( | ) | [inline] |
| uint TStrPool::AddStr | ( | const char * | Str, |
| const uint & | Len | ||
| ) |
Definition at line 1680 of file dt.cpp.
{
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] |
| 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] |
| int TStrPool::GetPrimHashCd | ( | const char * | CStr | ) | [static] |
Definition at line 1689 of file dt.cpp.
{
return TStrHashF_DJB::GetPrimHashCd(CStr);
}
| int TStrPool::GetPrimHashCd | ( | const uint & | Offset | ) | [inline] |
Definition at line 814 of file dt.h.
{ Assert(Offset < BfL);
if (Offset != 0) return GetPrimHashCd(Bf + Offset); else return GetPrimHashCd(""); }
| int TStrPool::GetSecHashCd | ( | const char * | CStr | ) | [static] |
Definition at line 1693 of file dt.cpp.
{
return TStrHashF_DJB::GetSecHashCd(CStr);
}
| int TStrPool::GetSecHashCd | ( | const uint & | Offset | ) | [inline] |
Definition at line 816 of file dt.h.
{ Assert(Offset < BfL);
if (Offset != 0) return GetSecHashCd(Bf + Offset); else return GetSecHashCd(""); }
| TStr TStrPool::GetStr | ( | const uint & | Offset | ) | const [inline] |
| 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 1669 of file dt.cpp.
{
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 1631 of file dt.cpp.
{
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 |
| void TStrPool::Save | ( | const TStr & | FNm | ) | [inline] |
Definition at line 789 of file dt.h.
{PSOut SOut=TFOut::New(FNm); Save(*SOut);}
| uint TStrPool::Size | ( | ) | const [inline] |
char* TStrPool::Bf [private] |
uint TStrPool::BfL [private] |
TCRef TStrPool::CRef [private] |
uint TStrPool::GrowBy [private] |
uint TStrPool::MxBfL [private] |