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
|
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 |
TVecPool & | operator= (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 > > |
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.
TVecPool< TVal, TSizeTy >::TVecPool | ( | const TSize & | ExpectVals = 0 , |
const TSize & | _GrowBy = 1000000 , |
||
const bool & | _FastCopy = false , |
||
const TVal & | _EmptyVal = TVal() |
||
) |
Vector pool constructor.
ExpectVals | At creation the pool allocates enough memory for storing the total of ExpectVals elements (not vectors). |
_GrowBy | Whenever the size of the pool needs to be expanded, it will be expanded to be able to store additional _GrowBy elements. |
_FastCopy | If 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. |
_EmptyVal | Empty (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().
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.
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.
int TVecPool< TVal, TSizeTy >::AddEmptyV | ( | const int & | ValVLen | ) |
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.
|
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().
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.
|
inline |
|
inline |
Returns the total memory footprint (in bytes) of the pool.
|
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.
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().
|
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().
|
inline |
|
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().
|
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().
|
inlinestatic |
|
inlinestatic |
Definition at line 1634 of file ds.h.
Referenced by TVecPool< TInt >::Load().
|
inlinestatic |
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.
|
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().
|
inline |
Sets the values of vector VId
with those in ValV
.
Definition at line 1675 of file ds.h.
|
inline |
|
inline |
|
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().
Definition at line 1769 of file ds.h.
References TSOut::Save().
Referenced by TBigNet< TNodeData, IsDir >::SaveToDisk().
|
inline |
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().
|
private |
Definition at line 1615 of file ds.h.
Referenced by TVecPool< TInt >::Clr(), TVecPool< TInt >::GetEmptyVal(), TVecPool< TInt >::GetValVPt(), TVecPool< TVal, TSizeTy >::operator=(), TVecPool< TInt >::SetEmptyVal(), and TVecPool< TVal, TSizeTy >::TVecPool().
Definition at line 1613 of file ds.h.
Referenced by TVecPool< TInt >::New(), TVecPool< TVal, TSizeTy >::operator=(), TVecPool< TInt >::PutV(), and TVecPool< TVal, TSizeTy >::TVecPool().
Definition at line 1614 of file ds.h.
Referenced by TVecPool< TInt >::New(), TVecPool< TVal, TSizeTy >::operator=(), and TVecPool< TVal, TSizeTy >::TVecPool().
|
private |
Definition at line 1617 of file ds.h.
Referenced by TVecPool< TInt >::Clr(), TVecPool< TInt >::GetValVPt(), TVecPool< TInt >::GetVecs(), TVecPool< TInt >::GetVLen(), TVecPool< TInt >::IsVId(), TVecPool< TVal, TSizeTy >::operator=(), and TVecPool< TVal, TSizeTy >::TVecPool().
Definition at line 1614 of file ds.h.
Referenced by TVecPool< TInt >::Clr(), TVecPool< TInt >::GetMemUsed(), TVecPool< TVal, TSizeTy >::operator=(), TVecPool< TInt >::PutAll(), TVecPool< TInt >::Reserved(), and TVecPool< TVal, TSizeTy >::TVecPool().
|
private |
Definition at line 1616 of file ds.h.
Referenced by TVecPool< TInt >::Clr(), TVecPool< TInt >::GetValVPt(), TVecPool< TVal, TSizeTy >::operator=(), TVecPool< TInt >::PutAll(), TVecPool< TVal, TSizeTy >::TVecPool(), and TVecPool< TInt >::~TVecPool().
Definition at line 1614 of file ds.h.
Referenced by TVecPool< TInt >::Clr(), TVecPool< TInt >::GetVals(), TVecPool< TVal, TSizeTy >::operator=(), and TVecPool< TVal, TSizeTy >::TVecPool().