SNAP Library , Developer Reference
2013-01-07 14:03:36
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 |
||
) |
Definition at line 18 of file hash.cpp.
References AddStr(), Bf, IAssert, and MxBfL.
: MxBfL(MxBfLen), BfL(0), GrowBy(_GrowBy), Bf(0) { //IAssert(MxBfL >= 0); IAssert(GrowBy >= 0); if (MxBfL > 0) { Bf = (char *) malloc(MxBfL); IAssert(Bf); } AddStr(""); // add empty string }
TBigStrPool::TBigStrPool | ( | TSIn & | SIn, |
bool | LoadCompact = true |
||
) |
Definition at line 24 of file hash.cpp.
References TVec< TVal >::Add(), Bf, BfL, TVec< TVal >::Gen(), GrowBy, IAssert, IdOffV, TSIn::Load(), TSIn::LoadBf(), TSIn::LoadCs(), MxBfL, and TSizeMx.
: 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.
References TVec< TVal >::Add(), Assert, Bf, BfL, IAssertR, IdOffV, TVec< TVal >::Len(), Len(), MxBfL, and Resize().
Referenced by TBigStrPool().
{ 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] |
Definition at line 686 of file hash.h.
References AddStr(), TStr::CStr(), and TStr::Len().
Referenced by AddStr().
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] |
Definition at line 690 of file hash.h.
References Assert, TStr::CStr(), and TStr::GetNullStr().
{ Assert(StrId < GetStrs()); if (StrId == 0) return TStr::GetNullStr().CStr(); else return (Bf + (TSize)IdOffV[StrId]); }
const char* TBigStrPool::GetCStrFromOffset | ( | const TSize & | Offset | ) | const [inline] |
Definition at line 695 of file hash.h.
References Assert, TStr::CStr(), and TStr::GetNullStr().
{ Assert(Offset < BfL); if (Offset == 0) return TStr::GetNullStr().CStr(); else return Bf + Offset; }
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 704 of file hash.h.
References Assert, and TPt< TRec >::GetPrimHashCd().
{ 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 706 of file hash.h.
References Assert, and TPt< TRec >::GetSecHashCd().
{ 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] |
Definition at line 693 of file hash.h.
References Assert, and TStr::GetNullStr().
{ Assert(Offset < BfL); if (Offset == 0) return TStr::GetNullStr(); else return TStr(Bf + Offset); }
int TBigStrPool::GetStrs | ( | ) | const [inline] |
TSize TBigStrPool::Len | ( | ) | const [inline] |
static PBigStrPool TBigStrPool::Load | ( | TSIn & | SIn, |
bool | LoadCompacted = true |
||
) | [inline, static] |
Definition at line 673 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 670 of file hash.h.
{ return PBigStrPool(new TBigStrPool(_MxBfLen, _GrowBy)); }
static PBigStrPool TBigStrPool::New | ( | TSIn & | SIn | ) | [inline, static] |
Definition at line 671 of file hash.h.
{ return new TBigStrPool(SIn); }
static PBigStrPool TBigStrPool::New | ( | const TStr & | fileName | ) | [inline, static] |
Definition at line 672 of file hash.h.
References TFIn::New().
{ 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.
References Bf, TStr::Fmt(), TInt::GetMn(), GrowBy, IAssert, IAssertR, and MxBfL.
Referenced by AddStr().
{ 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 |
Definition at line 43 of file hash.cpp.
References Bf, BfL, GrowBy, IdOffV, TVec< TVal >::Len(), MxBfL, TSOut::Save(), TSOut::SaveBf(), and TSOut::SaveCs().
{ SOut.Save(uint64(MxBfL)); SOut.Save(uint64(BfL)); SOut.Save(GrowBy); if (BfL > 0) { SOut.SaveBf(Bf, BfL); } SOut.SaveCs(); SOut.Save(IdOffV.Len()); for (int i = 0; i < IdOffV.Len(); i++) { SOut.Save(uint64(IdOffV[i])); } }
void TBigStrPool::Save | ( | const TStr & | fileName | ) | [inline] |
TSize TBigStrPool::Size | ( | ) | const [inline] |
friend class TPt< TBigStrPool > [friend] |
char* TBigStrPool::Bf [private] |
Definition at line 659 of file hash.h.
Referenced by AddStr(), operator=(), Resize(), Save(), and TBigStrPool().
TSize TBigStrPool::BfL [private] |
Definition at line 657 of file hash.h.
Referenced by AddStr(), operator=(), Save(), and TBigStrPool().
TCRef TBigStrPool::CRef [private] |
uint TBigStrPool::GrowBy [private] |
Definition at line 658 of file hash.h.
Referenced by operator=(), Resize(), Save(), and TBigStrPool().
TVec<TSize> TBigStrPool::IdOffV [private] |
Definition at line 660 of file hash.h.
Referenced by AddStr(), Save(), and TBigStrPool().
TSize TBigStrPool::MxBfL [private] |
Definition at line 657 of file hash.h.
Referenced by AddStr(), operator=(), Resize(), Save(), and TBigStrPool().