SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
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 1673 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 1675 of file ds.h.

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

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

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

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

1799  : GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
1800  IdToOffV.Add(0);
1801  Resize(ExpectVals);
1802 }
TVal * ValBf
Definition: ds.h:1682
void Resize(const TSize &_MxVals)
Definition: ds.h:1771
TSize GrowBy
Definition: ds.h:1680
TVal EmptyVal
Definition: ds.h:1681
TVec< uint64, int > IdToOffV
Definition: ds.h:1683
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
TSize Vals
Definition: ds.h:1680
TSize MxVals
Definition: ds.h:1680

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

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

1805  : FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy), MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
1806  try {
1807  ValBf = new TVal [MxVals]; }
1808  catch (std::exception Ex) {
1809  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()); }
1810  IAssert(ValBf != NULL);
1811  if (FastCopy) {
1812  memcpy(ValBf, Pool.ValBf, MxVals*sizeof(TVal)); }
1813  else {
1814  for (TSize ValN = 0; ValN < MxVals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
1815 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1200
TVal * ValBf
Definition: ds.h:1682
TSize GrowBy
Definition: ds.h:1680
TVal EmptyVal
Definition: ds.h:1681
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:1679
TVec< uint64, int > IdToOffV
Definition: ds.h:1683
char * CStr()
Definition: dt.h:479
TSize Vals
Definition: ds.h:1680
TSize MxVals
Definition: ds.h:1680

Here is the call graph for this function:

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

Definition at line 1818 of file ds.h.

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

1818  : FastCopy(SIn) {
1819  uint64 _GrowBy, _MxVals, _Vals;
1820  SIn.Load(_GrowBy); SIn.Load(_MxVals); SIn.Load(_Vals);
1821  IAssertR(_GrowBy<TSizeMx && _MxVals<TSizeMx && _Vals<TSizeMx, "This is a 64-bit vector pool. Use a 64-bit compiler.");
1822  GrowBy=TSize(_GrowBy); MxVals=TSize(_Vals); Vals=TSize(_Vals); //note MxVals==Vals
1823  EmptyVal = TVal(SIn);
1824  if (MxVals==0) { ValBf = NULL; } else { ValBf = new TVal [MxVals]; }
1825  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN] = TVal(SIn); }
1826  { TInt MxVals(SIn), Vals(SIn);
1827  IdToOffV.Gen(Vals);
1828  for (int ValN = 0; ValN < Vals; ValN++) {
1829  uint64 Offset; SIn.Load(Offset); IAssert(Offset < TSizeMx);
1830  IdToOffV[ValN]=TSize(Offset);
1831  } }
1832 }
#define IAssert(Cond)
Definition: bd.h:262
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TVal * ValBf
Definition: ds.h:1682
TSize GrowBy
Definition: ds.h:1680
TVal EmptyVal
Definition: ds.h:1681
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:1137
TBool FastCopy
Definition: ds.h:1679
TVec< uint64, int > IdToOffV
Definition: ds.h:1683
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
TSize Vals
Definition: ds.h:1680
TSize MxVals
Definition: ds.h:1680

Here is the call graph for this function:

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

Definition at line 1696 of file ds.h.

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

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

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

Referenced by TBigNet< TNodeData, IsDir >::AddNode(), TBigNet< TNodeData, IsDir >::AddUndirNode(), and TBigNet< TNodeData, IsDir >::InvertFromSources().

