SNAP Library 6.0, User 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.
TVecPool< TVal, TSizeTy >::TVecPool | ( | const TVecPool< TVal, TSizeTy > & | Pool | ) |
Definition at line 1805 of file ds.h.
int TVecPool< TVal, TSizeTy >::AddEmptyV | ( | const int & | ValVLen | ) |
|
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
.
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.
|
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.
|
inline |
|
inline |
|
inline |
|
inline |
Tests whether vector of id VId
is in the pool.
|
inlinestatic |
|
inlinestatic |
TVecPool< TVal, TSizeTy > & TVecPool< TVal, TSizeTy >::operator= | ( | const TVecPool< TVal, TSizeTy > & | Pool | ) |
|
inline |
|
inline |
Sets the values of vector VId
with those in ValV
.
Definition at line 1741 of file ds.h.
|
inline |
|
inline |
|
private |
Definition at line 1771 of file ds.h.
|
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.
|
private |
|
private |