|
SNAP Library 2.0, User Reference
2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <hash.h>
Public Member Functions | |
| TBigStrPool (TSize MxBfLen=0, uint _GrowBy=16 *1024 *1024) | |
| TBigStrPool (TSIn &SIn, bool LoadCompact=true) | |
| TBigStrPool (const TBigStrPool &Pool) | |
| ~TBigStrPool () | |
| void | Save (TSOut &SOut) const |
| void | Save (const TStr &fileName) |
| int | GetStrs () const |
| TSize | Len () const |
| TSize | Size () const |
| bool | Empty () const |
| char * | operator() () const |
| TBigStrPool & | operator= (const TBigStrPool &Pool) |
| int | AddStr (const char *Str, uint Len) |
| int | AddStr (const char *Str) |
| int | AddStr (const TStr &Str) |
| TStr | GetStr (const int &StrId) const |
| const char * | GetCStr (const int &StrId) const |
| TStr | GetStrFromOffset (const TSize &Offset) const |
| const char * | GetCStrFromOffset (const TSize &Offset) const |
| void | Clr (bool DoDel=false) |
| int | Cmp (const int &StrId, const char *Str) const |
| int | GetPrimHashCd (const int &StrId) |
| int | GetSecHashCd (const int &StrId) |
Static Public Member Functions | |
| static PBigStrPool | New (TSize _MxBfLen=0, uint _GrowBy=16 *1024 *1024) |
| static PBigStrPool | New (TSIn &SIn) |
| static PBigStrPool | New (const TStr &fileName) |
| static PBigStrPool | Load (TSIn &SIn, bool LoadCompacted=true) |
| static int | GetPrimHashCd (const char *CStr) |
| static int | GetSecHashCd (const char *CStr) |
Private Member Functions | |
| void | Resize (TSize _MxBfL) |
Private Attributes | |
| TCRef | CRef |
| TSize | MxBfL |
| TSize | BfL |
| uint | GrowBy |
| char * | Bf |
| TVec< TSize > | IdOffV |
Friends | |
| class | TPt< TBigStrPool > |
| TBigStrPool::TBigStrPool | ( | TSize | MxBfLen = 0, |
| uint | _GrowBy = 16*1024*1024 |
||
| ) |
| TBigStrPool::TBigStrPool | ( | TSIn & | SIn, |
| bool | LoadCompact = true |
||
| ) |
Definition at line 24 of file hash.cpp.
: MxBfL(0), BfL(0), GrowBy(0), Bf(0) { uint64 Tmp; SIn.Load(Tmp); IAssert(Tmp <= uint64(TSizeMx)); MxBfL=TSize(Tmp); SIn.Load(Tmp); IAssert(Tmp <= uint64(TSizeMx)); BfL=TSize(Tmp); SIn.Load(GrowBy); IAssert(MxBfL >= BfL); IAssert(BfL >= 0); IAssert(GrowBy >= 0); if (LoadCompact) MxBfL = BfL; if (MxBfL > 0) { Bf = (char *) malloc(MxBfL); IAssert(Bf); } if (BfL > 0) { SIn.LoadBf(Bf, BfL); } SIn.LoadCs(); int NStr=0; SIn.Load(NStr); IdOffV.Gen(NStr, 0); for (int i = 0; i < NStr; i++) { SIn.Load(Tmp); IAssert(Tmp <= uint64(TSizeMx)); IdOffV.Add(TSize(Tmp)); } }
| TBigStrPool::TBigStrPool | ( | const TBigStrPool & | Pool | ) | [inline] |
| TBigStrPool::~TBigStrPool | ( | ) | [inline] |
| int TBigStrPool::AddStr | ( | const char * | Str, |
| uint | Len | ||
| ) |
Definition at line 63 of file hash.cpp.
{
IAssertR(Len > 0, "String too short (lenght includes the null character)"); //J: if (! Len) return -1;
Assert(Str); Assert(Len > 0);
if (Len == 1 && IdOffV.Len() > 0) { return 0; } // empty string
if (BfL + Len > MxBfL) { Resize(BfL + Len); }
memcpy(Bf + BfL, Str, Len);
TSize Pos = BfL; BfL += Len;
IdOffV.Add(Pos);
return IdOffV.Len()-1;
}
| int TBigStrPool::AddStr | ( | const char * | Str | ) | [inline] |
| int TBigStrPool::AddStr | ( | const TStr & | Str | ) | [inline] |
| void TBigStrPool::Clr | ( | bool | DoDel = false | ) | [inline] |
| int TBigStrPool::Cmp | ( | const int & | StrId, |
| const char * | Str | ||
| ) | const [inline] |
| bool TBigStrPool::Empty | ( | ) | const [inline] |
| const char* TBigStrPool::GetCStr | ( | const int & | StrId | ) | const [inline] |
| const char* TBigStrPool::GetCStrFromOffset | ( | const TSize & | Offset | ) | const [inline] |
| int TBigStrPool::GetPrimHashCd | ( | const char * | CStr | ) | [static] |
Definition at line 74 of file hash.cpp.
{
return TStrHashF_DJB::GetPrimHashCd(CStr);
}
| int TBigStrPool::GetPrimHashCd | ( | const int & | StrId | ) | [inline] |
Definition at line 706 of file hash.h.
{ Assert(StrId < GetStrs());
if (StrId != 0) return GetPrimHashCd(Bf + (TSize)IdOffV[StrId]); else return GetPrimHashCd(""); }
| int TBigStrPool::GetSecHashCd | ( | const char * | CStr | ) | [static] |
Definition at line 78 of file hash.cpp.
{
return TStrHashF_DJB::GetSecHashCd(CStr);
}
| int TBigStrPool::GetSecHashCd | ( | const int & | StrId | ) | [inline] |
Definition at line 708 of file hash.h.
{ Assert(StrId < GetStrs());
if (StrId != 0) return GetSecHashCd(Bf + (TSize)IdOffV[StrId]); else return GetSecHashCd(""); }
| TStr TBigStrPool::GetStr | ( | const int & | StrId | ) | const [inline] |
| TStr TBigStrPool::GetStrFromOffset | ( | const TSize & | Offset | ) | const [inline] |
| int TBigStrPool::GetStrs | ( | ) | const [inline] |
| TSize TBigStrPool::Len | ( | ) | const [inline] |
| static PBigStrPool TBigStrPool::Load | ( | TSIn & | SIn, |
| bool | LoadCompacted = true |
||
| ) | [inline, static] |
Definition at line 675 of file hash.h.
{ return PBigStrPool(new TBigStrPool(SIn, LoadCompacted)); }
| static PBigStrPool TBigStrPool::New | ( | TSize | _MxBfLen = 0, |
| uint | _GrowBy = 16*1024*1024 |
||
| ) | [inline, static] |
Definition at line 672 of file hash.h.
{ return PBigStrPool(new TBigStrPool(_MxBfLen, _GrowBy)); }
| static PBigStrPool TBigStrPool::New | ( | TSIn & | SIn | ) | [inline, static] |
Definition at line 673 of file hash.h.
{ return new TBigStrPool(SIn); }
| static PBigStrPool TBigStrPool::New | ( | const TStr & | fileName | ) | [inline, static] |
Definition at line 674 of file hash.h.
{ PSIn SIn = TFIn::New(fileName); return new TBigStrPool(*SIn); }
| char* TBigStrPool::operator() | ( | ) | const [inline] |
| TBigStrPool & TBigStrPool::operator= | ( | const TBigStrPool & | Pool | ) |
| void TBigStrPool::Resize | ( | TSize | _MxBfL | ) | [private] |
Definition at line 3 of file hash.cpp.
{
TSize newSize = MxBfL;
while (newSize < _MxBfL) {
if (newSize >= GrowBy && GrowBy > 0) newSize += GrowBy;
else if (newSize > 0) newSize *= 2;
else newSize = TInt::GetMn(GrowBy, 1024);
}
if (newSize > MxBfL) {
Bf = (char *) realloc(Bf, newSize);
IAssertR(Bf, TStr::Fmt("old Bf size: %u, new size: %u", MxBfL, newSize).CStr());
MxBfL = newSize;
}
IAssert(MxBfL >= _MxBfL);
}
| void TBigStrPool::Save | ( | TSOut & | SOut | ) | const |
| void TBigStrPool::Save | ( | const TStr & | fileName | ) | [inline] |
| TSize TBigStrPool::Size | ( | ) | const [inline] |
friend class TPt< TBigStrPool > [friend] |
char* TBigStrPool::Bf [private] |
TSize TBigStrPool::BfL [private] |
TCRef TBigStrPool::CRef [private] |
uint TBigStrPool::GrowBy [private] |
TVec<TSize> TBigStrPool::IdOffV [private] |
TSize TBigStrPool::MxBfL [private] |