SNAP Library 2.4, User Reference  2015-05-11 19:40:56
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TBigStrPool Class Reference

#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
 
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 658 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.

18  : MxBfL(MxBfLen), BfL(0), GrowBy(_GrowBy), Bf(0) {
19  //IAssert(MxBfL >= 0); IAssert(GrowBy >= 0);
20  if (MxBfL > 0) { Bf = (char *) malloc(MxBfL); IAssert(Bf); }
21  AddStr(""); // add empty string
22 }
#define IAssert(Cond)
Definition: bd.h:262
uint GrowBy
Definition: hash.h:661
int AddStr(const char *Str, uint Len)
Definition: hash.cpp:63
TSize MxBfL
Definition: hash.h:660
TSize BfL
Definition: hash.h:660
char * Bf
Definition: hash.h:662
TBigStrPool::TBigStrPool ( TSIn SIn,
bool  LoadCompact = true 
)

Definition at line 24 of file hash.cpp.

24  : MxBfL(0), BfL(0), GrowBy(0), Bf(0) {
25  uint64 Tmp;
26  SIn.Load(Tmp); IAssert(Tmp <= uint64(TSizeMx)); MxBfL=TSize(Tmp);
27  SIn.Load(Tmp); IAssert(Tmp <= uint64(TSizeMx)); BfL=TSize(Tmp);
28  SIn.Load(GrowBy);
29  IAssert(MxBfL >= BfL); IAssert(BfL >= 0); IAssert(GrowBy >= 0);
30  if (LoadCompact) MxBfL = BfL;
31  if (MxBfL > 0) { Bf = (char *) malloc(MxBfL); IAssert(Bf); }
32  if (BfL > 0) { SIn.LoadBf(Bf, BfL); }
33  SIn.LoadCs();
34  int NStr=0; SIn.Load(NStr);
35  IdOffV.Gen(NStr, 0);
36  for (int i = 0; i < NStr; i++) {
37  SIn.Load(Tmp);
38  IAssert(Tmp <= uint64(TSizeMx));
39  IdOffV.Add(TSize(Tmp));
40  }
41 }
#define IAssert(Cond)
Definition: bd.h:262
TVec< TSize > IdOffV
Definition: hash.h:663
uint GrowBy
Definition: hash.h:661
TSize MxBfL
Definition: hash.h:660
void LoadCs()
Definition: fl.cpp:28
unsigned long long uint64
Definition: bd.h:38
void Load(bool &Bool)
Definition: fl.h:84
#define TSizeMx
Definition: bd.h:59
size_t TSize
Definition: bd.h:58
void LoadBf(const void *Bf, const TSize &BfL)
Definition: fl.h:81
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
TSize BfL
Definition: hash.h:660
char * Bf
Definition: hash.h:662
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
TBigStrPool::TBigStrPool ( const TBigStrPool Pool)
inline

Definition at line 669 of file hash.h.

669  : MxBfL(Pool.MxBfL), BfL(Pool.BfL), GrowBy(Pool.GrowBy) {
670  Bf = (char *) malloc(Pool.MxBfL); IAssert(Bf); memcpy(Bf, Pool.Bf, Pool.BfL); }
#define IAssert(Cond)
Definition: bd.h:262
uint GrowBy
Definition: hash.h:661
TSize MxBfL
Definition: hash.h:660
TSize BfL
Definition: hash.h:660
char * Bf
Definition: hash.h:662
TBigStrPool::~TBigStrPool ( )
inline

Definition at line 671 of file hash.h.

671 { if (Bf) free(Bf); else IAssert(MxBfL == 0); MxBfL = 0; BfL = 0; }
#define IAssert(Cond)
Definition: bd.h:262
TSize MxBfL
Definition: hash.h:660
TSize BfL
Definition: hash.h:660
char * Bf
Definition: hash.h:662

Member Function Documentation

int TBigStrPool::AddStr ( const char *  Str,
uint  Len 
)

Definition at line 63 of file hash.cpp.

