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
TVecPool< TVal, TSizeTy > Class Template Reference

Vector Pool. More...

#include <ds.h>

Public Types

typedef TPt< TVecPool< TVal,
TSizeTy > > 
PVecPool
 
typedef TVec< TVal, TSizeTy > TValV
 

Public Member Functions

 TVecPool (const TSize &ExpectVals=0, const TSize &_GrowBy=1000000, const bool &_FastCopy=false, const TVal &_EmptyVal=TVal())
 Vector pool constructor. More...
 
 TVecPool (const TVecPool< TVal, TSizeTy > &Pool)
 
 TVecPool (TSIn &SIn)
 
 ~TVecPool ()
 
void Save (TSOut &SOut) const
 
TVecPooloperator= (const TVecPool &Pool)
 
int GetVecs () const
 Returns the total number of vectors stored in the vector pool. More...
 
TSize GetVals () const
 Returns the total number of values stored in the vector pool. More...
 
bool IsVId (const int &VId) const
 Tests whether vector of id VId is in the pool. More...
 
uint64 Reserved () const
 Returns the total capacity of the pool. More...
 
void Reserve (const TSize &MxVals)
 Reserves enough capacity for the pool to store MxVals elements. More...
 
const TVal & GetEmptyVal () const
 Returns the reference to an empty value. More...
 
void SetEmptyVal (const TVal &_EmptyVal)
 Sets the empty value. More...
 
uint64 GetMemUsed () const
 Returns the total memory footprint (in bytes) of the pool. More...
 
int AddV (const TValV &ValV)
 Adds vector ValV to the pool and returns its id. More...
 
int AddEmptyV (const int &ValVLen)
 Adds a vector of length ValVLen to the pool and returns its id. More...
 
int GetVLen (const int &VId) const
 Returns the number of elements in the vector with id VId. More...
 
TVal * GetValVPt (const int &VId) const
 Returns pointer to the first element of the vector with id VId. More...
 
void GetV (const int &VId, TValV &ValV) const
 Returns ValV which is a reference (not a copy) to vector with id VId. More...
 
void PutV (const int &VId, const TValV &ValV)
 Sets the values of vector VId with those in ValV. More...
 
void CompactPool (const TVal &DelVal)
 Deletes all elements of value DelVal from all vectors. More...
 
void ShuffleAll (TRnd &Rnd=TInt::Rnd)
 Shuffles the order of all elements in the pool. More...
 
void Clr (bool DoDel=true)
 Clears the contents of the pool. More...
 
void PutAll (const TVal &Val)
 Sets the values of all elements in the pool to Val. More...
 

Static Public Member Functions

static PVecPool New (const TSize &ExpectVals=0, const TSize &GrowBy=1000000, const bool &FastCopy=false)
 
static PVecPool Load (TSIn &SIn)
 
static PVecPool Load (const TStr &FNm)
 

Private Member Functions

void Resize (const TSize &_MxVals)
 

Private Attributes

TCRef CRef
 
TBool FastCopy
 
TSize GrowBy
 
TSize MxVals
 
TSize Vals
 
TVal EmptyVal
 
TVal * ValBf
 
TVec< uint64, int > IdToOffV
 

Friends

class TPt< TVecPool< TVal > >
 

Detailed Description

template<class TVal, class TSizeTy = int>
class TVecPool< TVal, TSizeTy >

Vector Pool.

Used for storing a large number of small vectors. The pool can store up to 2G different vectors, each with up to 2G elements. Each vector in the pool gets a consecutive integer ID. IDs range 0...GetVecs(). Once a vector is added to the pool, the vector can modify the values of its elements (e.g., be sorted), but the vector is not allowed to change its length — it cannot grow or shrink.

Definition at line 1559 of file ds.h.

Member Typedef Documentation

template<class TVal, class TSizeTy = int>
typedef TPt<TVecPool<TVal, TSizeTy> > TVecPool< TVal, TSizeTy >::PVecPool

Definition at line 1561 of file ds.h.

template<class TVal, class TSizeTy = int>
typedef TVec<TVal, TSizeTy> TVecPool< TVal, TSizeTy >::TValV