1881  {
1882  if (ValVLen==0){return 0;}
1883  if (MxVals < Vals+ValVLen){Resize(Vals+MAX(TSize(ValVLen), GrowBy)); }
1884  Vals+=ValVLen; IdToOffV.Add(Vals);
1885  return IdToOffV.Len()-1;
1886 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void Resize(const TSize &_MxVals)
Definition: ds.h:1771
TSize GrowBy
Definition: ds.h:1680
size_t TSize
Definition: bd.h:58
TVec< uint64, int > IdToOffV
Definition: ds.h:1683
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
#define MAX(a, b)
Definition: bd.h:350
TSize Vals
Definition: ds.h:1680
TSize MxVals
Definition: ds.h:1680

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Referenced by TBigNet< TNodeData, IsDir >::AddNode(), and TBigNet< TNodeData, IsDir >::AddUndirNode().

1870  {
1871  const TSize ValVLen = ValV.Len();
1872  if (ValVLen == 0) { return 0; }
1873  if (MxVals < Vals+ValVLen) { Resize(Vals+MAX(ValVLen, GrowBy)); }
1874  if (FastCopy) { memcpy(ValBf+Vals, ValV.BegI(), sizeof(TVal)*ValV.Len()); }
1875  else { for (TSize ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
1876  Vals+=ValVLen; IdToOffV.Add(Vals);
1877  return IdToOffV.Len()-1;
1878 }
TVal * ValBf
Definition: ds.h:1682
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void Resize(const TSize &_MxVals)
Definition: ds.h:1771
TSize GrowBy
Definition: ds.h:1680
size_t TSize
Definition: bd.h:58
TBool FastCopy
Definition: ds.h:1679
TVec< uint64, int > IdToOffV
Definition: ds.h:1683
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
#define MAX(a, b)
Definition: bd.h:350
TSize Vals
Definition: ds.h:1680
TSize MxVals
Definition: ds.h:1680

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

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

1760  {
1761  IdToOffV.Clr(DoDel); MxVals=0; Vals=0;
1762  if (DoDel && ValBf!=NULL) { delete [] ValBf; ValBf=NULL;}
1763  if (! DoDel) { PutAll(EmptyVal); } }
TVal * ValBf
Definition: ds.h:1682
TVal EmptyVal
Definition: ds.h:1681
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
void PutAll(const TVal &Val)
Sets the values of all elements in the pool to Val.
Definition: ds.h:1765
TVec< uint64, int > IdToOffV
Definition: ds.h:1683
TSize Vals
Definition: ds.h:1680
TSize MxVals
Definition: ds.h:1680

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

References TVec< TVal, TSizeTy >::Last(), and TVec< TVal, TSizeTy >::Len().

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

1890  {
1891  ::TSize TotalDel=0, NDel=0;
1892  // printf("Compacting %d vectors\n", IdToOffV.Len());
1893  for (int vid = 1; vid < IdToOffV.Len(); vid++) {
1894  // if (vid % 10000000 == 0) { printf(" %dm", vid/1000000); fflush(stdout); }
1895  const uint Len = GetVLen(vid);
1896  TVal* ValV = GetValVPt(vid);
1897  if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; } // update end of vector
1898  if (Len == 0) { continue; }
1899  NDel = 0;
1900  for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
1901  if (*v == DelVal) {
1902  TVal* Beg = v;
1903  while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
1904  memcpy(Beg, v, sizeof(TVal)*int(Len - ::TSize(v - ValV)));
1905  v -= NDel;
1906  }
1907  }
1908  memcpy(ValV-TotalDel, ValV, sizeof(TVal)*Len); // move data
1909  TotalDel += NDel;
1910  }
1911  IdToOffV.Last() -= TotalDel;
1912  for (::TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
1913  Vals -= TotalDel;
1914  // printf(" deleted %llu elements from the pool\n", TotalDel);
1915 }
unsigned int uint
Definition: bd.h:11
TVal * ValBf
Definition: ds.h:1682
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TVal EmptyVal
Definition: ds.h:1681
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
Definition: ds.h:1731
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1729
size_t TSize
Definition: bd.h:58
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:579
TVec< uint64, int > IdToOffV
Definition: ds.h:1683
TSize Vals
Definition: ds.h:1680

Here is the call graph for this function:

Here is the caller graph for this function:

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

Returns the reference to an empty value.

Definition at line 1715 of file ds.h.

1715 { return EmptyVal; }
TVal EmptyVal
Definition: ds.h:1681
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 1719 of file ds.h.

1719  {
1720  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:974
TSize MxVals
Definition: ds.h:1680
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 1737 of file ds.h.

Referenced by TBigNet< TNodeData, IsDir >::GetInNIdV(), TBigNet< TNodeData, IsDir >::GetOutNIdV(), TBigNet< TNodeData, IsDir >::InvertFromSources(), TBigNet< TNodeData, IsDir >::IsOk(), TBigNet< TNodeData, IsDir >::SetInNIdV(), and TBigNet< TNodeData, IsDir >::SetOutNIdV().

1737  {
1738  if (GetVLen(VId)==0){ValV.Clr();}
1739  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:1731
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1729

Here is the caller graph for this function:

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

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

1707 { return Vals; }
TSize Vals
Definition: ds.h:1680

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

Referenced by TBigNet< TNodeData, IsDir >::AddEdge(), 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(), TBigNet< TNodeData, IsDir >::InvertFromSources(), TBigNet< TNodeData, IsDir >::IsEdge(), TBigNet< TNodeData, IsDir >::IsOk(), TBigNet< TNodeData, IsDir >::IsolateNode(), TVecPool< TInt >::PutV(), and TBigNet< TNodeData, IsDir >::Rewire().

1731  {
1732  if (GetVLen(VId)==0){return (TVal*)&EmptyVal;}
1733  else {return ValBf+IdToOffV[VId-1];}}
TVal * ValBf
Definition: ds.h:1682
TVal EmptyVal
Definition: ds.h:1681
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1729
TVec< uint64, int > IdToOffV
Definition: ds.h:1683

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

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

1705 { return IdToOffV.Len(); }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TVec< uint64, int > IdToOffV
Definition: ds.h:1683

Here is the caller graph for this function:

template<class TVal, class TSizeTy = int>
int TVecPool< TVal, TSizeTy >::GetVLen ( const int &  VId) const
inline
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 1709 of file ds.h.

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

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

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

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

Definition at line 1700 of file ds.h.

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

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

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

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

Definition at line 1848 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.

1848  {
1849  if (this!=&Pool) {
1850  FastCopy = Pool.FastCopy;
1851  GrowBy = Pool.GrowBy;
1852  MxVals = Pool.MxVals;
1853  Vals = Pool.Vals;
1854  EmptyVal = Pool.EmptyVal;
1855  IdToOffV=Pool.IdToOffV;
1856  try {
1857  ValBf = new TVal [MxVals]; }
1858  catch (std::exception Ex) {
1859  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()); }
1860  IAssert(ValBf != NULL);
1861  if (FastCopy) {
1862  memcpy(ValBf, Pool.ValBf, Vals*sizeof(TVal)); }
1863  else {
1864  for (TSize ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
1865  }
1866  return *this;
1867 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1200
TVal * ValBf
Definition: ds.h:1682
TSize GrowBy
Definition: ds.h:1680
TVal EmptyVal
Definition: ds.h:1681
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:1679
TVec< uint64, int > IdToOffV
Definition: ds.h:1683
char * CStr()
Definition: dt.h:479
TSize Vals
Definition: ds.h:1680
TSize MxVals
Definition: ds.h:1680

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

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

1765  {
1766  for (TSize ValN = 0; ValN < MxVals; ValN++) { ValBf[ValN]=Val; } }
TVal * ValBf
Definition: ds.h:1682
size_t TSize
Definition: bd.h:58
TSize MxVals
Definition: ds.h:1680

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

1741  {
1742  IAssert(IsVId(VId) && GetVLen(VId) == ValV.Len());
1743  if (FastCopy) {
1744  memcpy(GetValVPt(VId), ValV.BegI(), sizeof(TVal)*ValV.Len()); }
1745  else { TVal* ValPt = GetValVPt(VId);
1746  for (::TSize ValN=0; ValN < ::TSize(ValV.Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
1747  } }
#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:1731
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1729
size_t TSize
Definition: bd.h:58
TBool FastCopy
Definition: ds.h:1679
bool IsVId(const int &VId) const
Tests whether vector of id VId is in the pool.
Definition: ds.h:1709
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 1713 of file ds.h.

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

1713 { Resize(MxVals); }
void Resize(const TSize &_MxVals)
Definition: ds.h:1771
TSize MxVals
Definition: ds.h:1680

Here is the caller graph for this function:

template<class TVal, class TSizeTy = int>
uint64 TVecPool< TVal, TSizeTy >::Reserved ( ) const
inline

Returns the total capacity of the pool.

Definition at line 1711 of file ds.h.

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

1711 { return MxVals; }
TSize MxVals
Definition: ds.h:1680

Here is the caller graph for this function:

template<class TVal , class TSizeTy >
void TVecPool< TVal, TSizeTy >::Resize ( const TSize _MxVals)
private

Definition at line 1771 of file ds.h.

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

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

1771  {
1772  if (_MxVals <= MxVals){ return; } else { MxVals = _MxVals; }
1773  if (ValBf == NULL) {
1774  try { ValBf = new TVal [MxVals]; }
1775  catch (std::exception Ex) {
1776  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()); }
1777  IAssert(ValBf != NULL);
1778  if (EmptyVal != TVal()) { PutAll(EmptyVal); }
1779  } else {
1780  // printf("*** Resize vector pool: %llu -> %llu\n", uint64(Vals), uint64(MxVals));
1781  TVal* NewValBf = NULL;
1782  try { NewValBf = new TVal [MxVals]; }
1783  catch (std::exception Ex) {
1784  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()); }
1785  IAssert(NewValBf != NULL);
1786  if (FastCopy) {
1787  memcpy(NewValBf, ValBf, Vals*sizeof(TVal)); }
1788  else {
1789  for (TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
1790  if (EmptyVal != TVal()) { // init empty values
1791  for (TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
1792  }
1793  delete [] ValBf;
1794  ValBf = NewValBf;
1795  }
1796 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1200
TVal * ValBf
Definition: ds.h:1682
TVal EmptyVal
Definition: ds.h:1681
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:1765
#define FailR(Reason)
Definition: bd.h:240
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TBool FastCopy
Definition: ds.h:1679
char * CStr()
Definition: dt.h:479
TSize Vals
Definition: ds.h:1680
TSize MxVals
Definition: ds.h:1680

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

References TVec< TVal, TSizeTy >::Len(), and TSOut::Save().

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

1835  {
1836  SOut.Save(FastCopy);
1837  uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
1838  SOut.Save(_GrowBy); SOut.Save(_MxVals); SOut.Save(_Vals);
1839  SOut.Save(EmptyVal);
1840  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
1841  { SOut.Save(IdToOffV.Len()); SOut.Save(IdToOffV.Len());
1842  for (int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
1843  const uint64 Offset=IdToOffV[ValN]; SOut.Save(Offset);
1844  } }
1845 }
TVal * ValBf
Definition: ds.h:1682
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TSize GrowBy
Definition: ds.h:1680
TVal EmptyVal
Definition: ds.h:1681
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:1679
TVec< uint64, int > IdToOffV
Definition: ds.h:1683
TSize Vals
Definition: ds.h:1680
TSize MxVals
Definition: ds.h:1680

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

1717 { EmptyVal = _EmptyVal; }
TVal EmptyVal
Definition: ds.h:1681
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 1919 of file ds.h.

References TRnd::GetUniDevInt().

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

1919  {
1920  for (::TSize n = Vals-1; n > 0; n--) {
1921  const ::TSize k = ::TSize(((uint64(Rnd.GetUniDevInt())<<32) | uint64(Rnd.GetUniDevInt())) % (n+1));
1922  const TVal Tmp = ValBf[n];
1923  ValBf[n] = ValBf[k];
1924  ValBf[k] = Tmp;
1925  }
1926 }
TVal * ValBf
Definition: ds.h:1682
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:1680

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

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

Definition at line 1767 of file ds.h.

Member Data Documentation

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

Definition at line 1678 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

Definition at line 1679 of file ds.h.

Referenced by TVecPool< TVal, TSizeTy >::operator=().

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

Definition at line 1680 of file ds.h.

Referenced by TVecPool< TVal, TSizeTy >::operator=().

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

Definition at line 1683 of file ds.h.

Referenced by TVecPool< TVal, TSizeTy >::operator=().

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: