SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
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 1672 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 1674 of file ds.h.

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

Definition at line 1675 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 1798 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().

1798  : GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
1799  IdToOffV.Add(0);
1800  Resize(ExpectVals);
1801 }
TVal * ValBf
Definition: ds.h:1681
void Resize(const TSize &_MxVals)
Definition: ds.h:1770
TSize GrowBy
Definition: ds.h:1679
TVal EmptyVal
Definition: ds.h:1680
TVec< uint64, int > IdToOffV
Definition: ds.h:1682
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:1679
TSize MxVals
Definition: ds.h:1679

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 1804 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.

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

Here is the call graph for this function:

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

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

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

Here is the call graph for this function:

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

Definition at line 1695 of file ds.h.

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

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

References MAX.

1880  {
1881  if (ValVLen==0){return 0;}
1882  if (MxVals < Vals+ValVLen){Resize(Vals+MAX(TSize(ValVLen), GrowBy)); }
1883  Vals+=ValVLen; IdToOffV.Add(Vals);
1884  return IdToOffV.Len()-1;
1885 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void Resize(const TSize &_MxVals)
Definition: ds.h:1770
TSize GrowBy
Definition: ds.h:1679
size_t TSize
Definition: bd.h:58
TVec< uint64, int > IdToOffV
Definition: ds.h:1682
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:1679
TSize MxVals
Definition: ds.h:1679
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 1869 of file ds.h.

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

1869  {
1870  const TSize ValVLen = ValV.Len();
1871  if (ValVLen == 0) { return 0; }
1872  if (MxVals < Vals+ValVLen) { Resize(Vals+MAX(ValVLen, GrowBy)); }
1873  if (FastCopy) { memcpy(ValBf+Vals, ValV.BegI(), sizeof(TVal)*ValV.Len()); }
1874  else { for (TSize ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
1875  Vals+=ValVLen; IdToOffV.Add(Vals);
1876  return IdToOffV.Len()-1;
1877 }
TVal * ValBf
Definition: ds.h:1681
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void Resize(const TSize &_MxVals)
Definition: ds.h:1770
TSize GrowBy
Definition: ds.h:1679
size_t TSize
Definition: bd.h:58
TBool FastCopy
Definition: ds.h:1678
TVec< uint64, int > IdToOffV
Definition: ds.h:1682
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:1679
TSize MxVals
Definition: ds.h:1679

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

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

1759  {
1760  IdToOffV.Clr(DoDel); MxVals=0; Vals=0;
1761  if (DoDel && ValBf!=NULL) { delete [] ValBf; ValBf=NULL;}
1762  if (! DoDel) { PutAll(EmptyVal); } }
TVal * ValBf
Definition: ds.h:1681
TVal EmptyVal
Definition: ds.h:1680
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:1764
TVec< uint64, int > IdToOffV
Definition: ds.h:1682
TSize Vals
Definition: ds.h:1679
TSize MxVals
Definition: ds.h:1679

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

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

Returns the reference to an empty value.

Definition at line 1714 of file ds.h.

1714 { return EmptyVal; }
TVal EmptyVal
Definition: ds.h:1680
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 1718 of file ds.h.

1718  {
1719  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:971
TSize MxVals
Definition: ds.h:1679
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 1736 of file ds.h.

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

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

1706 { return Vals; }
TSize Vals
Definition: ds.h:1679

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 1730 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().

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

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

1704 { 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:1682
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 1728 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().

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

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

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

1708 { 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:1682

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

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

Definition at line 1699 of file ds.h.

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

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

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

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

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

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

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

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

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

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

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

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

Returns the total capacity of the pool.

Definition at line 1710 of file ds.h.

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

Definition at line 1770 of file ds.h.

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

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

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

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

References TSOut::Save().

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

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

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

1716 { EmptyVal = _EmptyVal; }
TVal EmptyVal
Definition: ds.h:1680
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 1918 of file ds.h.

References TRnd::GetUniDevInt().

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

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

Member Data Documentation

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

Definition at line 1677 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: