SNAP Library 2.0, Developer Reference  2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TGLib_OLD::TVecPool< TVal > Class Template Reference

#include <ds.h>

Collaboration diagram for TGLib_OLD::TVecPool< TVal >:

List of all members.

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
TVecPooloperator= (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< ::TSizeIdToOffV

Friends

class TPt< TVecPool< TVal > >

Detailed Description

template<class TVal>
class TGLib_OLD::TVecPool< TVal >

Definition at line 2802 of file ds.h.


Member Typedef Documentation

template<class TVal >
typedef TPt<TVecPool<TVal> > TGLib_OLD::TVecPool< TVal >::PVecPool

Definition at line 2804 of file ds.h.

template<class TVal >
typedef TVec<TVal> TGLib_OLD::TVecPool< TVal >::TValV

Definition at line 2805 of file ds.h.


Constructor & Destructor Documentation

template<class TVal >
TVecPool< TVal >::TVecPool ( const ::TSize ExpectVals = 0,
const ::TSize _GrowBy = 1000000,
const bool &  _FastCopy = false,
const TVal &  _EmptyVal = TVal() 
)

Definition at line 2901 of file ds.h.

References TGLib_OLD::TVec< TVal >::Add(), TGLib_OLD::TVecPool< TVal >::IdToOffV, and TGLib_OLD::TVecPool< TVal >::Resize().

Referenced by TGLib_OLD::TVecPool< TVal >::Load(), and TGLib_OLD::TVecPool< TVal >::New().

                                                                                                                    :
  GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
  IdToOffV.Add(0);
  Resize(ExpectVals);
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal >
TVecPool< TVal >::TVecPool ( const TVecPool< TVal > &  Pool)

Definition at line 2908 of file ds.h.

References FailR, TGLib_OLD::TVecPool< TVal >::FastCopy, TStr::Fmt(), IAssert, TGLib_OLD::TVecPool< TVal >::MxVals, and TGLib_OLD::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]; } }
}

Here is the call graph for this function:

template<class TVal >
TVecPool< TVal >::TVecPool ( TSIn SIn)

Definition at line 2921 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::EmptyVal, TGLib_OLD::TVec< TVal >::Gen(), TGLib_OLD::TVecPool< TVal >::GrowBy, IAssert, TGLib_OLD::TVecPool< TVal >::IdToOffV, TSIn::Load(), TGLib_OLD::TVecPool< TVal >::MxVals, TSizeMx, TGLib_OLD::TVecPool< TVal >::ValBf, and TGLib_OLD::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);
  } }
}

Here is the call graph for this function:

template<class TVal >
TGLib_OLD::TVecPool< TVal >::~TVecPool ( ) [inline]

Definition at line 2819 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::ValBf.

{ if (ValBf != NULL) { delete [] ValBf; } ValBf=NULL; }

Member Function Documentation

template<class TVal >
int TVecPool< TVal >::AddEmptyV ( const int &  ValVLen)

Definition at line 2983 of file ds.h.

References max.

                                                {
  if (ValVLen==0){return 0;}
  if (MxVals < Vals+ValVLen){Resize(Vals+max(TSize(ValVLen), GrowBy)); }
  Vals+=ValVLen; IdToOffV.Add(Vals);
  return IdToOffV.Len()-1;
}
template<class TVal >
int TVecPool< TVal >::AddV ( const TValV ValV)

Definition at line 2972 of file ds.h.

References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::BegI(), TVec< TVal, TSizeTy >::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;
}

Here is the call graph for this function:

template<class TVal >
void TGLib_OLD::TVecPool< TVal >::Clr ( bool  DoDel = true) [inline]
template<class TVal >
void TVecPool< TVal >::CompactPool ( const TVal &  DelVal)

Definition at line 2993 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);
}
template<class TVal >
const TVal& TGLib_OLD::TVecPool< TVal >::GetEmptyVal ( ) const [inline]

Definition at line 2833 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::EmptyVal.

