SNAP Library 3.0, User Reference  2016-07-20 17:56:49
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)
 
::TSize GetMemUsed ()
 
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 668 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:671
int AddStr(const char *Str, uint Len)
Definition: hash.cpp:63
TSize MxBfL
Definition: hash.h:670
TSize BfL
Definition: hash.h:670
char * Bf
Definition: hash.h:672
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:673
uint GrowBy
Definition: hash.h:671
TSize MxBfL
Definition: hash.h:670
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:495
TSize BfL
Definition: hash.h:670
char * Bf
Definition: hash.h:672
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
TBigStrPool::TBigStrPool ( const TBigStrPool Pool)
inline

Definition at line 679 of file hash.h.

679  : MxBfL(Pool.MxBfL), BfL(Pool.BfL), GrowBy(Pool.GrowBy) {
680  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:671
TSize MxBfL
Definition: hash.h:670
TSize BfL
Definition: hash.h:670
char * Bf
Definition: hash.h:672
TBigStrPool::~TBigStrPool ( )
inline

Definition at line 681 of file hash.h.

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

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:673
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TSize Len() const
Definition: hash.h:691
TSize MxBfL
Definition: hash.h:670
size_t TSize
Definition: bd.h:58
#define Assert(Cond)
Definition: bd.h:251
TSize BfL
Definition: hash.h:670
char * Bf
Definition: hash.h:672
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
void Resize(TSize _MxBfL)
Definition: hash.cpp:3
int TBigStrPool::AddStr ( const char *  Str)
inline

Definition at line 701 of file hash.h.

701 { 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 702 of file hash.h.

702 { 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 714 of file hash.h.

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

Definition at line 715 of file hash.h.

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

Definition at line 693 of file hash.h.

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

Definition at line 706 of file hash.h.

706  { Assert(StrId < GetStrs());
707  if (StrId == 0) return TStr::GetNullStr().CStr(); else return (Bf + (TSize)IdOffV[StrId]); }
TVec< TSize > IdOffV
Definition: hash.h:673
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:672
int GetStrs() const
Definition: hash.h:690
const char* TBigStrPool::GetCStrFromOffset ( const TSize Offset) const
inline

Definition at line 711 of file hash.h.

711  { Assert(Offset < BfL);
712  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:670
char * Bf
Definition: hash.h:672
::TSize TBigStrPool::GetMemUsed ( )
inline

Definition at line 696 of file hash.h.

696  {
697  return 4 * sizeof(int) + IdOffV.GetMemUsed() + MxBfL;
698  }
TVec< TSize > IdOffV
Definition: hash.h:673
TSize MxBfL
Definition: hash.h:670
TSizeTy GetMemUsed() const
Returns the memory footprint (the number of bytes) of the vector.
Definition: ds.h:483
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:1181
int TBigStrPool::GetPrimHashCd ( const int &  StrId)
inline

Definition at line 720 of file hash.h.

720  { Assert(StrId < GetStrs());
721  if (StrId != 0) return GetPrimHashCd(Bf + (TSize)IdOffV[StrId]); else return GetPrimHashCd(""); }
TVec< TSize > IdOffV
Definition: hash.h:673
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:672
int GetStrs() const
Definition: hash.h:690
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:1184
int TBigStrPool::GetSecHashCd ( const int &  StrId)
inline

Definition at line 722 of file hash.h.

722  { Assert(StrId < GetStrs());
723  if (StrId != 0) return GetSecHashCd(Bf + (TSize)IdOffV[StrId]); else return GetSecHashCd(""); }
TVec< TSize > IdOffV
Definition: hash.h:673
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:672
int GetStrs() const
Definition: hash.h:690
TStr TBigStrPool::GetStr ( const int &  StrId) const
inline

Definition at line 704 of file hash.h.

704  { Assert(StrId < GetStrs());
705  if (StrId == 0) return TStr::GetNullStr(); else return TStr(Bf + (TSize)IdOffV[StrId]); }
TVec< TSize > IdOffV
Definition: hash.h:673
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:672
int GetStrs() const
Definition: hash.h:690
TStr TBigStrPool::GetStrFromOffset ( const TSize Offset) const
inline

Definition at line 709 of file hash.h.

709  { Assert(Offset < BfL);
710  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:670
char * Bf
Definition: hash.h:672
int TBigStrPool::GetStrs ( ) const
inline

Definition at line 690 of file hash.h.

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

Definition at line 691 of file hash.h.

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

Definition at line 686 of file hash.h.

686 { 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:668
static PBigStrPool TBigStrPool::New ( TSize  _MxBfLen = 0,
uint  _GrowBy = 16*1024*1024 
)
inlinestatic

Definition at line 683 of file hash.h.

683 { 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:668
static PBigStrPool TBigStrPool::New ( TSIn SIn)
inlinestatic

Definition at line 684 of file hash.h.

684 { 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 685 of file hash.h.

685 { 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
char* TBigStrPool::operator() ( ) const
inline

Definition at line 694 of file hash.h.

694 { return Bf; }
char * Bf
Definition: hash.h:672
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:671
TSize MxBfL
Definition: hash.h:670
TSize BfL
Definition: hash.h:670
char * Bf
Definition: hash.h:672
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:671
TSize MxBfL
Definition: hash.h:670
static int GetMn(const int &Int1, const int &Int2)
Definition: dt.h:1090
size_t TSize
Definition: bd.h:58
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * Bf
Definition: hash.h:672
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:673
uint GrowBy
Definition: hash.h:671
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TSize MxBfL
Definition: hash.h:670
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:670
char * Bf
Definition: hash.h:672
void TBigStrPool::Save ( const TStr fileName)
inline

Definition at line 688 of file hash.h.

688 { 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 692 of file hash.h.

692 { return MxBfL; }
TSize MxBfL
Definition: hash.h:670

Friends And Related Function Documentation

friend class TPt< TBigStrPool >
friend

Definition at line 668 of file hash.h.

Member Data Documentation

char* TBigStrPool::Bf
private

Definition at line 672 of file hash.h.

TSize TBigStrPool::BfL
private

Definition at line 670 of file hash.h.

TCRef TBigStrPool::CRef
private

Definition at line 668 of file hash.h.

uint TBigStrPool::GrowBy
private

Definition at line 671 of file hash.h.

TVec<TSize> TBigStrPool::IdOffV
private

Definition at line 673 of file hash.h.

TSize TBigStrPool::MxBfL
private

Definition at line 670 of file hash.h.


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