SNAP Library 2.2, User Reference  2014-03-11 19:15:55
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
TSparseTable< TVal, GroupSize > Class Template Reference

#include <shash.h>

List of all members.

Public Types

typedef TSparseGroup< TVal,
GroupSize > 
TSGroup
typedef TSparseTableI< TVal,
GroupSize > 
TIter

Public Member Functions

 TSparseTable (const int &MaxVals=0)
 TSparseTable (const TSparseTable &ST)
 TSparseTable (TSIn &SIn)
void Load (TSIn &SIn)
void Save (TSOut &SOut) const
TSparseTableoperator= (const TSparseTable &ST)
bool operator== (const TSparseTable &ST) const
bool operator< (const TSparseTable &ST) const
::TSize GetMemUsed () const
TIter BegI () const
TIter EndI () const
TIter GetI (const int &ValN) const
int Len () const
int Reserved () const
int Groups () const
bool Empty () const
uint GetDiskSz () const
void Clr (const bool &DoDel=true)
void Reserve (const int NewVals)
void Resize (const int &NewVals)
void Swap (TSparseTable &ST)
bool IsEmpty (const int &ValN) const
const TVal & Get (const int &ValN) const
TVal & Set (const int &ValN, const TVal &Val)
TVal & Set (const int &ValN)
void Del (const int &ValN)
TSGroupGetGroup (const int &GroupN)
const TSGroupGetGroup (const int &GroupN) const

Private Member Functions

int PosInGroup (const int &ValN) const
int GroupNum (const int &ValN) const
const TSGroupGetGrp1 (const int &ValN) const
TSGroupGetGrp1 (const int &ValN)

Static Private Member Functions

static int GetGroups (const int &Vals)

Private Attributes

TInt MxVals
TInt Vals
TVec< TSGroupGroupV

Detailed Description

template<class TVal, uint16 GroupSize = 48>
class TSparseTable< TVal, GroupSize >

Definition at line 310 of file shash.h.


Member Typedef Documentation

template<class TVal, uint16 GroupSize = 48>
typedef TSparseTableI<TVal, GroupSize> TSparseTable< TVal, GroupSize >::TIter

Definition at line 313 of file shash.h.

template<class TVal, uint16 GroupSize = 48>
typedef TSparseGroup<TVal, GroupSize> TSparseTable< TVal, GroupSize >::TSGroup

Definition at line 312 of file shash.h.


Constructor & Destructor Documentation

template<class TVal, uint16 GroupSize = 48>
TSparseTable< TVal, GroupSize >::TSparseTable ( const int &  MaxVals = 0) [inline]

Definition at line 324 of file shash.h.

                                       : MxVals(MaxVals),
    Vals(0), GroupV(GetGroups(MaxVals), GetGroups(MaxVals)) { }
template<class TVal, uint16 GroupSize = 48>
TSparseTable< TVal, GroupSize >::TSparseTable ( const TSparseTable< TVal, GroupSize > &  ST) [inline]

Definition at line 326 of file shash.h.

: MxVals(ST.MxVals), Vals(ST.Vals), GroupV(ST.GroupV) { }
template<class TVal, uint16 GroupSize = 48>
TSparseTable< TVal, GroupSize >::TSparseTable ( TSIn SIn) [inline]

Definition at line 327 of file shash.h.

: MxVals(SIn), Vals(SIn), GroupV(SIn) { }

Member Function Documentation

template<class TVal, uint16 GroupSize = 48>
TIter TSparseTable< TVal, GroupSize >::BegI ( ) const [inline]

Definition at line 336 of file shash.h.

                     {
    if (Len() > 0) { int B = 0;
      while (B < Groups() && GroupV[B].Empty()) { B++; }
      return TIter(GroupV.BegI(), GroupV.BegI()+B, GroupV.EndI()); }
    return TIter(GroupV.BegI(), GroupV.EndI(), GroupV.EndI());
  }
template<class TVal , uint16 GroupSize>
void TSparseTable< TVal, GroupSize >::Clr ( const bool &  DoDel = true)

Definition at line 392 of file shash.h.

                                                         {
  if (! DoDel) {
    for (int g = 0; g < GroupV.Len(); g++) GroupV[g].Clr(false);
  } else {
    MxVals = 0;
    GroupV.Clr(true);
  }
  Vals = 0;
}
template<class TVal , uint16 GroupSize>
void TSparseTable< TVal, GroupSize >::Del ( const int &  ValN)

