SNAP Library 2.3, User Reference  2014-06-16 11:58:46
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 2550 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 2552 of file ds.h.

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

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

2676  : GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
2677  IdToOffV.Add(0);
2678  Resize(ExpectVals);
2679 }
TVal * ValBf
Definition: ds.h:2559
void Resize(const TSize &_MxVals)
Definition: ds.h:2648
TSize GrowBy
Definition: ds.h:2557
TVal EmptyVal
Definition: ds.h:2558
TVec< uint64, int > IdToOffV
Definition: ds.h:2560
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:2557
TSize MxVals
Definition: ds.h:2557
template<class TVal, class TSizeTy >
TVecPool< TVal, TSizeTy >::TVecPool ( const TVecPool< TVal, TSizeTy > &  Pool)

Definition at line 2682 of file ds.h.

2682  : FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy), MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
2683  try {
2684  ValBf = new TVal [MxVals]; }
2685  catch (std::exception Ex) {
2686  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()); }
2687  IAssert(ValBf != NULL);
2688  if (FastCopy) {
2689  memcpy(ValBf, Pool.ValBf, MxVals*sizeof(TVal)); }
2690  else {
2691  for (TSize ValN = 0; ValN < MxVals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
2692 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1104
TVal * ValBf
Definition: ds.h:2559
TSize GrowBy
Definition: ds.h:2557
TVal EmptyVal
Definition: ds.h:2558
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:2556
TVec< uint64, int > IdToOffV
Definition: ds.h:2560
char * CStr()
Definition: dt.h:476
TSize Vals
Definition: ds.h:2557
TSize MxVals
Definition: ds.h:2557
template<class TVal, class TSizeTy >
TVecPool< TVal, TSizeTy >::TVecPool ( TSIn SIn)

Definition at line 2695 of file ds.h.

2695  : FastCopy(SIn) {
2696  uint64 _GrowBy, _MxVals, _Vals;
2697  SIn.Load(_GrowBy); SIn.Load(_MxVals); SIn.Load(_Vals);
2698  IAssertR(_GrowBy<TSizeMx && _MxVals<TSizeMx && _Vals<TSizeMx, "This is a 64-bit vector pool. Use a 64-bit compiler.");
2699  GrowBy=TSize(_GrowBy); MxVals=TSize(_Vals); Vals=TSize(_Vals); //note MxVals==Vals
2700  EmptyVal = TVal(SIn);
2701  if (MxVals==0) { ValBf = NULL; } else { ValBf = new TVal [MxVals]; }
2702  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN] = TVal(SIn); }
2703  { TInt MxVals(SIn), Vals(SIn);
2704  IdToOffV.Gen(Vals);
2705  for (int ValN = 0; ValN < Vals; ValN++) {
2706  uint64 Offset; SIn.Load(Offset); IAssert(Offset < TSizeMx);
2707  IdToOffV[ValN]=TSize(Offset);
2708  } }
2709 }
#define IAssert(Cond)
Definition: bd.h:262
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TVal * ValBf
Definition: ds.h:2559
TSize GrowBy
Definition: ds.h:2557
TVal EmptyVal
Definition: ds.h:2558
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:1041
TBool FastCopy
Definition: ds.h:2556
TVec< uint64, int > IdToOffV
Definition: ds.h:2560
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
TSize Vals
Definition: ds.h:2557
TSize MxVals
Definition: ds.h:2557
template<class TVal, class TSizeTy = int>
TVecPool< TVal, TSizeTy >::~TVecPool ( )
inline

Definition at line 2573 of file ds.h.

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

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