63  {
64  IAssertR(Len > 0, "String too short (lenght includes the null character)"); //J: if (! Len) return -1;
65  Assert(Str); Assert(Len > 0);
66  if (Len == 1 && IdOffV.Len() > 0) { return 0; } // empty string
67  if (BfL + Len > MxBfL) { Resize(BfL + Len); }
68  memcpy(Bf + BfL, Str, Len);
69  TSize Pos = BfL; BfL += Len;
70  IdOffV.Add(Pos);
71  return IdOffV.Len()-1;
72 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TVec< TSize > IdOffV
Definition: hash.h:663
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TSize Len() const
Definition: hash.h:681
TSize MxBfL
Definition: hash.h:660
size_t TSize
Definition: bd.h:58
#define Assert(Cond)
Definition: bd.h:251
TSize BfL
Definition: hash.h:660
char * Bf
Definition: hash.h:662
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
void Resize(TSize _MxBfL)
Definition: hash.cpp:3
int TBigStrPool::AddStr ( const char *  Str)
inline

Definition at line 688 of file hash.h.

688 { return AddStr(Str, uint(strlen(Str)) + 1); }
unsigned int uint
Definition: bd.h:11
int AddStr(const char *Str, uint Len)
Definition: hash.cpp:63
int TBigStrPool::AddStr ( const TStr Str)
inline

Definition at line 689 of file hash.h.

689 { return AddStr(Str.CStr(), Str.Len() + 1); }
int Len() const
Definition: dt.h:487
int AddStr(const char *Str, uint Len)
Definition: hash.cpp:63
char * CStr()
Definition: dt.h:476
void TBigStrPool::Clr ( bool  DoDel = false)
inline

Definition at line 701 of file hash.h.

701 { BfL = 0; if (DoDel && Bf) { free(Bf); Bf = 0; MxBfL = 0; } }
TSize MxBfL
Definition: hash.h:660
TSize BfL
Definition: hash.h:660
char * Bf
Definition: hash.h:662
int TBigStrPool::Cmp ( const int &  StrId,
const char *  Str 
) const
inline

Definition at line 702 of file hash.h.

702  { Assert(StrId < GetStrs());
703  if (StrId != 0) return strcmp(Bf + (TSize)IdOffV[StrId], Str); else return strcmp("", Str); }
TVec< TSize > IdOffV
Definition: hash.h:663
size_t TSize
Definition: bd.h:58
#define Assert(Cond)
Definition: bd.h:251
char * Bf
Definition: hash.h:662
int GetStrs() const
Definition: hash.h:680
bool TBigStrPool::Empty ( ) const
inline

Definition at line 683 of file hash.h.

683 { return ! Len(); }
TSize Len() const
Definition: hash.h:681
const char* TBigStrPool::GetCStr ( const int &  StrId) const
inline

Definition at line 693 of file hash.h.

693  { Assert(StrId < GetStrs());
694  if (StrId == 0) return TStr::GetNullStr().CStr(); else return (Bf + (TSize)IdOffV[StrId]); }
TVec< TSize > IdOffV
Definition: hash.h:663
size_t TSize
Definition: bd.h:58
#define Assert(Cond)
Definition: bd.h:251
static TStr GetNullStr()
Definition: dt.cpp:1626
char * CStr()
Definition: dt.h:476
char * Bf
Definition: hash.h:662
int GetStrs() const
Definition: hash.h:680
const char* TBigStrPool::GetCStrFromOffset ( const TSize Offset) const
inline

Definition at line 698 of file hash.h.

698  { Assert(Offset < BfL);
699  if (Offset == 0) return TStr::GetNullStr().CStr(); else return Bf + Offset; }
#define Assert(Cond)
Definition: bd.h:251
static TStr GetNullStr()
Definition: dt.cpp:1626
char * CStr()
Definition: dt.h:476
TSize BfL
Definition: hash.h:660
char * Bf
Definition: hash.h:662
int TBigStrPool::GetPrimHashCd ( const char *  CStr)
static

Definition at line 74 of file hash.cpp.

74  {
75  return TStrHashF_DJB::GetPrimHashCd(CStr);
76 }
static int GetPrimHashCd(const char *p)
Definition: hash.h:1155
int TBigStrPool::GetPrimHashCd ( const int &  StrId)
inline

Definition at line 707 of file hash.h.

707  { Assert(StrId < GetStrs());
708  if (StrId != 0) return GetPrimHashCd(Bf + (TSize)IdOffV[StrId]); else return GetPrimHashCd(""); }
TVec< TSize > IdOffV
Definition: hash.h:663
size_t TSize
Definition: bd.h:58
#define Assert(Cond)
Definition: bd.h:251
static int GetPrimHashCd(const char *CStr)
Definition: hash.cpp:74
char * Bf
Definition: hash.h:662
int GetStrs() const
Definition: hash.h:680
int TBigStrPool::GetSecHashCd ( const char *  CStr)
static

Definition at line 78 of file hash.cpp.

78  {
79  return TStrHashF_DJB::GetSecHashCd(CStr);
80 }
static int GetSecHashCd(const char *p)
Definition: hash.h:1158
int TBigStrPool::GetSecHashCd ( const int &  StrId)
inline

Definition at line 709 of file hash.h.

709  { Assert(StrId < GetStrs());
710  if (StrId != 0) return GetSecHashCd(Bf + (TSize)IdOffV[StrId]); else return GetSecHashCd(""); }
TVec< TSize > IdOffV
Definition: hash.h:663
size_t TSize
Definition: bd.h:58
#define Assert(Cond)
Definition: bd.h:251
static int GetSecHashCd(const char *CStr)
Definition: hash.cpp:78
char * Bf
Definition: hash.h:662
int GetStrs() const
Definition: hash.h:680
TStr TBigStrPool::GetStr ( const int &  StrId) const
inline

Definition at line 691 of file hash.h.

691  { Assert(StrId < GetStrs());
692  if (StrId == 0) return TStr::GetNullStr(); else return TStr(Bf + (TSize)IdOffV[StrId]); }
TVec< TSize > IdOffV
Definition: hash.h:663
size_t TSize
Definition: bd.h:58
#define Assert(Cond)
Definition: bd.h:251
static TStr GetNullStr()
Definition: dt.cpp:1626
Definition: dt.h:412
char * Bf
Definition: hash.h:662
int GetStrs() const
Definition: hash.h:680
TStr TBigStrPool::GetStrFromOffset ( const TSize Offset) const
inline

Definition at line 696 of file hash.h.

696  { Assert(Offset < BfL);
697  if (Offset == 0) return TStr::GetNullStr(); else return TStr(Bf + Offset); }
#define Assert(Cond)
Definition: bd.h:251
static TStr GetNullStr()
Definition: dt.cpp:1626
Definition: dt.h:412
TSize BfL
Definition: hash.h:660
char * Bf
Definition: hash.h:662
int TBigStrPool::GetStrs ( ) const
inline

Definition at line 680 of file hash.h.

680 { return IdOffV.Len(); }
TVec< TSize > IdOffV
Definition: hash.h:663
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TSize TBigStrPool::Len ( ) const
inline

Definition at line 681 of file hash.h.

681 { return BfL; }
TSize BfL
Definition: hash.h:660
static PBigStrPool TBigStrPool::Load ( TSIn SIn,
bool  LoadCompacted = true 
)
inlinestatic

Definition at line 676 of file hash.h.

676 { return PBigStrPool(new TBigStrPool(SIn, LoadCompacted)); }
TBigStrPool(TSize MxBfLen=0, uint _GrowBy=16 *1024 *1024)
Definition: hash.cpp:18
TPt< TBigStrPool > PBigStrPool
Definition: hash.h:658
static PBigStrPool TBigStrPool::New ( TSize  _MxBfLen = 0,
uint  _GrowBy = 16*1024*1024 
)
inlinestatic

Definition at line 673 of file hash.h.

673 { return PBigStrPool(new TBigStrPool(_MxBfLen, _GrowBy)); }
TBigStrPool(TSize MxBfLen=0, uint _GrowBy=16 *1024 *1024)
Definition: hash.cpp:18
TPt< TBigStrPool > PBigStrPool
Definition: hash.h:658
static PBigStrPool TBigStrPool::New ( TSIn SIn)
inlinestatic

Definition at line 674 of file hash.h.

674 { return new TBigStrPool(SIn); }
TBigStrPool(TSize MxBfLen=0, uint _GrowBy=16 *1024 *1024)
Definition: hash.cpp:18
static PBigStrPool TBigStrPool::New ( const TStr fileName)
inlinestatic

Definition at line 675 of file hash.h.

675 { PSIn SIn = TFIn::New(fileName); return new TBigStrPool(*SIn); }
TBigStrPool(TSize MxBfLen=0, uint _GrowBy=16 *1024 *1024)
Definition: hash.cpp:18
static PSIn New(const TStr &FNm)
Definition: fl.cpp:290
Definition: bd.h:196
char* TBigStrPool::operator() ( ) const
inline

Definition at line 684 of file hash.h.

684 { return Bf; }
char * Bf
Definition: hash.h:662
TBigStrPool & TBigStrPool::operator= ( const TBigStrPool Pool)

Definition at line 53 of file hash.cpp.

53  {
54  if (this != &Pool) {
55  GrowBy = Pool.GrowBy; MxBfL = Pool.MxBfL; BfL = Pool.BfL;
56  if (Bf) free(Bf); else IAssert(MxBfL == 0);
57  Bf = (char *) malloc(MxBfL); IAssert(Bf); memcpy(Bf, Pool.Bf, BfL);
58  }
59  return *this;
60 }
#define IAssert(Cond)
Definition: bd.h:262
uint GrowBy
Definition: hash.h:661
TSize MxBfL
Definition: hash.h:660
TSize BfL
Definition: hash.h:660
char * Bf
Definition: hash.h:662
void TBigStrPool::Resize ( TSize  _MxBfL)
private

Definition at line 3 of file hash.cpp.

3  {
4  TSize newSize = MxBfL;
5  while (newSize < _MxBfL) {
6  if (newSize >= GrowBy && GrowBy > 0) newSize += GrowBy;
7  else if (newSize > 0) newSize *= 2;
8  else newSize = TInt::GetMn(GrowBy, 1024);
9  }
10  if (newSize > MxBfL) {
11  Bf = (char *) realloc(Bf, newSize);
12  IAssertR(Bf, TStr::Fmt("old Bf size: %u, new size: %u", MxBfL, newSize).CStr());
13  MxBfL = newSize;
14  }
15  IAssert(MxBfL >= _MxBfL);
16 }
#define IAssert(Cond)
Definition: bd.h:262
#define IAssertR(Cond, Reason)
Definition: bd.h:265
uint GrowBy
Definition: hash.h:661
TSize MxBfL
Definition: hash.h:660
static int GetMn(const int &Int1, const int &Int2)
Definition: dt.h:1088
size_t TSize
Definition: bd.h:58
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * Bf
Definition: hash.h:662
void TBigStrPool::Save ( TSOut SOut) const

Definition at line 43 of file hash.cpp.

43  {
44  SOut.Save(uint64(MxBfL)); SOut.Save(uint64(BfL)); SOut.Save(GrowBy);
45  if (BfL > 0) { SOut.SaveBf(Bf, BfL); }
46  SOut.SaveCs();
47  SOut.Save(IdOffV.Len());
48  for (int i = 0; i < IdOffV.Len(); i++) {
49  SOut.Save(uint64(IdOffV[i]));
50  }
51 }
TVec< TSize > IdOffV
Definition: hash.h:663
uint GrowBy
Definition: hash.h:661
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TSize MxBfL
Definition: hash.h:660
void SaveCs()
Definition: fl.h:171
unsigned long long uint64
Definition: bd.h:38
void SaveBf(const void *Bf, const TSize &BfL)
Definition: fl.h:172
void Save(const bool &Bool)
Definition: fl.h:173
TSize BfL
Definition: hash.h:660
char * Bf
Definition: hash.h:662
void TBigStrPool::Save ( const TStr fileName)
inline

Definition at line 678 of file hash.h.

678 { TFOut FOut(fileName); Save(FOut); }
Definition: fl.h:319
void Save(TSOut &SOut) const
Definition: hash.cpp:43
TSize TBigStrPool::Size ( ) const
inline

Definition at line 682 of file hash.h.

682 { return MxBfL; }
TSize MxBfL
Definition: hash.h:660

Friends And Related Function Documentation

friend class TPt< TBigStrPool >
friend

Definition at line 658 of file hash.h.

Member Data Documentation

char* TBigStrPool::Bf
private

Definition at line 662 of file hash.h.

TSize TBigStrPool::BfL
private

Definition at line 660 of file hash.h.

TCRef TBigStrPool::CRef
private

Definition at line 658 of file hash.h.

uint TBigStrPool::GrowBy
private

Definition at line 661 of file hash.h.

TVec<TSize> TBigStrPool::IdOffV
private

Definition at line 663 of file hash.h.

TSize TBigStrPool::MxBfL
private

Definition at line 660 of file hash.h.


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