Definition at line 1562 of file ds.h.

Constructor & Destructor Documentation

template<class TVal, class TSizeTy >
TVecPool< TVal, TSizeTy >::TVecPool ( const TSize ExpectVals = 0,
const TSize _GrowBy = 1000000,
const bool &  _FastCopy = false,
const TVal &  _EmptyVal = TVal() 
)

Vector pool constructor.

Parameters
ExpectValsAt creation the pool allocates enough memory for storing the total of ExpectVals elements (not vectors).
_GrowByWhenever the size of the pool needs to be expanded, it will be expanded to be able to store additional _GrowBy elements.
_FastCopyIf true, then vectors are copied using memcpy(), otherwise the assignment operator is used for copying. This option is slower but useful for complex objects where assignment operator is non-trivial.
_EmptyValEmpty (not yet used) elements in the pool are assigned to this value. By default _EmptyVal = TVal().

Definition at line 1685 of file ds.h.

1685  : GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
1686  IdToOffV.Add(0);
1687  Resize(ExpectVals);
1688 }
TVal * ValBf
Definition: ds.h:1568
void Resize(const TSize &_MxVals)
Definition: ds.h:1657
TSize GrowBy
Definition: ds.h:1566
TVal EmptyVal
Definition: ds.h:1567
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
TSize Vals
Definition: ds.h:1566
TSize MxVals
Definition: ds.h:1566
template<class TVal, class TSizeTy >
TVecPool< TVal, TSizeTy >::TVecPool ( const TVecPool< TVal, TSizeTy > &  Pool)

Definition at line 1691 of file ds.h.

1691  : FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy), MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
1692  try {
1693  ValBf = new TVal [MxVals]; }
1694  catch (std::exception Ex) {
1695  FailR(TStr::Fmt("TVecPool::TVecPool: %s, MxVals: %s. [Program failed to allocate memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), TInt::GetStr(uint64(MxVals)).CStr()).CStr()); }
1696  IAssert(ValBf != NULL);
1697  if (FastCopy) {
1698  memcpy(ValBf, Pool.ValBf, MxVals*sizeof(TVal)); }
1699  else {
1700  for (TSize ValN = 0; ValN < MxVals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
1701 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1105
TVal * ValBf
Definition: ds.h:1568
TSize GrowBy
Definition: ds.h:1566
TVal EmptyVal
Definition: ds.h:1567
unsigned long long uint64
Definition: bd.h:38
size_t TSize
Definition: bd.h:58
#define FailR(Reason)
Definition: bd.h:240
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TBool FastCopy
Definition: ds.h:1565
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
char * CStr()
Definition: dt.h:476
TSize Vals
Definition: ds.h:1566
TSize MxVals
Definition: ds.h:1566
template<class TVal, class TSizeTy >
TVecPool< TVal, TSizeTy >::TVecPool ( TSIn SIn)

Definition at line 1704 of file ds.h.

1704  : FastCopy(SIn) {
1705  uint64 _GrowBy, _MxVals, _Vals;
1706  SIn.Load(_GrowBy); SIn.Load(_MxVals); SIn.Load(_Vals);
1707  IAssertR(_GrowBy<TSizeMx && _MxVals<TSizeMx && _Vals<TSizeMx, "This is a 64-bit vector pool. Use a 64-bit compiler.");
1708  GrowBy=TSize(_GrowBy); MxVals=TSize(_Vals); Vals=TSize(_Vals); //note MxVals==Vals
1709  EmptyVal = TVal(SIn);
1710  if (MxVals==0) { ValBf = NULL; } else { ValBf = new TVal [MxVals]; }
1711  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN] = TVal(SIn); }
1712  { TInt MxVals(SIn), Vals(SIn);
1713  IdToOffV.Gen(Vals);
1714  for (int ValN = 0; ValN < Vals; ValN++) {
1715  uint64 Offset; SIn.Load(Offset); IAssert(Offset < TSizeMx);
1716  IdToOffV[ValN]=TSize(Offset);
1717  } }
1718 }
#define IAssert(Cond)
Definition: bd.h:262
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TVal * ValBf
Definition: ds.h:1568
TSize GrowBy
Definition: ds.h:1566
TVal EmptyVal
Definition: ds.h:1567
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
Definition: dt.h:1042
TBool FastCopy
Definition: ds.h:1565
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
TSize Vals
Definition: ds.h:1566
TSize MxVals
Definition: ds.h:1566
template<class TVal, class TSizeTy = int>
TVecPool< TVal, TSizeTy >::~TVecPool ( )
inline

Definition at line 1582 of file ds.h.

1582 { if (ValBf != NULL) { delete [] ValBf; } ValBf=NULL; }
TVal * ValBf
Definition: ds.h:1568

Member Function Documentation

template<class TVal , class TSizeTy >
int TVecPool< TVal, TSizeTy >::AddEmptyV ( const int &  ValVLen)

Adds a vector of length ValVLen to the pool and returns its id.

Elements of the vector are initialized to EmptyVal.

Definition at line 1767 of file ds.h.

1767  {
1768  if (ValVLen==0){return 0;}
1769  if (MxVals < Vals+ValVLen){Resize(Vals+max(TSize(ValVLen), GrowBy)); }
1770  Vals+=ValVLen; IdToOffV.Add(Vals);
1771  return IdToOffV.Len()-1;
1772 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
void Resize(const TSize &_MxVals)
Definition: ds.h:1657
TSize GrowBy
Definition: ds.h:1566
size_t TSize
Definition: bd.h:58
#define max(a, b)
Definition: bd.h:350
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
TSize Vals
Definition: ds.h:1566
TSize MxVals
Definition: ds.h:1566
template<class TVal , class TSizeTy >
int TVecPool< TVal, TSizeTy >::AddV ( const TValV ValV)

Adds vector ValV to the pool and returns its id.

Definition at line 1756 of file ds.h.

1756  {
1757  const TSizeTy ValVLen = ValV.Len();
1758  if (ValVLen == 0) { return 0; }
1759  if (MxVals < Vals+ValVLen) { Resize(Vals+max(ValVLen, GrowBy)); }
1760  if (FastCopy) { memcpy(ValBf+Vals, ValV.BegI(), sizeof(TVal)*ValV.Len()); }
1761  else { for (uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
1762  Vals+=ValVLen; IdToOffV.Add(Vals);
1763  return IdToOffV.Len()-1;
1764 }
unsigned int uint
Definition: bd.h:11
TVal * ValBf
Definition: ds.h:1568
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
void Resize(const TSize &_MxVals)
Definition: ds.h:1657
TSize GrowBy
Definition: ds.h:1566
#define max(a, b)
Definition: bd.h:350
TBool FastCopy
Definition: ds.h:1565
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
TSize Vals
Definition: ds.h:1566
TSize MxVals
Definition: ds.h:1566
template<class TVal, class TSizeTy = int>
void TVecPool< TVal, TSizeTy >::Clr ( bool  DoDel = true)
inline

Clears the contents of the pool.

If DoDel=true memory is freed, otherwise all vectors are deleted and all element values in the pool are set to EmptyVal.

Definition at line 1646 of file ds.h.

1646  {
1647  IdToOffV.Clr(DoDel); MxVals=0; Vals=0;
1648  if (DoDel && ValBf!=NULL) { delete [] ValBf; ValBf=NULL;}
1649  if (! DoDel) { PutAll(EmptyVal); } }
TVal * ValBf
Definition: ds.h:1568
TVal EmptyVal
Definition: ds.h:1567
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:953
void PutAll(const TVal &Val)
Sets the values of all elements in the pool to Val.
Definition: ds.h:1651
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
TSize Vals
Definition: ds.h:1566
TSize MxVals
Definition: ds.h:1566
template<class TVal, class TSizeTy >
void TVecPool< TVal, TSizeTy >::CompactPool ( const TVal &  DelVal)

Deletes all elements of value DelVal from all vectors.

Empty space is left at the end of the pool.

Definition at line 1776 of file ds.h.

1776  {
1777  ::TSize TotalDel=0, NDel=0;
1778  // printf("Compacting %d vectors\n", IdToOffV.Len());
1779  for (int vid = 1; vid < IdToOffV.Len(); vid++) {
1780  // if (vid % 10000000 == 0) { printf(" %dm", vid/1000000); fflush(stdout); }
1781  const uint Len = GetVLen(vid);
1782  TVal* ValV = GetValVPt(vid);
1783  if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; } // update end of vector
1784  if (Len == 0) { continue; }
1785  NDel = 0;
1786  for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
1787  if (*v == DelVal) {
1788  TVal* Beg = v;
1789  while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
1790  memcpy(Beg, v, sizeof(TVal)*int(Len - ::TSize(v - ValV)));
1791  v -= NDel;
1792  }
1793  }
1794  memcpy(ValV-TotalDel, ValV, sizeof(TVal)*Len); // move data
1795  TotalDel += NDel;
1796  }
1797  IdToOffV.Last() -= TotalDel;
1798  for (::TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
1799  Vals -= TotalDel;
1800  // printf(" deleted %llu elements from the pool\n", TotalDel);
1801 }
unsigned int uint
Definition: bd.h:11
TVal * ValBf
Definition: ds.h:1568
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TVal EmptyVal
Definition: ds.h:1567
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
Definition: ds.h:1617
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1615
size_t TSize
Definition: bd.h:58
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:539
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
TSize Vals
Definition: ds.h:1566
template<class TVal, class TSizeTy = int>
const TVal& TVecPool< TVal, TSizeTy >::GetEmptyVal ( ) const
inline

Returns the reference to an empty value.

Definition at line 1601 of file ds.h.

1601 { return EmptyVal; }
TVal EmptyVal
Definition: ds.h:1567
template<class TVal, class TSizeTy = int>
uint64 TVecPool< TVal, TSizeTy >::GetMemUsed ( ) const
inline

Returns the total memory footprint (in bytes) of the pool.

Definition at line 1605 of file ds.h.

1605  {
1606  return sizeof(TCRef)+sizeof(TBool)+3*sizeof(TSize)+sizeof(TVal*)+MxVals*sizeof(TVal);}
Definition: bd.h:440
size_t TSize
Definition: bd.h:58
Definition: dt.h:881
TSize MxVals
Definition: ds.h:1566
template<class TVal, class TSizeTy = int>
void TVecPool< TVal, TSizeTy >::GetV ( const int &  VId,
TValV ValV 
) const
inline

Returns ValV which is a reference (not a copy) to vector with id VId.

No data is copied. Elements of the vector ValV can be modified but the vector cannot change its size.

Definition at line 1623 of file ds.h.

1623  {
1624  if (GetVLen(VId)==0){ValV.Clr();}
1625  else { ValV.GenExt(GetValVPt(VId), GetVLen(VId)); } }
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
Definition: ds.h:1617
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1615
template<class TVal, class TSizeTy = int>
TSize TVecPool< TVal, TSizeTy >::GetVals ( ) const
inline

Returns the total number of values stored in the vector pool.

Definition at line 1593 of file ds.h.

1593 { return Vals; }
TSize Vals
Definition: ds.h:1566
template<class TVal, class TSizeTy = int>
TVal* TVecPool< TVal, TSizeTy >::GetValVPt ( const int &  VId) const
inline

Returns pointer to the first element of the vector with id VId.

Definition at line 1617 of file ds.h.

1617  {
1618  if (GetVLen(VId)==0){return (TVal*)&EmptyVal;}
1619  else {return ValBf+IdToOffV[VId-1];}}
TVal * ValBf
Definition: ds.h:1568
TVal EmptyVal
Definition: ds.h:1567
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1615
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
template<class TVal, class TSizeTy = int>
int TVecPool< TVal, TSizeTy >::GetVecs ( ) const
inline

Returns the total number of vectors stored in the vector pool.

Definition at line 1591 of file ds.h.

1591 { return IdToOffV.Len(); }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
template<class TVal, class TSizeTy = int>
int TVecPool< TVal, TSizeTy >::GetVLen ( const int &  VId) const
inline

Returns the number of elements in the vector with id VId.

Definition at line 1615 of file ds.h.

1615 { if (VId==0){return 0;} else {return int(IdToOffV[VId]-IdToOffV[VId-1]);}}
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
template<class TVal, class TSizeTy = int>
bool TVecPool< TVal, TSizeTy >::IsVId ( const int &  VId) const
inline

Tests whether vector of id VId is in the pool.

Definition at line 1595 of file ds.h.

1595 { return (0 <= VId) && (VId < IdToOffV.Len()); }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
template<class TVal, class TSizeTy = int>
static PVecPool TVecPool< TVal, TSizeTy >::Load ( TSIn SIn)
inlinestatic

Definition at line 1585 of file ds.h.

1585 { return new TVecPool(SIn); }
TVecPool(const TSize &ExpectVals=0, const TSize &_GrowBy=1000000, const bool &_FastCopy=false, const TVal &_EmptyVal=TVal())
Vector pool constructor.
Definition: ds.h:1685
template<class TVal, class TSizeTy = int>
static PVecPool TVecPool< TVal, TSizeTy >::Load ( const TStr FNm)
inlinestatic

Definition at line 1586 of file ds.h.

1586 { TFIn FIn(FNm); return Load(FIn); }
Definition: fl.h:275
static PVecPool Load(TSIn &SIn)
Definition: ds.h:1585
template<class TVal, class TSizeTy = int>
static PVecPool TVecPool< TVal, TSizeTy >::New ( const TSize ExpectVals = 0,
const TSize GrowBy = 1000000,
const bool &  FastCopy = false 
)
inlinestatic

Definition at line 1583 of file ds.h.

1583  {
1584  return new TVecPool(ExpectVals, GrowBy, FastCopy); }
TSize GrowBy
Definition: ds.h:1566
TBool FastCopy
Definition: ds.h:1565
TVecPool(const TSize &ExpectVals=0, const TSize &_GrowBy=1000000, const bool &_FastCopy=false, const TVal &_EmptyVal=TVal())
Vector pool constructor.
Definition: ds.h:1685
template<class TVal , class TSizeTy >
TVecPool< TVal, TSizeTy > & TVecPool< TVal, TSizeTy >::operator= ( const TVecPool< TVal, TSizeTy > &  Pool)

Definition at line 1734 of file ds.h.

1734  {
1735  if (this!=&Pool) {
1736  FastCopy = Pool.FastCopy;
1737  GrowBy = Pool.GrowBy;
1738  MxVals = Pool.MxVals;
1739  Vals = Pool.Vals;
1740  EmptyVal = Pool.EmptyVal;
1741  IdToOffV=Pool.IdToOffV;
1742  try {
1743  ValBf = new TVal [MxVals]; }
1744  catch (std::exception Ex) {
1745  FailR(TStr::Fmt("TVecPool::operator=: %s, MxVals: %s. [Program failed to allocate memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), TInt::GetStr(uint64(MxVals)).CStr()).CStr()); }
1746  IAssert(ValBf != NULL);
1747  if (FastCopy) {
1748  memcpy(ValBf, Pool.ValBf, Vals*sizeof(TVal)); }
1749  else {
1750  for (TSize ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
1751  }
1752  return *this;
1753 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1105
TVal * ValBf
Definition: ds.h:1568
TSize GrowBy
Definition: ds.h:1566
TVal EmptyVal
Definition: ds.h:1567
unsigned long long uint64
Definition: bd.h:38
size_t TSize
Definition: bd.h:58
#define FailR(Reason)
Definition: bd.h:240
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TBool FastCopy
Definition: ds.h:1565
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
char * CStr()
Definition: dt.h:476
TSize Vals
Definition: ds.h:1566
TSize MxVals
Definition: ds.h:1566
template<class TVal, class TSizeTy = int>
void TVecPool< TVal, TSizeTy >::PutAll ( const TVal &  Val)
inline

Sets the values of all elements in the pool to Val.

Definition at line 1651 of file ds.h.

1651  {
1652  for (TSize ValN = 0; ValN < MxVals; ValN++) { ValBf[ValN]=Val; } }
TVal * ValBf
Definition: ds.h:1568
size_t TSize
Definition: bd.h:58
TSize MxVals
Definition: ds.h:1566
template<class TVal, class TSizeTy = int>
void TVecPool< TVal, TSizeTy >::PutV ( const int &  VId,
const TValV ValV 
)
inline

Sets the values of vector VId with those in ValV.

Definition at line 1627 of file ds.h.

1627  {
1628  IAssert(IsVId(VId) && GetVLen(VId) == ValV.Len());
1629  if (FastCopy) {
1630  memcpy(GetValVPt(VId), ValV.BegI(), sizeof(TVal)*ValV.Len()); }
1631  else { TVal* ValPt = GetValVPt(VId);
1632  for (::TSize ValN=0; ValN < ::TSize(ValV.Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
1633  } }
#define IAssert(Cond)
Definition: bd.h:262
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
Definition: ds.h:1617
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1615
size_t TSize
Definition: bd.h:58
TBool FastCopy
Definition: ds.h:1565
bool IsVId(const int &VId) const
Tests whether vector of id VId is in the pool.
Definition: ds.h:1595
template<class TVal, class TSizeTy = int>
void TVecPool< TVal, TSizeTy >::Reserve ( const TSize MxVals)
inline

Reserves enough capacity for the pool to store MxVals elements.

Definition at line 1599 of file ds.h.

1599 { Resize(MxVals); }
void Resize(const TSize &_MxVals)
Definition: ds.h:1657
TSize MxVals
Definition: ds.h:1566
template<class TVal, class TSizeTy = int>
uint64 TVecPool< TVal, TSizeTy >::Reserved ( ) const
inline

Returns the total capacity of the pool.

Definition at line 1597 of file ds.h.

1597 { return MxVals; }
TSize MxVals
Definition: ds.h:1566
template<class TVal , class TSizeTy >
void TVecPool< TVal, TSizeTy >::Resize ( const TSize _MxVals)
private

Definition at line 1657 of file ds.h.

1657  {
1658  if (_MxVals <= MxVals){ return; } else { MxVals = _MxVals; }
1659  if (ValBf == NULL) {
1660  try { ValBf = new TVal [MxVals]; }
1661  catch (std::exception Ex) {
1662  FailR(TStr::Fmt("TVecPool::Resize 1: %s, MxVals: %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), TInt::GetStr(uint64(_MxVals)).CStr()).CStr()); }
1663  IAssert(ValBf != NULL);
1664  if (EmptyVal != TVal()) { PutAll(EmptyVal); }
1665  } else {
1666  // printf("*** Resize vector pool: %llu -> %llu\n", uint64(Vals), uint64(MxVals));
1667  TVal* NewValBf = NULL;
1668  try { NewValBf = new TVal [MxVals]; }
1669  catch (std::exception Ex) {
1670  FailR(TStr::Fmt("TVecPool::Resize 1: %s, MxVals: %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), TInt::GetStr(uint64(_MxVals)).CStr()).CStr()); }
1671  IAssert(NewValBf != NULL);
1672  if (FastCopy) {
1673  memcpy(NewValBf, ValBf, Vals*sizeof(TVal)); }
1674  else {
1675  for (TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
1676  if (EmptyVal != TVal()) { // init empty values
1677  for (TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
1678  }
1679  delete [] ValBf;
1680  ValBf = NewValBf;
1681  }
1682 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1105
TVal * ValBf
Definition: ds.h:1568
TVal EmptyVal
Definition: ds.h:1567
unsigned long long uint64
Definition: bd.h:38
size_t TSize
Definition: bd.h:58
void PutAll(const TVal &Val)
Sets the values of all elements in the pool to Val.
Definition: ds.h:1651
#define FailR(Reason)
Definition: bd.h:240
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TBool FastCopy
Definition: ds.h:1565
char * CStr()
Definition: dt.h:476
TSize Vals
Definition: ds.h:1566
TSize MxVals
Definition: ds.h:1566
template<class TVal , class TSizeTy >
void TVecPool< TVal, TSizeTy >::Save ( TSOut SOut) const

Definition at line 1721 of file ds.h.

1721  {
1722  SOut.Save(FastCopy);
1723  uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
1724  SOut.Save(_GrowBy); SOut.Save(_MxVals); SOut.Save(_Vals);
1725  SOut.Save(EmptyVal);
1726  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
1727  { SOut.Save(IdToOffV.Len()); SOut.Save(IdToOffV.Len());
1728  for (int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
1729  const uint64 Offset=IdToOffV[ValN]; SOut.Save(Offset);
1730  } }
1731 }
TVal * ValBf
Definition: ds.h:1568
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TSize GrowBy
Definition: ds.h:1566
TVal EmptyVal
Definition: ds.h:1567
unsigned long long uint64
Definition: bd.h:38
size_t TSize
Definition: bd.h:58
void Save(const bool &Bool)
Definition: fl.h:173
TBool FastCopy
Definition: ds.h:1565
TVec< uint64, int > IdToOffV
Definition: ds.h:1569
TSize Vals
Definition: ds.h:1566
TSize MxVals
Definition: ds.h:1566
template<class TVal, class TSizeTy = int>
void TVecPool< TVal, TSizeTy >::SetEmptyVal ( const TVal &  _EmptyVal)
inline

Sets the empty value.

Definition at line 1603 of file ds.h.

1603 { EmptyVal = _EmptyVal; }
TVal EmptyVal
Definition: ds.h:1567
template<class TVal , class TSizeTy >
void TVecPool< TVal, TSizeTy >::ShuffleAll ( TRnd Rnd = TInt::Rnd)

Shuffles the order of all elements in the pool.

It does not respect vector boundaries!

Definition at line 1805 of file ds.h.

1805  {
1806  for (::TSize n = Vals-1; n > 0; n--) {
1807  const ::TSize k = ::TSize(((uint64(Rnd.GetUniDevInt())<<32) | uint64(Rnd.GetUniDevInt())) % (n+1));
1808  const TVal Tmp = ValBf[n];
1809  ValBf[n] = ValBf[k];
1810  ValBf[k] = Tmp;
1811  }
1812 }
TVal * ValBf
Definition: ds.h:1568
unsigned long long uint64
Definition: bd.h:38
size_t TSize
Definition: bd.h:58
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
TSize Vals
Definition: ds.h:1566

Friends And Related Function Documentation

template<class TVal, class TSizeTy = int>
friend class TPt< TVecPool< TVal > >
friend

Definition at line 1653 of file ds.h.

Member Data Documentation

template<class TVal, class TSizeTy = int>
TCRef TVecPool< TVal, TSizeTy >::CRef
private

Definition at line 1564 of file ds.h.

template<class TVal, class TSizeTy = int>
TVal TVecPool< TVal, TSizeTy >::EmptyVal
private

Definition at line 1567 of file ds.h.

template<class TVal, class TSizeTy = int>
TBool TVecPool< TVal, TSizeTy >::FastCopy
private

Definition at line 1565 of file ds.h.

template<class TVal, class TSizeTy = int>
TSize TVecPool< TVal, TSizeTy >::GrowBy
private

Definition at line 1566 of file ds.h.

template<class TVal, class TSizeTy = int>
TVec<uint64, int> TVecPool< TVal, TSizeTy >::IdToOffV
private

Definition at line 1569 of file ds.h.

template<class TVal, class TSizeTy = int>
TSize TVecPool< TVal, TSizeTy >::MxVals
private

Definition at line 1566 of file ds.h.

template<class TVal, class TSizeTy = int>
TVal* TVecPool< TVal, TSizeTy >::ValBf
private

Definition at line 1568 of file ds.h.

template<class TVal, class TSizeTy = int>
TSize TVecPool< TVal, TSizeTy >::Vals
private

Definition at line 1566 of file ds.h.


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