{ return EmptyVal; }
template<class TVal >
::TSize TGLib_OLD::TVecPool< TVal >::GetMemUsed ( ) const [inline]

Definition at line 2835 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::MxVals.

                           {
    return sizeof(TCRef)+sizeof(TBool)+3*sizeof(TSize)+sizeof(TVal*)+MxVals*sizeof(TVal);}
template<class TVal >
void TGLib_OLD::TVecPool< TVal >::GetV ( const int &  VId,
TValV ValV 
) const [inline]

Definition at line 2846 of file ds.h.

References TVec< TVal, TSizeTy >::Clr(), TVec< TVal, TSizeTy >::GenExt(), TGLib_OLD::TVecPool< TVal >::GetValVPt(), and TGLib_OLD::TVecPool< TVal >::GetVLen().

                                               {
    if (GetVLen(VId)==0){ValV.Clr();}
    else { ValV.GenExt(GetValVPt(VId), GetVLen(VId)); } }

Here is the call graph for this function:

template<class TVal >
::TSize TGLib_OLD::TVecPool< TVal >::GetVals ( ) const [inline]

Definition at line 2828 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::Vals.

{ return Vals; }
template<class TVal >
TVal* TGLib_OLD::TVecPool< TVal >::GetValVPt ( const int &  VId) const [inline]

Definition at line 2843 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::EmptyVal, TGLib_OLD::TVecPool< TVal >::GetVLen(), TGLib_OLD::TVecPool< TVal >::IdToOffV, and TGLib_OLD::TVecPool< TVal >::ValBf.

Referenced by TGLib_OLD::TVecPool< TVal >::GetV(), and TGLib_OLD::TVecPool< TVal >::PutV().

                                        {
    if (GetVLen(VId)==0){return (TVal*)&EmptyVal;}
    else {return ValBf+IdToOffV[VId-1];}}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal >
::TSize TGLib_OLD::TVecPool< TVal >::GetVecs ( ) const [inline]

Definition at line 2829 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::IdToOffV, and TGLib_OLD::TVec< TVal >::Len().

{ return IdToOffV.Len(); }

Here is the call graph for this function:

template<class TVal >
uint TGLib_OLD::TVecPool< TVal >::GetVLen ( const int &  VId) const [inline]

Definition at line 2840 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::IdToOffV.

Referenced by TGLib_OLD::TVecPool< TVal >::GetV(), TGLib_OLD::TVecPool< TVal >::GetValVPt(), and TGLib_OLD::TVecPool< TVal >::PutV().

                                     {
    if (VId==0){return 0;}
    else {return uint(IdToOffV[VId]-IdToOffV[VId-1]);}}

Here is the caller graph for this function:

template<class TVal >
bool TGLib_OLD::TVecPool< TVal >::IsVId ( const int &  VId) const [inline]

Definition at line 2830 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::IdToOffV, and TGLib_OLD::TVec< TVal >::Len().

Referenced by TGLib_OLD::TVecPool< TVal >::PutV().

{ return (0 <= VId) && (VId < IdToOffV.Len()); }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal >
static PVecPool TGLib_OLD::TVecPool< TVal >::Load ( TSIn SIn) [inline, static]

Definition at line 2822 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::TVecPool().

{ return new TVecPool(SIn); }

Here is the call graph for this function:

template<class TVal >
static PVecPool TGLib_OLD::TVecPool< TVal >::Load ( const TStr FNm) [inline, static]

Definition at line 2823 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::Load().

Referenced by TGLib_OLD::TVecPool< TVal >::Load().

{ TFIn FIn(FNm); return Load(FIn); }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal >
static PVecPool TGLib_OLD::TVecPool< TVal >::New ( const ::TSize ExpectVals = 0,
const ::TSize GrowBy = 1000000,
const bool &  FastCopy = false 
) [inline, static]

Definition at line 2820 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::FastCopy, TGLib_OLD::TVecPool< TVal >::GrowBy, and TGLib_OLD::TVecPool< TVal >::TVecPool().

                                                                                                          {
    return new TVecPool(ExpectVals, GrowBy, FastCopy); }

