| 
    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 
   | 
  
  
  
 
#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 > > | 
| typedef TPt<TVecPool<TVal> > TGLib_OLD::TVecPool< TVal >::PVecPool | 
| typedef TVec<TVal> TGLib_OLD::TVecPool< TVal >::TValV | 
| 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); }


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]; } } }

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

| TGLib_OLD::TVecPool< TVal >::~TVecPool | ( | ) |  [inline] | 
        
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;
}

| void TGLib_OLD::TVecPool< TVal >::Clr | ( | bool | DoDel = true | ) |  [inline] | 
        
Definition at line 2862 of file ds.h.
References TGLib_OLD::TVec< TVal >::Clr(), TGLib_OLD::TVecPool< TVal >::EmptyVal, TGLib_OLD::TVecPool< TVal >::IdToOffV, TGLib_OLD::TVecPool< TVal >::MxVals, TGLib_OLD::TVecPool< TVal >::PutAll(), TGLib_OLD::TVecPool< TVal >::ValBf, and TGLib_OLD::TVecPool< TVal >::Vals.
                              {
    IdToOffV.Clr(DoDel);  MxVals=0;  Vals=0;
    if (DoDel && ValBf!=NULL) { delete [] ValBf; ValBf=NULL;}
    if (! DoDel) { PutAll(EmptyVal); }
  }

| 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);
}
| 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; }
| ::TSize TGLib_OLD::TVecPool< TVal >::GetMemUsed | ( | ) |  const [inline] | 
        
| 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().

| ::TSize TGLib_OLD::TVecPool< TVal >::GetVals | ( | ) |  const [inline] | 
        
Definition at line 2828 of file ds.h.
References TGLib_OLD::TVecPool< TVal >::Vals.
{ return Vals; }
| 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().


| ::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().

| 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().

| 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().


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

| 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().


| 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().

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

| 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().

| 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]; }
    }
  }

| void TGLib_OLD::TVecPool< TVal >::Reserve | ( | const ::TSize & | MxVals | ) |  [inline] | 
        
Definition at line 2832 of file ds.h.
References TGLib_OLD::TVecPool< TVal >::Resize().

| ::TSize TGLib_OLD::TVecPool< TVal >::Reserved | ( | ) |  const [inline] | 
        
Definition at line 2831 of file ds.h.
References TGLib_OLD::TVecPool< TVal >::MxVals.
{ return MxVals; }
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;
  }
}


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

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

TCRef TGLib_OLD::TVecPool< TVal >::CRef [private] | 
        
TVal TGLib_OLD::TVecPool< TVal >::EmptyVal [private] | 
        
Definition at line 2810 of file ds.h.
Referenced by TGLib_OLD::TVecPool< TVal >::Clr(), TGLib_OLD::TVecPool< TVal >::GetEmptyVal(), TGLib_OLD::TVecPool< TVal >::GetValVPt(), TGLib_OLD::TVecPool< TVal >::operator=(), TGLib_OLD::TVecPool< TVal >::SetEmptyVal(), and TGLib_OLD::TVecPool< TVal >::TVecPool().
TBool TGLib_OLD::TVecPool< TVal >::FastCopy [private] | 
        
Definition at line 2808 of file ds.h.
Referenced by TGLib_OLD::TVecPool< TVal >::New(), TGLib_OLD::TVecPool< TVal >::operator=(), TGLib_OLD::TVecPool< TVal >::PutV(), and TGLib_OLD::TVecPool< TVal >::TVecPool().
::TSize TGLib_OLD::TVecPool< TVal >::GrowBy [private] | 
        
Definition at line 2809 of file ds.h.
Referenced by TGLib_OLD::TVecPool< TVal >::New(), TGLib_OLD::TVecPool< TVal >::operator=(), and TGLib_OLD::TVecPool< TVal >::TVecPool().
TVec< ::TSize> TGLib_OLD::TVecPool< TVal >::IdToOffV [private] | 
        
Definition at line 2812 of file ds.h.
Referenced by TGLib_OLD::TVecPool< TVal >::Clr(), TGLib_OLD::TVecPool< TVal >::GetValVPt(), TGLib_OLD::TVecPool< TVal >::GetVecs(), TGLib_OLD::TVecPool< TVal >::GetVLen(), TGLib_OLD::TVecPool< TVal >::IsVId(), TGLib_OLD::TVecPool< TVal >::operator=(), and TGLib_OLD::TVecPool< TVal >::TVecPool().
::TSize TGLib_OLD::TVecPool< TVal >::MxVals [private] | 
        
TVal* TGLib_OLD::TVecPool< TVal >::ValBf [private] | 
        
::TSize TGLib_OLD::TVecPool< TVal >::Vals [private] | 
        
Definition at line 2809 of file ds.h.
Referenced by TGLib_OLD::TVecPool< TVal >::Clr(), TGLib_OLD::TVecPool< TVal >::GetVals(), TGLib_OLD::TVecPool< TVal >::operator=(), and TGLib_OLD::TVecPool< TVal >::TVecPool().