2758  {
2759  if (ValVLen==0){return 0;}
2760  if (MxVals < Vals+ValVLen){Resize(Vals+max(TSize(ValVLen), GrowBy)); }
2761  Vals+=ValVLen; IdToOffV.Add(Vals);
2762  return IdToOffV.Len()-1;
2763 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
void Resize(const TSize &_MxVals)
Definition: ds.h:2648
TSize GrowBy
Definition: ds.h:2557
size_t TSize
Definition: bd.h:58
#define max(a, b)
Definition: bd.h:350
TVec< uint64, int > IdToOffV
Definition: ds.h:2560
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:2557
TSize MxVals
Definition: ds.h:2557
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 2747 of file ds.h.

2747  {
2748  const TSizeTy ValVLen = ValV.Len();
2749  if (ValVLen == 0) { return 0; }
2750  if (MxVals < Vals+ValVLen) { Resize(Vals+max(ValVLen, GrowBy)); }
2751  if (FastCopy) { memcpy(ValBf+Vals, ValV.BegI(), sizeof(TVal)*ValV.Len()); }
2752  else { for (uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
2753  Vals+=ValVLen; IdToOffV.Add(Vals);
2754  return IdToOffV.Len()-1;
2755 }
unsigned int uint
Definition: bd.h:11
TVal * ValBf
Definition: ds.h:2559
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
void Resize(const TSize &_MxVals)
Definition: ds.h:2648
TSize GrowBy
Definition: ds.h:2557
#define max(a, b)
Definition: bd.h:350
TBool FastCopy
Definition: ds.h:2556
TVec< uint64, int > IdToOffV
Definition: ds.h:2560
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:2557
TSize MxVals
Definition: ds.h:2557
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 2637 of file ds.h.

2637  {
2638  IdToOffV.Clr(DoDel); MxVals=0; Vals=0;
2639  if (DoDel && ValBf!=NULL) { delete [] ValBf; ValBf=NULL;}
2640  if (! DoDel) { PutAll(EmptyVal); } }
TVal * ValBf
Definition: ds.h:2559
TVal EmptyVal
Definition: ds.h:2558
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:2642
TVec< uint64, int > IdToOffV
Definition: ds.h:2560
TSize Vals
Definition: ds.h:2557
TSize MxVals
Definition: ds.h:2557
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 2767 of file ds.h.

2767  {
2768  ::TSize TotalDel=0, NDel=0;
2769  // printf("Compacting %d vectors\n", IdToOffV.Len());
2770  for (int vid = 1; vid < IdToOffV.Len(); vid++) {
2771  // if (vid % 10000000 == 0) { printf(" %dm", vid/1000000); fflush(stdout); }
2772  const uint Len = GetVLen(vid);
2773  TVal* ValV = GetValVPt(vid);
2774  if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; } // update end of vector
2775  if (Len == 0) { continue; }
2776  NDel = 0;
2777  for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
2778  if (*v == DelVal) {
2779  TVal* Beg = v;
2780  while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
2781  memcpy(Beg, v, sizeof(TVal)*int(Len - ::TSize(v - ValV)));
2782  v -= NDel;
2783  }
2784  }
2785  memcpy(ValV-TotalDel, ValV, sizeof(TVal)*Len); // move data
2786  TotalDel += NDel;
2787  }
2788  IdToOffV.Last() -= TotalDel;
2789  for (::TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
2790  Vals -= TotalDel;
2791  // printf(" deleted %llu elements from the pool\n", TotalDel);
2792 }
unsigned int uint
Definition: bd.h:11
TVal * ValBf
Definition: ds.h:2559
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TVal EmptyVal
Definition: ds.h:2558
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
Definition: ds.h:2608
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:2606
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:2560
TSize Vals
Definition: ds.h:2557
template<class TVal, class TSizeTy = int>
const TVal& TVecPool< TVal, TSizeTy >::GetEmptyVal ( ) const
inline

Returns the reference to an empty value.

Definition at line 2592 of file ds.h.

2592 { return EmptyVal; }
TVal EmptyVal
Definition: ds.h:2558
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 2596 of file ds.h.

2596  {
2597  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:2557
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 2614 of file ds.h.

2614  {
2615  if (GetVLen(VId)==0){ValV.Clr();}
2616  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:2608
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:2606
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 2584 of file ds.h.

2584 { return Vals; }
TSize Vals
Definition: ds.h:2557
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 2608 of file ds.h.

2608  {
2609  if (GetVLen(VId)==0){return (TVal*)&EmptyVal;}
2610  else {return ValBf+IdToOffV[VId-1];}}
TVal * ValBf
Definition: ds.h:2559
TVal EmptyVal
Definition: ds.h:2558
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:2606
TVec< uint64, int > IdToOffV
Definition: ds.h:2560
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 2582 of file ds.h.

2582 { 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:2560
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 2606 of file ds.h.

2606 { if (VId==0){return 0;} else {return int(IdToOffV[VId]-IdToOffV[VId-1]);}}
TVec< uint64, int > IdToOffV
Definition: ds.h:2560
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 2586 of file ds.h.

2586 { 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:2560
template<class TVal, class TSizeTy = int>
static PVecPool TVecPool< TVal, TSizeTy >::Load ( TSIn SIn)
inlinestatic

Definition at line 2576 of file ds.h.

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

Definition at line 2577 of file ds.h.

2577 { TFIn FIn(FNm); return Load(FIn); }
Definition: fl.h:275
static PVecPool Load(TSIn &SIn)
Definition: ds.h:2576
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 2574 of file ds.h.

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

Definition at line 2725 of file ds.h.

2725  {
2726  if (this!=&Pool) {
2727  FastCopy = Pool.FastCopy;
2728  GrowBy = Pool.GrowBy;
2729  MxVals = Pool.MxVals;
2730  Vals = Pool.Vals;
2731  EmptyVal = Pool.EmptyVal;
2732  IdToOffV=Pool.IdToOffV;
2733  try {
2734  ValBf = new TVal [MxVals]; }
2735  catch (std::exception Ex) {
2736  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()); }
2737  IAssert(ValBf != NULL);
2738  if (FastCopy) {
2739  memcpy(ValBf, Pool.ValBf, Vals*sizeof(TVal)); }
2740  else {
2741  for (TSize ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
2742  }
2743  return *this;
2744 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1104
TVal * ValBf
Definition: ds.h:2559
TSize GrowBy
Definition: ds.h:2557
TVal EmptyVal
Definition: ds.h:2558
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:2556
TVec< uint64, int > IdToOffV
Definition: ds.h:2560
char * CStr()
Definition: dt.h:476
TSize Vals
Definition: ds.h:2557
TSize MxVals
Definition: ds.h:2557
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 2642 of file ds.h.

2642  {
2643  for (TSize ValN = 0; ValN < MxVals; ValN++) { ValBf[ValN]=Val; } }
TVal * ValBf
Definition: ds.h:2559
size_t TSize
Definition: bd.h:58
TSize MxVals
Definition: ds.h:2557
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 2618 of file ds.h.

2618  {
2619  IAssert(IsVId(VId) && GetVLen(VId) == ValV.Len());
2620  if (FastCopy) {
2621  memcpy(GetValVPt(VId), ValV.BegI(), sizeof(TVal)*ValV.Len()); }
2622  else { TVal* ValPt = GetValVPt(VId);
2623  for (::TSize ValN=0; ValN < ::TSize(ValV.Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
2624  } }
#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:2608
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:2606
size_t TSize
Definition: bd.h:58
TBool FastCopy
Definition: ds.h:2556
bool IsVId(const int &VId) const
Tests whether vector of id VId is in the pool.
Definition: ds.h:2586
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 2590 of file ds.h.

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

Returns the total capacity of the pool.

Definition at line 2588 of file ds.h.

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

Definition at line 2648 of file ds.h.

2648  {
2649  if (_MxVals <= MxVals){ return; } else { MxVals = _MxVals; }
2650  if (ValBf == NULL) {
2651  try { ValBf = new TVal [MxVals]; }
2652  catch (std::exception Ex) {
2653  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()); }
2654  IAssert(ValBf != NULL);
2655  if (EmptyVal != TVal()) { PutAll(EmptyVal); }
2656  } else {
2657  // printf("*** Resize vector pool: %llu -> %llu\n", uint64(Vals), uint64(MxVals));
2658  TVal* NewValBf = NULL;
2659  try { NewValBf = new TVal [MxVals]; }
2660  catch (std::exception Ex) {
2661  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()); }
2662  IAssert(NewValBf != NULL);
2663  if (FastCopy) {
2664  memcpy(NewValBf, ValBf, Vals*sizeof(TVal)); }
2665  else {
2666  for (TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
2667  if (EmptyVal != TVal()) { // init empty values
2668  for (TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
2669  }
2670  delete [] ValBf;
2671  ValBf = NewValBf;
2672  }
2673 }
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: dt.h:1104
TVal * ValBf
Definition: ds.h:2559
TVal EmptyVal
Definition: ds.h:2558
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:2642
#define FailR(Reason)
Definition: bd.h:240
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TBool FastCopy
Definition: ds.h:2556
char * CStr()
Definition: dt.h:476
TSize Vals
Definition: ds.h:2557
TSize MxVals
Definition: ds.h:2557
template<class TVal , class TSizeTy >
void TVecPool< TVal, TSizeTy >::Save ( TSOut SOut) const

Definition at line 2712 of file ds.h.

2712  {
2713  SOut.Save(FastCopy);
2714  uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
2715  SOut.Save(_GrowBy); SOut.Save(_MxVals); SOut.Save(_Vals);
2716  SOut.Save(EmptyVal);
2717  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
2718  { SOut.Save(IdToOffV.Len()); SOut.Save(IdToOffV.Len());
2719  for (int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
2720  const uint64 Offset=IdToOffV[ValN]; SOut.Save(Offset);
2721  } }
2722 }
TVal * ValBf
Definition: ds.h:2559
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TSize GrowBy
Definition: ds.h:2557
TVal EmptyVal
Definition: ds.h:2558
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:2556
TVec< uint64, int > IdToOffV
Definition: ds.h:2560
TSize Vals
Definition: ds.h:2557
TSize MxVals
Definition: ds.h:2557
template<class TVal, class TSizeTy = int>
void TVecPool< TVal, TSizeTy >::SetEmptyVal ( const TVal &  _EmptyVal)
inline

Sets the empty value.

Definition at line 2594 of file ds.h.

2594 { EmptyVal = _EmptyVal; }
TVal EmptyVal
Definition: ds.h:2558
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 2796 of file ds.h.

2796  {
2797  for (::TSize n = Vals-1; n > 0; n--) {
2798  const ::TSize k = ::TSize(((uint64(Rnd.GetUniDevInt())<<32) | uint64(Rnd.GetUniDevInt())) % (n+1));
2799  const TVal Tmp = ValBf[n];
2800  ValBf[n] = ValBf[k];
2801  ValBf[k] = Tmp;
2802  }
2803 }
TVal * ValBf
Definition: ds.h:2559
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:2557

Friends And Related Function Documentation

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

Definition at line 2644 of file ds.h.

Member Data Documentation

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

Definition at line 2555 of file ds.h.

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

Definition at line 2558 of file ds.h.

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

Definition at line 2556 of file ds.h.

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

Definition at line 2557 of file ds.h.

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

Definition at line 2560 of file ds.h.

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

Definition at line 2557 of file ds.h.

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

Definition at line 2559 of file ds.h.

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

Definition at line 2557 of file ds.h.


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