SNAP Library 3.0, Developer 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
TVecPool< TVal, TSizeTy > Class Template Reference

Vector Pool. More...

#include <ds.h>

Collaboration diagram for TVecPool< TVal, TSizeTy >:

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 1607 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 1609 of file ds.h.

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

Definition at line 1610 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 1733 of file ds.h.

References TVec< TVal, TSizeTy >::Add(), TVecPool< TVal, TSizeTy >::IdToOffV, and TVecPool< TVal, TSizeTy >::Resize().

Referenced by TVecPool< TInt >::Load(), and TVecPool< TInt >::New().

1733  : GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
1734  IdToOffV.Add(0);
1735  Resize(ExpectVals);
1736 }
TVal * ValBf
Definition: ds.h:1616
void Resize(const TSize &_MxVals)
Definition: ds.h:1705
TSize GrowBy
Definition: ds.h:1614
TVal EmptyVal
Definition: ds.h:1615
TVec< uint64, int > IdToOffV
Definition: ds.h:1617
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
TSize Vals
Definition: ds.h:1614
TSize MxVals
Definition: ds.h:1614

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal, class TSizeTy >
TVecPool< TVal, TSizeTy >::TVecPool ( const TVecPool< TVal, TSizeTy > &  Pool)

Definition at line 1739 of file ds.h.

References TStr::CStr(), FailR, TVecPool< TVal, TSizeTy >::FastCopy, TStr::Fmt(), TInt::GetStr(), IAssert, TVecPool< TVal, TSizeTy >::MxVals, and TVecPool< TVal, TSizeTy >::ValBf.

1739  : FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy), MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
1740  try {
1741  ValBf = new TVal [MxVals]; }
1742  catch (std::exception Ex) {
1743  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()); }
1744  IAssert(ValBf != NULL);
1745  if (FastCopy) {
1746  memcpy(ValBf, Pool.ValBf, MxVals*sizeof(TVal)); }
1747  else {
1748  for (TSize ValN = 0; ValN < MxVals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
1749 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1107
TVal * ValBf
Definition: ds.h:1616
TSize GrowBy
Definition: ds.h:1614
TVal EmptyVal
Definition: ds.h:1615
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:1613
TVec< uint64, int > IdToOffV
Definition: ds.h:1617
char * CStr()
Definition: dt.h:476
TSize Vals
Definition: ds.h:1614
TSize MxVals
Definition: ds.h:1614

Here is the call graph for this function:

template<class TVal, class TSizeTy >
TVecPool< TVal, TSizeTy >::TVecPool ( TSIn SIn)

Definition at line 1752 of file ds.h.

References TVecPool< TVal, TSizeTy >::EmptyVal, TVec< TVal, TSizeTy >::Gen(), TVecPool< TVal, TSizeTy >::GrowBy, IAssert, IAssertR, TVecPool< TVal, TSizeTy >::IdToOffV, TSIn::Load(), TVecPool< TVal, TSizeTy >::MxVals, TSizeMx, TVecPool< TVal, TSizeTy >::ValBf, and TVecPool< TVal, TSizeTy >::Vals.

1752  : FastCopy(SIn) {
1753  uint64 _GrowBy, _MxVals, _Vals;
1754  SIn.Load(_GrowBy); SIn.Load(_MxVals); SIn.Load(_Vals);
1755  IAssertR(_GrowBy<TSizeMx && _MxVals<TSizeMx && _Vals<TSizeMx, "This is a 64-bit vector pool. Use a 64-bit compiler.");
1756  GrowBy=TSize(_GrowBy); MxVals=TSize(_Vals); Vals=TSize(_Vals); //note MxVals==Vals
1757  EmptyVal = TVal(SIn);
1758  if (MxVals==0) { ValBf = NULL; } else { ValBf = new TVal [MxVals]; }
1759  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN] = TVal(SIn); }
1760  { TInt MxVals(SIn), Vals(SIn);
1761  IdToOffV.Gen(Vals);
1762  for (int ValN = 0; ValN < Vals; ValN++) {
1763  uint64 Offset; SIn.Load(Offset); IAssert(Offset < TSizeMx);
1764  IdToOffV[ValN]=TSize(Offset);
1765  } }
1766 }
#define IAssert(Cond)
Definition: bd.h:262
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TVal * ValBf
Definition: ds.h:1616
TSize GrowBy
Definition: ds.h:1614
TVal EmptyVal
Definition: ds.h:1615
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:1044
TBool FastCopy
Definition: ds.h:1613
TVec< uint64, int > IdToOffV
Definition: ds.h:1617
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
TSize Vals
Definition: ds.h:1614
TSize MxVals
Definition: ds.h:1614

Here is the call graph for this function:

template<class TVal, class TSizeTy = int>
TVecPool< TVal, TSizeTy >::~TVecPool ( )
inline

Definition at line 1630 of file ds.h.

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

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 1815 of file ds.h.

References MAX.

1815  {
1816  if (ValVLen==0){return 0;}
1817  if (MxVals < Vals+ValVLen){Resize(Vals+MAX(TSize(ValVLen), GrowBy)); }
1818  Vals+=ValVLen; IdToOffV.Add(Vals);
1819  return IdToOffV.Len()-1;
1820 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
void Resize(const TSize &_MxVals)
Definition: ds.h:1705
TSize GrowBy
Definition: ds.h:1614
size_t TSize
Definition: bd.h:58
TVec< uint64, int > IdToOffV
Definition: ds.h:1617
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
#define MAX(a, b)
Definition: bd.h:350
TSize Vals
Definition: ds.h:1614
TSize MxVals
Definition: ds.h:1614
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 1804 of file ds.h.

References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::BegI(), TVec< TVal, TSizeTy >::Len(), and MAX.

1804  {
1805  const TSize ValVLen = ValV.Len();
1806  if (ValVLen == 0) { return 0; }
1807  if (MxVals < Vals+ValVLen) { Resize(Vals+MAX(ValVLen, GrowBy)); }
1808  if (FastCopy) { memcpy(ValBf+Vals, ValV.BegI(), sizeof(TVal)*ValV.Len()); }
1809  else { for (TSize ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
1810  Vals+=ValVLen; IdToOffV.Add(Vals);
1811  return IdToOffV.Len()-1;
1812 }
TVal * ValBf
Definition: ds.h:1616
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
void Resize(const TSize &_MxVals)
Definition: ds.h:1705
TSize GrowBy
Definition: ds.h:1614
size_t TSize
Definition: bd.h:58
TBool FastCopy
Definition: ds.h:1613
TVec< uint64, int > IdToOffV
Definition: ds.h:1617
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
#define MAX(a, b)
Definition: bd.h:350
TSize Vals
Definition: ds.h:1614
TSize MxVals
Definition: ds.h:1614

Here is the call graph for this function:

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 1694 of file ds.h.

Referenced by TBigNet< TNodeData, IsDir >::Clr().

1694  {
1695  IdToOffV.Clr(DoDel); MxVals=0; Vals=0;
1696  if (DoDel && ValBf!=NULL) { delete [] ValBf; ValBf=NULL;}
1697  if (! DoDel) { PutAll(EmptyVal); } }
TVal * ValBf
Definition: ds.h:1616
TVal EmptyVal
Definition: ds.h:1615
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:971
void PutAll(const TVal &Val)
Sets the values of all elements in the pool to Val.
Definition: ds.h:1699
TVec< uint64, int > IdToOffV
Definition: ds.h:1617
TSize Vals
Definition: ds.h:1614
TSize MxVals
Definition: ds.h:1614

Here is the caller graph for this function:

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 1824 of file ds.h.

1824  {
1825  ::TSize TotalDel=0, NDel=0;
1826  // printf("Compacting %d vectors\n", IdToOffV.Len());
1827  for (int vid = 1; vid < IdToOffV.Len(); vid++) {
1828  // if (vid % 10000000 == 0) { printf(" %dm", vid/1000000); fflush(stdout); }
1829  const uint Len = GetVLen(vid);
1830  TVal* ValV = GetValVPt(vid);
1831  if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; } // update end of vector
1832  if (Len == 0) { continue; }
1833  NDel = 0;
1834  for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
1835  if (*v == DelVal) {
1836  TVal* Beg = v;
1837  while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
1838  memcpy(Beg, v, sizeof(TVal)*int(Len - ::TSize(v - ValV)));
1839  v -= NDel;
1840  }
1841  }
1842  memcpy(ValV-TotalDel, ValV, sizeof(TVal)*Len); // move data
1843  TotalDel += NDel;
1844  }
1845  IdToOffV.Last() -= TotalDel;
1846  for (::TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
1847  Vals -= TotalDel;
1848  // printf(" deleted %llu elements from the pool\n", TotalDel);
1849 }
unsigned int uint
Definition: bd.h:11
TVal * ValBf
Definition: ds.h:1616
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TVal EmptyVal
Definition: ds.h:1615
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
Definition: ds.h:1665
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1663
size_t TSize
Definition: bd.h:58
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:551
TVec< uint64, int > IdToOffV
Definition: ds.h:1617
TSize Vals
Definition: ds.h:1614
template<class TVal, class TSizeTy = int>
const TVal& TVecPool< TVal, TSizeTy >::GetEmptyVal ( ) const
inline

Returns the reference to an empty value.

Definition at line 1649 of file ds.h.

1649 { return EmptyVal; }
TVal EmptyVal
Definition: ds.h:1615
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 1653 of file ds.h.

1653  {
1654  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:1614
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 1671 of file ds.h.

1671  {
1672  if (GetVLen(VId)==0){ValV.Clr();}
1673  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:1665
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1663
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 1641 of file ds.h.

Referenced by TBigNet< TNodeData, IsDir >::GetEdges().

1641 { return Vals; }
TSize Vals
Definition: ds.h:1614

Here is the caller graph for this function:

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 1665 of file ds.h.

Referenced by TNGraphMP::AddNode(), TUNGraph::AddNode(), TNGraph::AddNode(), TUndirNet::AddNode(), TDirNet::AddNode(), TBigNet< TNodeData, IsDir >::GetInNIdVPt(), TBigNet< TNodeData, IsDir >::TNodeI::GetInOutNIdV(), TBigNet< TNodeData, IsDir >::GetOutNIdVPt(), TVecPool< TInt >::GetV(), and TVecPool< TInt >::PutV().

1665  {
1666  if (GetVLen(VId)==0){return (TVal*)&EmptyVal;}
1667  else {return ValBf+IdToOffV[VId-1];}}
TVal * ValBf
Definition: ds.h:1616
TVal EmptyVal
Definition: ds.h:1615
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1663
TVec< uint64, int > IdToOffV
Definition: ds.h:1617

Here is the caller graph for this function:

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 1639 of file ds.h.

1639 { return IdToOffV.Len(); }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TVec< uint64, int > IdToOffV
Definition: ds.h:1617
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 1663 of file ds.h.

Referenced by TNGraphMP::AddNode(), TUNGraph::AddNode(), TNGraph::AddNode(), TUndirNet::AddNode(), TDirNet::AddNode(), TBigNet< TNodeData, IsDir >::TNodeI::GetInOutNIdV(), TVecPool< TInt >::GetV(), TVecPool< TInt >::GetValVPt(), and TVecPool< TInt >::PutV().

1663 { if (VId==0){return 0;} else {return int(IdToOffV[VId]-IdToOffV[VId-1]);}}
TVec< uint64, int > IdToOffV
Definition: ds.h:1617

Here is the caller graph for this function:

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 1643 of file ds.h.

Referenced by TBigNet< TNodeData, IsDir >::TNodeI::GetInOutNIdV(), and TVecPool< TInt >::PutV().

1643 { return (0 <= VId) && (VId < IdToOffV.Len()); }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TVec< uint64, int > IdToOffV
Definition: ds.h:1617

Here is the caller graph for this function:

template<class TVal, class TSizeTy = int>
static PVecPool TVecPool< TVal, TSizeTy >::Load ( TSIn SIn)
inlinestatic

Definition at line 1633 of file ds.h.

1633 { 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:1733
template<class TVal, class TSizeTy = int>
static PVecPool TVecPool< TVal, TSizeTy >::Load ( const TStr FNm)
inlinestatic

Definition at line 1634 of file ds.h.

Referenced by TVecPool< TInt >::Load().

1634 { TFIn FIn(FNm); return Load(FIn); }
Definition: fl.h:275
static PVecPool Load(TSIn &SIn)
Definition: ds.h:1633

Here is the caller graph for this function:

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 1631 of file ds.h.

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

Definition at line 1782 of file ds.h.

References TStr::CStr(), TVecPool< TVal, TSizeTy >::EmptyVal, FailR, TVecPool< TVal, TSizeTy >::FastCopy, TStr::Fmt(), TInt::GetStr(), TVecPool< TVal, TSizeTy >::GrowBy, IAssert, TVecPool< TVal, TSizeTy >::IdToOffV, TVecPool< TVal, TSizeTy >::MxVals, TVecPool< TVal, TSizeTy >::ValBf, and TVecPool< TVal, TSizeTy >::Vals.

1782  {
1783  if (this!=&Pool) {
1784  FastCopy = Pool.FastCopy;
1785  GrowBy = Pool.GrowBy;
1786  MxVals = Pool.MxVals;
1787  Vals = Pool.Vals;
1788  EmptyVal = Pool.EmptyVal;
1789  IdToOffV=Pool.IdToOffV;
1790  try {
1791  ValBf = new TVal [MxVals]; }
1792  catch (std::exception Ex) {
1793  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()); }
1794  IAssert(ValBf != NULL);
1795  if (FastCopy) {
1796  memcpy(ValBf, Pool.ValBf, Vals*sizeof(TVal)); }
1797  else {
1798  for (TSize ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
1799  }
1800  return *this;
1801 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1107
TVal * ValBf
Definition: ds.h:1616
TSize GrowBy
Definition: ds.h:1614
TVal EmptyVal
Definition: ds.h:1615
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:1613
TVec< uint64, int > IdToOffV
Definition: ds.h:1617
char * CStr()
Definition: dt.h:476
TSize Vals
Definition: ds.h:1614
TSize MxVals
Definition: ds.h:1614

Here is the call graph for this function:

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 1699 of file ds.h.

Referenced by TVecPool< TInt >::Clr().

1699  {
1700  for (TSize ValN = 0; ValN < MxVals; ValN++) { ValBf[ValN]=Val; } }
TVal * ValBf
Definition: ds.h:1616
size_t TSize
Definition: bd.h:58
TSize MxVals
Definition: ds.h:1614

Here is the caller graph for this function:

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 1675 of file ds.h.

1675  {
1676  IAssert(IsVId(VId) && GetVLen(VId) == ValV.Len());
1677  if (FastCopy) {
1678  memcpy(GetValVPt(VId), ValV.BegI(), sizeof(TVal)*ValV.Len()); }
1679  else { TVal* ValPt = GetValVPt(VId);
1680  for (::TSize ValN=0; ValN < ::TSize(ValV.Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
1681  } }
#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:1665
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1663
size_t TSize
Definition: bd.h:58
TBool FastCopy
Definition: ds.h:1613
bool IsVId(const int &VId) const
Tests whether vector of id VId is in the pool.
Definition: ds.h:1643
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 1647 of file ds.h.

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

Returns the total capacity of the pool.

Definition at line 1645 of file ds.h.

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

Definition at line 1705 of file ds.h.

References TStr::CStr(), FailR, TStr::Fmt(), TInt::GetStr(), and IAssert.

Referenced by TVecPool< TInt >::Reserve(), and TVecPool< TVal, TSizeTy >::TVecPool().

1705  {
1706  if (_MxVals <= MxVals){ return; } else { MxVals = _MxVals; }
1707  if (ValBf == NULL) {
1708  try { ValBf = new TVal [MxVals]; }
1709  catch (std::exception Ex) {
1710  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()); }
1711  IAssert(ValBf != NULL);
1712  if (EmptyVal != TVal()) { PutAll(EmptyVal); }
1713  } else {
1714  // printf("*** Resize vector pool: %llu -> %llu\n", uint64(Vals), uint64(MxVals));
1715  TVal* NewValBf = NULL;
1716  try { NewValBf = new TVal [MxVals]; }
1717  catch (std::exception Ex) {
1718  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()); }
1719  IAssert(NewValBf != NULL);
1720  if (FastCopy) {
1721  memcpy(NewValBf, ValBf, Vals*sizeof(TVal)); }
1722  else {
1723  for (TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
1724  if (EmptyVal != TVal()) { // init empty values
1725  for (TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
1726  }
1727  delete [] ValBf;
1728  ValBf = NewValBf;
1729  }
1730 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1107
TVal * ValBf
Definition: ds.h:1616
TVal EmptyVal
Definition: ds.h:1615
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:1699
#define FailR(Reason)
Definition: bd.h:240
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TBool FastCopy
Definition: ds.h:1613
char * CStr()
Definition: dt.h:476
TSize Vals
Definition: ds.h:1614
TSize MxVals
Definition: ds.h:1614

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal , class TSizeTy >
void TVecPool< TVal, TSizeTy >::Save ( TSOut SOut) const

Definition at line 1769 of file ds.h.

References TSOut::Save().

Referenced by TBigNet< TNodeData, IsDir >::SaveToDisk().

1769  {
1770  SOut.Save(FastCopy);
1771  uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
1772  SOut.Save(_GrowBy); SOut.Save(_MxVals); SOut.Save(_Vals);
1773  SOut.Save(EmptyVal);
1774  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
1775  { SOut.Save(IdToOffV.Len()); SOut.Save(IdToOffV.Len());
1776  for (int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
1777  const uint64 Offset=IdToOffV[ValN]; SOut.Save(Offset);
1778  } }
1779 }
TVal * ValBf
Definition: ds.h:1616
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TSize GrowBy
Definition: ds.h:1614
TVal EmptyVal
Definition: ds.h:1615
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:1613
TVec< uint64, int > IdToOffV
Definition: ds.h:1617
TSize Vals
Definition: ds.h:1614
TSize MxVals
Definition: ds.h:1614

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal, class TSizeTy = int>
void TVecPool< TVal, TSizeTy >::SetEmptyVal ( const TVal &  _EmptyVal)
inline

Sets the empty value.

Definition at line 1651 of file ds.h.

1651 { EmptyVal = _EmptyVal; }
TVal EmptyVal
Definition: ds.h:1615
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 1853 of file ds.h.

References TRnd::GetUniDevInt().

1853  {
1854  for (::TSize n = Vals-1; n > 0; n--) {
1855  const ::TSize k = ::TSize(((uint64(Rnd.GetUniDevInt())<<32) | uint64(Rnd.GetUniDevInt())) % (n+1));
1856  const TVal Tmp = ValBf[n];
1857  ValBf[n] = ValBf[k];
1858  ValBf[k] = Tmp;
1859  }
1860 }
TVal * ValBf
Definition: ds.h:1616
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:1614

Here is the call graph for this function:

Friends And Related Function Documentation

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

Definition at line 1701 of file ds.h.

Member Data Documentation

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

Definition at line 1612 of file ds.h.

template<class TVal, class TSizeTy = int>
TVal TVecPool< TVal, TSizeTy >::EmptyVal
private
template<class TVal, class TSizeTy = int>
TBool TVecPool< TVal, TSizeTy >::FastCopy
private
template<class TVal, class TSizeTy = int>
TSize TVecPool< TVal, TSizeTy >::GrowBy
private
template<class TVal, class TSizeTy = int>
TSize TVecPool< TVal, TSizeTy >::MxVals
private
template<class TVal, class TSizeTy = int>
TVal* TVecPool< TVal, TSizeTy >::ValBf
private
template<class TVal, class TSizeTy = int>
TSize TVecPool< TVal, TSizeTy >::Vals
private

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