Definition at line 440 of file shash.h.

                                                       {
  Assert(ValN < MxVals);
  TSGroup& Group = GetGrp1(ValN);
  const int OldVals = Group.Len();
  Group.Del(PosInGroup(ValN));
  Vals += Group.Len() - OldVals;
}
template<class TVal, uint16 GroupSize = 48>
bool TSparseTable< TVal, GroupSize >::Empty ( ) const [inline]

Definition at line 352 of file shash.h.

{ return Vals == 0; }
template<class TVal, uint16 GroupSize = 48>
TIter TSparseTable< TVal, GroupSize >::EndI ( ) const [inline]

Definition at line 342 of file shash.h.

{ return TIter(GroupV.BegI(), GroupV.EndI(), GroupV.EndI()); }
template<class TVal, uint16 GroupSize = 48>
const TVal& TSparseTable< TVal, GroupSize >::Get ( const int &  ValN) const [inline]

Definition at line 362 of file shash.h.

{ return GroupV[GroupNum(ValN)].Get(PosInGroup(ValN)); }
template<class TVal, uint16 GroupSize = 48>
uint TSparseTable< TVal, GroupSize >::GetDiskSz ( ) const [inline]

Definition at line 353 of file shash.h.

                         {
    return sizeof(TInt)*4 + ((GroupSize+16)/8)*Groups() + sizeof(TVal)*Vals; }
template<class TVal, uint16 GroupSize = 48>
TSGroup& TSparseTable< TVal, GroupSize >::GetGroup ( const int &  GroupN) [inline]

Definition at line 367 of file shash.h.

{ return GroupV[GroupN]; }
template<class TVal, uint16 GroupSize = 48>
const TSGroup& TSparseTable< TVal, GroupSize >::GetGroup ( const int &  GroupN) const [inline]

Definition at line 368 of file shash.h.

{ return GroupV[GroupN]; }
template<class TVal, uint16 GroupSize = 48>
static int TSparseTable< TVal, GroupSize >::GetGroups ( const int &  Vals) [inline, static, private]

Definition at line 318 of file shash.h.

{ return Vals == 0 ? 0 : ((Vals-1) / GroupSize) + 1; }
template<class TVal, uint16 GroupSize = 48>
const TSGroup& TSparseTable< TVal, GroupSize >::GetGrp1 ( const int &  ValN) const [inline, private]

Definition at line 321 of file shash.h.

{ return GroupV[GroupNum(ValN)]; }
template<class TVal, uint16 GroupSize = 48>
TSGroup& TSparseTable< TVal, GroupSize >::GetGrp1 ( const int &  ValN) [inline, private]

Definition at line 322 of file shash.h.

{ return GroupV[GroupNum(ValN)]; }
template<class TVal, uint16 GroupSize = 48>
TIter TSparseTable< TVal, GroupSize >::GetI ( const int &  ValN) const [inline]

Definition at line 343 of file shash.h.

                                    { Assert(! IsEmpty(ValN));
    typedef typename TVec<TSGroup>::TIter TVIter;
    const TVIter GI = GroupV.GetI(GroupNum(ValN));
    return TIter(GroupV.BegI(), GI, GroupV.EndI(), GI->PosToOffset(PosInGroup(ValN)));
  }
template<class TVal, uint16 GroupSize = 48>
::TSize TSparseTable< TVal, GroupSize >::GetMemUsed ( ) const [inline]

Definition at line 334 of file shash.h.

{ return 2*sizeof(TInt)+Vals*sizeof(TVal)+GroupV.GetMemUsed(); }
template<class TVal, uint16 GroupSize = 48>
int TSparseTable< TVal, GroupSize >::GroupNum ( const int &  ValN) const [inline, private]

Definition at line 320 of file shash.h.

{ return ValN / GroupSize; }
template<class TVal, uint16 GroupSize = 48>
int TSparseTable< TVal, GroupSize >::Groups ( ) const [inline]

Definition at line 351 of file shash.h.

{ return GroupV.Len(); }
template<class TVal, uint16 GroupSize = 48>
bool TSparseTable< TVal, GroupSize >::IsEmpty ( const int &  ValN) const [inline]

Definition at line 361 of file shash.h.

{ return GroupV[GroupNum(ValN)].IsEmpty(PosInGroup(ValN)); }
template<class TVal, uint16 GroupSize = 48>
int TSparseTable< TVal, GroupSize >::Len ( ) const [inline]

Definition at line 349 of file shash.h.

