SNAP Library , Developer Reference  2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TBigStrPool Class Reference

#include <hash.h>

Collaboration diagram for TBigStrPool:

List of all members.

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
TBigStrPooloperator= (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< TSizeIdOffV

Friends

class TPt< TBigStrPool >

Detailed Description

Definition at line 655 of file hash.h.


Constructor & Destructor Documentation

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
}

Here is the call graph for this function:

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));
  }
}

Here is the call graph for this function:

TBigStrPool::TBigStrPool ( const TBigStrPool Pool) [inline]

Definition at line 666 of file hash.h.

References IAssert.

                                       : MxBfL(Pool.MxBfL), BfL(Pool.BfL), GrowBy(Pool.GrowBy) {
    Bf = (char *) malloc(Pool.MxBfL); IAssert(Bf); memcpy(Bf, Pool.Bf, Pool.BfL); }

Definition at line 668 of file hash.h.

References IAssert.

{ if (Bf) free(Bf); else IAssert(MxBfL == 0);  MxBfL = 0; BfL = 0; }

Member Function Documentation

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int TBigStrPool::AddStr ( const char *  Str) [inline]

Definition at line 685 of file hash.h.

References AddStr().

Referenced by AddStr().

{ return AddStr(Str, uint(strlen(Str)) + 1); }

Here is the call graph for this function:

Here is the caller graph for this function:

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().

{ return AddStr(Str.CStr(), Str.Len() + 1); }

Here is the call graph for this function:

Here is the caller graph for this function:

void TBigStrPool::Clr ( bool  DoDel = false) [inline]

Definition at line 698 of file hash.h.

{ BfL = 0; if (DoDel && Bf) { free(Bf); Bf = 0; MxBfL = 0; } }
int TBigStrPool::Cmp ( const int &  StrId,
const char *  Str 
) const [inline]

Definition at line 699 of file hash.h.

References Assert.

                                                   { Assert(StrId < GetStrs());
    if (StrId != 0) return strcmp(Bf + (TSize)IdOffV[StrId], Str); else return strcmp("", Str); }
bool TBigStrPool::Empty ( ) const [inline]

Definition at line 680 of file hash.h.

{ return ! Len(); }
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]); }

Here is the call graph for this function:

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; }

Here is the call graph for this function:

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(""); }

Here is the call graph for this function:

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(""); }

Here is the call graph for this function:

TStr TBigStrPool::GetStr ( const int &  StrId) const [inline]

Definition at line 688 of file hash.h.

References Assert, and TStr::GetNullStr().

                                      { Assert(StrId < GetStrs());
    if (StrId == 0) return TStr::GetNullStr(); else return TStr(Bf + (TSize)IdOffV[StrId]); }

Here is the call graph for this function:

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); }

Here is the call graph for this function:

int TBigStrPool::GetStrs ( ) const [inline]

Definition at line 677 of file hash.h.

{ return IdOffV.Len(); }
TSize TBigStrPool::Len ( ) const [inline]

Definition at line 678 of file hash.h.

Referenced by AddStr().

{ return BfL; }

Here is the caller graph for this function:

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); }

Here is the call graph for this function:

char* TBigStrPool::operator() ( ) const [inline]

Definition at line 681 of file hash.h.

{ return Bf; }
TBigStrPool & TBigStrPool::operator= ( const TBigStrPool Pool)

Definition at line 53 of file hash.cpp.

References Bf, BfL, GrowBy, IAssert, and MxBfL.

                                                             {
  if (this != &Pool) {
    GrowBy = Pool.GrowBy;  MxBfL = Pool.MxBfL;  BfL = Pool.BfL;
    if (Bf) free(Bf); else IAssert(MxBfL == 0);
    Bf = (char *) malloc(MxBfL);  IAssert(Bf);  memcpy(Bf, Pool.Bf, BfL);
  }
  return *this;
}
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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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])); 
  }
}

Here is the call graph for this function:

void TBigStrPool::Save ( const TStr fileName) [inline]

Definition at line 675 of file hash.h.

References Save().

Referenced by Save().

{ TFOut FOut(fileName); Save(FOut); }

Here is the call graph for this function:

Here is the caller graph for this function:

TSize TBigStrPool::Size ( ) const [inline]

Definition at line 679 of file hash.h.

{ return MxBfL; }

Friends And Related Function Documentation

friend class TPt< TBigStrPool > [friend]

Definition at line 655 of file hash.h.


Member Data Documentation

char* TBigStrPool::Bf [private]

Definition at line 659 of file hash.h.

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

Definition at line 657 of file hash.h.

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

Definition at line 655 of file hash.h.

Definition at line 658 of file hash.h.

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

Definition at line 660 of file hash.h.

Referenced by AddStr(), Save(), and TBigStrPool().

Definition at line 657 of file hash.h.

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


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