Here is the call graph for this function:

template<class TVal >
TVecPool< TVal > & TVecPool< TVal >::operator= ( const TVecPool< TVal > &  Pool)

Definition at line 2952 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::EmptyVal, FailR, TGLib_OLD::TVecPool< TVal >::FastCopy, TStr::Fmt(), TGLib_OLD::TVecPool< TVal >::GrowBy, IAssert, TGLib_OLD::TVecPool< TVal >::IdToOffV, TGLib_OLD::TVecPool< TVal >::MxVals, TGLib_OLD::TVecPool< TVal >::ValBf, and TGLib_OLD::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;
}

Here is the call graph for this function:

template<class TVal >
void TGLib_OLD::TVecPool< TVal >::PutAll ( const TVal &  Val) [inline]

Definition at line 2867 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::MxVals, and TGLib_OLD::TVecPool< TVal >::ValBf.

Referenced by TGLib_OLD::TVecPool< TVal >::Clr().

                               {
    for (TSize ValN = 0; ValN < MxVals; ValN++) { ValBf[ValN]=Val; } }

Here is the caller graph for this function:

template<class TVal >
void TGLib_OLD::TVecPool< TVal >::PutV ( const int &  VId,
const TValV ValV 
) [inline]

Definition at line 2849 of file ds.h.

References TVec< TVal, TSizeTy >::BegI(), TGLib_OLD::TVecPool< TVal >::FastCopy, TGLib_OLD::TVecPool< TVal >::GetValVPt(), TGLib_OLD::TVecPool< TVal >::GetVLen(), IAssert, TGLib_OLD::TVecPool< TVal >::IsVId(), and TVec< TVal, TSizeTy >::Len().

                                               {
    IAssert(IsVId(VId) && GetVLen(VId) == ValV.Len());
    if (FastCopy) {
      memcpy(GetValVPt(VId), ValV.BegI(), sizeof(TVal)*ValV.Len()); }
    else { TVal* ValPt = GetValVPt(VId);
      for (uint ValN=0; ValN < uint(ValV.Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
    }
  }

Here is the call graph for this function:

template<class TVal >
void TGLib_OLD::TVecPool< TVal >::Reserve ( const ::TSize MxVals) [inline]

Definition at line 2832 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::Resize().

{ Resize(MxVals); }

Here is the call graph for this function:

template<class TVal >
::TSize TGLib_OLD::TVecPool< TVal >::Reserved ( ) const [inline]

Definition at line 2831 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::MxVals.

{ return MxVals; }
template<class TVal >
void TVecPool< TVal >::Resize ( const ::TSize _MxVals) [private]

Definition at line 2874 of file ds.h.

References FailR, TStr::Fmt(), and IAssert.

Referenced by TGLib_OLD::TVecPool< TVal >::Reserve(), and TGLib_OLD::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;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal >
void TVecPool< TVal >::Save ( TSOut SOut) const

Definition at line 2939 of file ds.h.

References TSOut::Save().

                                           {
  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);
  } }
}

Here is the call graph for this function:

template<class TVal >
void TGLib_OLD::TVecPool< TVal >::SetEmptyVal ( const TVal &  _EmptyVal) [inline]

Definition at line 2834 of file ds.h.

References TGLib_OLD::TVecPool< TVal >::EmptyVal.

{ EmptyVal = _EmptyVal; }
template<class TVal >
void TVecPool< TVal >::ShuffleAll ( TRnd Rnd = TInt::Rnd)

Definition at line 3022 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;
  }
}

Here is the call graph for this function:


Friends And Related Function Documentation

template<class TVal >
friend class TPt< TVecPool< TVal > > [friend]

Definition at line 2870 of file ds.h.


Member Data Documentation

template<class TVal >
TCRef TGLib_OLD::TVecPool< TVal >::CRef [private]

Definition at line 2807 of file ds.h.

template<class TVal >
::TSize TGLib_OLD::TVecPool< TVal >::GrowBy [private]

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