{ return Vals; }
template<class TVal, uint16 GroupSize = 48>
void TSparseTable< TVal, GroupSize >::Load ( TSIn SIn) [inline]

Definition at line 328 of file shash.h.

{ MxVals.Load(SIn);  Vals.Load(SIn);  GroupV.Load(SIn); }
template<class TVal , uint16 GroupSize>
bool TSparseTable< TVal, GroupSize >::operator< ( const TSparseTable< TVal, GroupSize > &  ST) const

Definition at line 387 of file shash.h.

                                                                            {
  return Vals < ST.Vals || (Vals == ST.Vals && GroupV < ST.GroupV);
}
template<class TVal , uint16 GroupSize>
TSparseTable< TVal, GroupSize > & TSparseTable< TVal, GroupSize >::operator= ( const TSparseTable< TVal, GroupSize > &  ST)

Definition at line 372 of file shash.h.

                                                                                                {
  if (this != &ST) {
    MxVals = ST.MxVals;
    Vals = ST.Vals;
    GroupV = ST.GroupV;
  }
  return *this;
}
template<class TVal , uint16 GroupSize>
bool TSparseTable< TVal, GroupSize >::operator== ( const TSparseTable< TVal, GroupSize > &  ST) const

Definition at line 382 of file shash.h.

                                                                             {
  return Vals == ST.Vals && MxVals == ST.MxVals && GroupV == ST.GroupV;
}
template<class TVal, uint16 GroupSize = 48>
int TSparseTable< TVal, GroupSize >::PosInGroup ( const int &  ValN) const [inline, private]

Definition at line 319 of file shash.h.

{ return ValN % GroupSize; }
template<class TVal, uint16 GroupSize = 48>
void TSparseTable< TVal, GroupSize >::Reserve ( const int  NewVals) [inline]

Definition at line 357 of file shash.h.

{ Resize(NewVals); }
template<class TVal, uint16 GroupSize = 48>
int TSparseTable< TVal, GroupSize >::Reserved ( ) const [inline]

Definition at line 350 of file shash.h.

{ return MxVals; }
template<class TVal , uint16 GroupSize>
void TSparseTable< TVal, GroupSize >::Resize ( const int &  NewVals)

Definition at line 403 of file shash.h.

                                                             {
  // only allow to grow
  if (NewVals > MxVals) {
    const int Groups = GetGroups(NewVals);
    GroupV.Reserve(Groups, Groups);
    MxVals = NewVals;
  }
}
template<class TVal, uint16 GroupSize = 48>
void TSparseTable< TVal, GroupSize >::Save ( TSOut SOut) const [inline]

Definition at line 329 of file shash.h.

{ MxVals.Save(SOut);  Vals.Save(SOut);  GroupV.Save(SOut); }
template<class TVal, uint16 GroupSize>
TVal & TSparseTable< TVal, GroupSize >::Set ( const int &  ValN,
const TVal &  Val 
)

Definition at line 420 of file shash.h.

                                                                         {
  Assert(ValN < MxVals);
  TSGroup& Group = GetGrp1(ValN);
  const int OldVals = Group.Len();
  TVal& ValRef = Group.Set(PosInGroup(ValN), Val);
  Vals += Group.Len() - OldVals;
  return ValRef;
}
template<class TVal, uint16 GroupSize>
TVal & TSparseTable< TVal, GroupSize >::Set ( const int &  ValN)

Definition at line 430 of file shash.h.

                                                        {
  Assert(ValN < MxVals);
  TSGroup& Group = GetGrp1(ValN);
  const int OldVals = Group.Len();
  TVal& ValRef = Group.Set(PosInGroup(ValN));
  Vals += Group.Len() - OldVals;
  return ValRef;
}
template<class TVal , uint16 GroupSize>
void TSparseTable< TVal, GroupSize >::Swap ( TSparseTable< TVal, GroupSize > &  ST)

Definition at line 413 of file shash.h.


Member Data Documentation

template<class TVal, uint16 GroupSize = 48>
TVec<TSGroup> TSparseTable< TVal, GroupSize >::GroupV [private]

Definition at line 316 of file shash.h.

template<class TVal, uint16 GroupSize = 48>
TInt TSparseTable< TVal, GroupSize >::MxVals [private]

Definition at line 315 of file shash.h.

template<class TVal, uint16 GroupSize = 48>
TInt TSparseTable< TVal, GroupSize >::Vals [private]

Definition at line 315 of file shash.h.


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