|
SNAP Library , Developer Reference
2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <ds.h>

Public Types | |
| typedef TPt< TVecPool< TVal > > | PVecPool |
| typedef TVec< TVal > | TValV |
Public Member Functions | |
| TVecPool (const ::TSize &ExpectVals=0, const ::TSize &_GrowBy=1000000, const bool &_FastCopy=false, const TVal &_EmptyVal=TVal()) | |
| TVecPool (const TVecPool &Pool) | |
| TVecPool (TSIn &SIn) | |
| ~TVecPool () | |
| void | Save (TSOut &SOut) const |
| TVecPool & | operator= (const TVecPool &Pool) |
| ::TSize | GetVals () const |
| ::TSize | GetVecs () const |
| bool | IsVId (const int &VId) const |
| ::TSize | Reserved () const |
| void | Reserve (const ::TSize &MxVals) |
| const TVal & | GetEmptyVal () const |
| void | SetEmptyVal (const TVal &_EmptyVal) |
| ::TSize | GetMemUsed () const |
| int | AddV (const TValV &ValV) |
| int | AddEmptyV (const int &ValVLen) |
| uint | GetVLen (const int &VId) const |
| TVal * | GetValVPt (const int &VId) const |
| void | GetV (const int &VId, TValV &ValV) const |
| void | PutV (const int &VId, const TValV &ValV) |
| void | CompactPool (const TVal &DelVal) |
| void | ShuffleAll (TRnd &Rnd=TInt::Rnd) |
| void | Clr (bool DoDel=true) |
| void | PutAll (const TVal &Val) |
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< ::TSize > | IdToOffV |
Friends | |
| class | TPt< TVecPool< TVal > > |
| TVecPool< TVal >::TVecPool | ( | const ::TSize & | ExpectVals = 0, |
| const ::TSize & | _GrowBy = 1000000, |
||
| const bool & | _FastCopy = false, |
||
| const TVal & | _EmptyVal = TVal() |
||
| ) |
Definition at line 1538 of file ds.h.
References TVec< TVal >::Add(), TVecPool< TVal >::IdToOffV, and TVecPool< TVal >::Resize().
Referenced by TVecPool< TInt >::Load(), and TVecPool< TInt >::New().
: GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) { IdToOffV.Add(0); Resize(ExpectVals); }


Definition at line 1545 of file ds.h.
References FailR, TVecPool< TVal >::FastCopy, TStr::Fmt(), IAssert, TVecPool< TVal >::MxVals, and TVecPool< TVal >::ValBf.
: FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy), MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) { try { ValBf = new TVal [MxVals]; } catch (std::exception Ex) { FailR(TStr::Fmt("TVecPool::TVecPool: %s, MxVals: %d", Ex.what(), MxVals).CStr()); } IAssert(ValBf != NULL); if (FastCopy) { memcpy(ValBf, Pool.ValBf, MxVals*sizeof(TVal)); } else { for (TSize ValN = 0; ValN < MxVals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } } }

Definition at line 1558 of file ds.h.
References TVecPool< TVal >::EmptyVal, TVec< TVal >::Gen(), TVecPool< TVal >::GrowBy, IAssert, TVecPool< TVal >::IdToOffV, TSIn::Load(), TVecPool< TVal >::MxVals, TSizeMx, TVecPool< TVal >::ValBf, and TVecPool< TVal >::Vals.
: FastCopy(SIn) { uint64 _GrowBy, _MxVals, _Vals; SIn.Load(_GrowBy); SIn.Load(_MxVals); SIn.Load(_Vals); IAssert(_GrowBy<TSizeMx && _MxVals<TSizeMx && _Vals<TSizeMx); GrowBy=TSize(_GrowBy); MxVals=TSize(_Vals); Vals=TSize(_Vals); //note MxVals==Vals EmptyVal = TVal(SIn); if (MxVals==0) { ValBf = NULL; } else { ValBf = new TVal [MxVals]; } for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN] = TVal(SIn); } { TInt MxVals(SIn), Vals(SIn); IdToOffV.Gen(Vals); for (int ValN = 0; ValN < Vals; ValN++) { uint64 Offset; SIn.Load(Offset); IAssert(Offset < TSizeMx); IdToOffV[ValN]=TSize(Offset); } } }

Definition at line 1609 of file ds.h.
References TVec< TVal >::Add(), TVec< TVal >::BegI(), TVec< TVal >::Len(), and max.
{
const ::TSize ValVLen = ValV.Len();
if (ValVLen == 0) { return 0; }
if (MxVals < Vals+ValVLen) { Resize(Vals+max(ValVLen, GrowBy)); }
if (FastCopy) { memcpy(ValBf+Vals, ValV.BegI(), sizeof(TVal)*ValV.Len()); }
else { for (uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
Vals+=ValVLen; IdToOffV.Add(Vals);
return IdToOffV.Len()-1;
}

| void TVecPool< TVal >::CompactPool | ( | const TVal & | DelVal | ) |
Definition at line 1630 of file ds.h.
{
::TSize TotalDel=0, NDel=0;
// printf("Compacting %d vectors\n", IdToOffV.Len());
for (int vid = 1; vid < IdToOffV.Len(); vid++) {
// if (vid % 10000000 == 0) { printf(" %dm", vid/1000000); fflush(stdout); }
const uint Len = GetVLen(vid);
TVal* ValV = GetValVPt(vid);
if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; } // update end of vector
if (Len == 0) { continue; }
NDel = 0;
for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
if (*v == DelVal) {
TVal* Beg = v;
while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
memcpy(Beg, v, sizeof(TVal)*int(Len - ::TSize(v - ValV)));
v -= NDel;
}
}
memcpy(ValV-TotalDel, ValV, sizeof(TVal)*Len); // move data
TotalDel += NDel;
}
IdToOffV.Last() -= TotalDel;
for (::TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
Vals -= TotalDel;
// printf(" deleted %llu elements from the pool\n", TotalDel);
}
| const TVal& TVecPool< TVal >::GetEmptyVal | ( | ) | const [inline] |
| ::TSize TVecPool< TVal >::GetMemUsed | ( | ) | const [inline] |
Definition at line 1465 of file ds.h.
Referenced by TBigNet< TNodeData, IsDir >::GetEdges().
{ return Vals; }

Definition at line 1480 of file ds.h.
Referenced by TUNGraph::AddNode(), TNGraph::AddNode(), TBigNet< TNodeData, IsDir >::GetInNIdVPt(), TBigNet< TNodeData, IsDir >::TNodeI::GetInOutNIdV(), TBigNet< TNodeData, IsDir >::GetOutNIdVPt(), TVecPool< TInt >::GetV(), and TVecPool< TInt >::PutV().

Definition at line 1477 of file ds.h.
Referenced by TUNGraph::AddNode(), TNGraph::AddNode(), TBigNet< TNodeData, IsDir >::TNodeI::GetInOutNIdV(), TVecPool< TInt >::GetV(), TVecPool< TInt >::GetValVPt(), and TVecPool< TInt >::PutV().

Definition at line 1467 of file ds.h.
Referenced by TBigNet< TNodeData, IsDir >::TNodeI::GetInOutNIdV(), and TVecPool< TInt >::PutV().

Definition at line 1460 of file ds.h.
Referenced by TVecPool< TInt >::Load().

| TVecPool< TVal > & TVecPool< TVal >::operator= | ( | const TVecPool< TVal > & | Pool | ) |
Definition at line 1589 of file ds.h.
References TVecPool< TVal >::EmptyVal, FailR, TVecPool< TVal >::FastCopy, TStr::Fmt(), TVecPool< TVal >::GrowBy, IAssert, TVecPool< TVal >::IdToOffV, TVecPool< TVal >::MxVals, TVecPool< TVal >::ValBf, and TVecPool< TVal >::Vals.
{
if (this!=&Pool) {
FastCopy = Pool.FastCopy;
GrowBy = Pool.GrowBy;
MxVals = Pool.MxVals;
Vals = Pool.Vals;
EmptyVal = Pool.EmptyVal;
IdToOffV=Pool.IdToOffV;
try { ValBf = new TVal [MxVals]; }
catch (std::exception Ex) { FailR(TStr::Fmt("TVec::operator= : %s, MxVals: %d", Ex.what(), MxVals).CStr()); }
IAssert(ValBf != NULL);
if (FastCopy) {
memcpy(ValBf, Pool.ValBf, Vals*sizeof(TVal)); }
else {
for (uint64 ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
}
return *this;
}

Definition at line 1511 of file ds.h.
References FailR, TStr::Fmt(), and IAssert.
Referenced by TVecPool< TInt >::Reserve(), and TVecPool< TVal >::TVecPool().
{
if (_MxVals <= MxVals){ return; } else { MxVals = _MxVals; }
if (ValBf == NULL) {
try { ValBf = new TVal [MxVals]; }
catch (std::exception Ex) {
FailR(TStr::Fmt("TVecPool::Resize 1: %s, MxVals: %d. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), _MxVals).CStr()); }
IAssert(ValBf != NULL);
if (EmptyVal != TVal()) { PutAll(EmptyVal); }
} else {
// printf("*** Resize vector pool: %llu -> %llu\n", uint64(Vals), uint64(MxVals));
TVal* NewValBf = NULL;
try { NewValBf = new TVal [MxVals]; }
catch (std::exception Ex) { FailR(TStr::Fmt("TVecPool::Resize 2: %s, MxVals: %d. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), _MxVals).CStr()); }
IAssert(NewValBf != NULL);
if (FastCopy) {
memcpy(NewValBf, ValBf, Vals*sizeof(TVal)); }
else {
for (TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
if (EmptyVal != TVal()) { // init empty values
for (TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
}
delete [] ValBf;
ValBf = NewValBf;
}
}


Definition at line 1576 of file ds.h.
References TSOut::Save().
Referenced by TBigNet< TNodeData, IsDir >::SaveToDisk().
{
SOut.Save(FastCopy);
uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
SOut.Save(_GrowBy); SOut.Save(_MxVals); SOut.Save(_Vals);
SOut.Save(EmptyVal);
for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
{ SOut.Save(IdToOffV.Len()); SOut.Save(IdToOffV.Len());
for (int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
const uint64 Offset=IdToOffV[ValN]; SOut.Save(Offset);
} }
}


| void TVecPool< TVal >::SetEmptyVal | ( | const TVal & | _EmptyVal | ) | [inline] |
| void TVecPool< TVal >::ShuffleAll | ( | TRnd & | Rnd = TInt::Rnd | ) |
Definition at line 1659 of file ds.h.
References TRnd::GetUniDevInt().
{
for (::TSize n = Vals-1; n > 0; n--) {
const ::TSize k = ::TSize(((uint64(Rnd.GetUniDevInt())<<32) | uint64(Rnd.GetUniDevInt())) % (n+1));
const TVal Tmp = ValBf[n];
ValBf[n] = ValBf[k];
ValBf[k] = Tmp;
}
}

Definition at line 1447 of file ds.h.
Referenced by TVecPool< TInt >::Clr(), TVecPool< TInt >::GetEmptyVal(), TVecPool< TInt >::GetValVPt(), TVecPool< TVal >::operator=(), TVecPool< TInt >::SetEmptyVal(), and TVecPool< TVal >::TVecPool().
Definition at line 1445 of file ds.h.
Referenced by TVecPool< TInt >::New(), TVecPool< TVal >::operator=(), TVecPool< TInt >::PutV(), and TVecPool< TVal >::TVecPool().
Definition at line 1446 of file ds.h.
Referenced by TVecPool< TInt >::New(), TVecPool< TVal >::operator=(), and TVecPool< TVal >::TVecPool().
Definition at line 1449 of file ds.h.
Referenced by TVecPool< TInt >::Clr(), TVecPool< TInt >::GetValVPt(), TVecPool< TInt >::GetVecs(), TVecPool< TInt >::GetVLen(), TVecPool< TInt >::IsVId(), TVecPool< TVal >::operator=(), and TVecPool< TVal >::TVecPool().
Definition at line 1446 of file ds.h.
Referenced by TVecPool< TInt >::Clr(), TVecPool< TInt >::GetMemUsed(), TVecPool< TVal >::operator=(), TVecPool< TInt >::PutAll(), TVecPool< TInt >::Reserved(), and TVecPool< TVal >::TVecPool().
Definition at line 1448 of file ds.h.
Referenced by TVecPool< TInt >::Clr(), TVecPool< TInt >::GetValVPt(), TVecPool< TVal >::operator=(), TVecPool< TInt >::PutAll(), TVecPool< TVal >::TVecPool(), and TVecPool< TInt >::~TVecPool().
Definition at line 1446 of file ds.h.
Referenced by TVecPool< TInt >::Clr(), TVecPool< TInt >::GetVals(), TVecPool< TVal >::operator=(), and TVecPool< TVal >::TVecPool().