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
|
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 1799 of file ds.h.
References TVec< TVal, TSizeTy >::Add(), 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 1805 of file ds.h.
References TStr::CStr(), FailR, TStr::Fmt(), TInt::GetStr(), IAssert, TVecPool< TVal, TSizeTy >::MxVals, and TVecPool< TVal, TSizeTy >::ValBf.
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.
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().
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().
|
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().
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().
|
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.
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().
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().
|
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().
|
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().
|
inline |
Returns the number of elements in the vector with id VId
.
Definition at line 1729 of file ds.h.
Referenced by TBigNet< TNodeData, IsDir >::AddEdge(), TNGraphMP::AddNode(), TUNGraph::AddNode(), TNGraph::AddNode(), TUndirNet::AddNode(), TDirNet::AddNode(), TBigNet< TNodeData, IsDir >::TNodeI::GetInOutNIdV(), TVecPool< TInt >::GetV(), TVecPool< TInt >::GetValVPt(), TBigNet< TNodeData, IsDir >::IsEdge(), TBigNet< TNodeData, IsDir >::IsOk(), TBigNet< TNodeData, IsDir >::IsolateNode(), TVecPool< TInt >::PutV(), and TBigNet< TNodeData, IsDir >::Rewire().
|
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().
|
inlinestatic |
|
inlinestatic |
Definition at line 1700 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 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.
|
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().
|
inline |
Sets the values of vector VId
with those in ValV
.
Definition at line 1741 of file ds.h.
|
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().
|
inline |
Returns the total capacity of the pool.
Definition at line 1711 of file ds.h.
Referenced by TBigNet< TNodeData, IsDir >::InvertFromSources().
|
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().
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().
|
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 1919 of file ds.h.
References TRnd::GetUniDevInt().
Referenced by TBigNet< TNodeData, IsDir >::Rewire().
|
private |
Definition at line 1681 of file ds.h.
Referenced by TVecPool< TInt >::GetEmptyVal(), TVecPool< TInt >::GetValVPt(), and TVecPool< TVal, TSizeTy >::operator=().
Definition at line 1679 of file ds.h.
Referenced by TVecPool< TVal, TSizeTy >::operator=().
Definition at line 1680 of file ds.h.
Referenced by TVecPool< TVal, TSizeTy >::operator=().
|
private |
Definition at line 1683 of file ds.h.
Referenced by TVecPool< TVal, TSizeTy >::operator=().
Definition at line 1680 of file ds.h.
Referenced by TVecPool< TVal, TSizeTy >::operator=(), TVecPool< TInt >::PutAll(), TVecPool< TInt >::Reserved(), and TVecPool< TVal, TSizeTy >::TVecPool().
|
private |
Definition at line 1682 of file ds.h.
Referenced by TVecPool< TInt >::Clr(), TVecPool< TVal, TSizeTy >::operator=(), TVecPool< TVal, TSizeTy >::TVecPool(), and TVecPool< TInt >::~TVecPool().
Definition at line 1680 of file ds.h.
Referenced by TVecPool< TInt >::GetVals(), TVecPool< TVal, TSizeTy >::operator=(), and TVecPool< TVal, TSizeTy >::TVecPool().