SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TSparseTable< TVal, GroupSize > Class Template Reference

#include <shash.h>

Collaboration diagram for TSparseTable< TVal, GroupSize >:

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.

324  : MxVals(MaxVals),
325  Vals(0), GroupV(GetGroups(MaxVals), GetGroups(MaxVals)) { }
TVec< TSGroup > GroupV
Definition: shash.h:316
static int GetGroups(const int &Vals)
Definition: shash.h:318
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315
template<class TVal, uint16 GroupSize = 48>
TSparseTable< TVal, GroupSize >::TSparseTable ( const TSparseTable< TVal, GroupSize > &  ST)
inline

Definition at line 326 of file shash.h.

326 : MxVals(ST.MxVals), Vals(ST.Vals), GroupV(ST.GroupV) { }
TVec< TSGroup > GroupV
Definition: shash.h:316
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315
template<class TVal, uint16 GroupSize = 48>
TSparseTable< TVal, GroupSize >::TSparseTable ( TSIn SIn)
inline

Definition at line 327 of file shash.h.

327 : MxVals(SIn), Vals(SIn), GroupV(SIn) { }
TVec< TSGroup > GroupV
Definition: shash.h:316
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315

Member Function Documentation

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

Definition at line 336 of file shash.h.

Referenced by TSparseSet< TKey, GroupSize >::BegI().

336  {
337  if (Len() > 0) { int B = 0;
338  while (B < Groups() && GroupV[B].Empty()) { B++; }
339  return TIter(GroupV.BegI(), GroupV.BegI()+B, GroupV.EndI()); }
340  return TIter(GroupV.BegI(), GroupV.EndI(), GroupV.EndI());
341  }
TVec< TSGroup > GroupV
Definition: shash.h:316
TSparseTableI< TVal, GroupSize > TIter
Definition: shash.h:313
int Groups() const
Definition: shash.h:351
int Len() const
Definition: shash.h:349
bool Empty() const
Definition: shash.h:352

Here is the caller graph for this function:

template<class TVal , uint16 GroupSize>
void TSparseTable< TVal, GroupSize >::Clr ( const bool &  DoDel = true)

Definition at line 392 of file shash.h.

Referenced by TSparseSet< TKey, GroupSize >::Clr().

392  {
393  if (! DoDel) {
394  for (int g = 0; g < GroupV.Len(); g++) GroupV[g].Clr(false);
395  } else {
396  MxVals = 0;
397  GroupV.Clr(true);
398  }
399  Vals = 0;
400 }
TVec< TSGroup > GroupV
Definition: shash.h:316
void Clr(const bool &DoDel=true)
Definition: shash.h:392
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315

Here is the caller graph for this function:

template<class TVal , uint16 GroupSize>
void TSparseTable< TVal, GroupSize >::Del ( const int &  ValN)

Definition at line 440 of file shash.h.

References Assert, TSparseGroup< TVal, GroupSize >::Del(), and TSparseGroup< TVal, GroupSize >::Len().

440  {
441  Assert(ValN < MxVals);
442  TSGroup& Group = GetGrp1(ValN);
443  const int OldVals = Group.Len();
444  Group.Del(PosInGroup(ValN));
445  Vals += Group.Len() - OldVals;
446 }
const TSGroup & GetGrp1(const int &ValN) const
Definition: shash.h:321
int PosInGroup(const int &ValN) const
Definition: shash.h:319
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315
#define Assert(Cond)
Definition: bd.h:251
TSparseGroup< TVal, GroupSize > TSGroup
Definition: shash.h:312

Here is the call graph for this function:

template<class TVal, uint16 GroupSize = 48>
bool TSparseTable< TVal, GroupSize >::Empty ( ) const
inline

Definition at line 352 of file shash.h.

Referenced by TSparseTable< TKey, GroupSize >::BegI().

352 { return Vals == 0; }
TInt Vals
Definition: shash.h:315

Here is the caller graph for this function:

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

Definition at line 342 of file shash.h.

Referenced by TSparseSet< TKey, GroupSize >::EndI().

342 { return TIter(GroupV.BegI(), GroupV.EndI(), GroupV.EndI()); }
TVec< TSGroup > GroupV
Definition: shash.h:316
TSparseTableI< TVal, GroupSize > TIter
Definition: shash.h:313

Here is the caller graph for this function:

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.

Referenced by TSparseSet< TKey, GroupSize >::GetKey().

362 { return GroupV[GroupNum(ValN)].Get(PosInGroup(ValN)); }
TVec< TSGroup > GroupV
Definition: shash.h:316
int GroupNum(const int &ValN) const
Definition: shash.h:320
int PosInGroup(const int &ValN) const
Definition: shash.h:319

Here is the caller graph for this function:

template<class TVal, uint16 GroupSize = 48>
uint TSparseTable< TVal, GroupSize >::GetDiskSz ( ) const
inline

Definition at line 353 of file shash.h.

Referenced by TSparseSet< TKey, GroupSize >::GetDiskSz().

353  {
354  return sizeof(TInt)*4 + ((GroupSize+16)/8)*Groups() + sizeof(TVal)*Vals; }
int Groups() const
Definition: shash.h:351
TInt Vals
Definition: shash.h:315
Definition: dt.h:1134

Here is the caller graph for this function:

template<class TVal, uint16 GroupSize = 48>
TSGroup& TSparseTable< TVal, GroupSize >::GetGroup ( const int &  GroupN)
inline

Definition at line 367 of file shash.h.

Referenced by TSparseSet< TKey, GroupSize >::CopyFrom(), and TSparseSet< TKey, GroupSize >::MoveFrom().

367 { return GroupV[GroupN]; }
TVec< TSGroup > GroupV
Definition: shash.h:316

Here is the caller graph for this function:

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.

368 { return GroupV[GroupN]; }
TVec< TSGroup > GroupV
Definition: shash.h:316
template<class TVal, uint16 GroupSize = 48>
static int TSparseTable< TVal, GroupSize >::GetGroups ( const int &  Vals)
inlinestaticprivate

Definition at line 318 of file shash.h.

318 { return Vals == 0 ? 0 : ((Vals-1) / GroupSize) + 1; }
TInt Vals
Definition: shash.h:315
template<class TVal, uint16 GroupSize = 48>
const TSGroup& TSparseTable< TVal, GroupSize >::GetGrp1 ( const int &  ValN) const
inlineprivate

Definition at line 321 of file shash.h.

321 { return GroupV[GroupNum(ValN)]; }
TVec< TSGroup > GroupV
Definition: shash.h:316
int GroupNum(const int &ValN) const
Definition: shash.h:320
template<class TVal, uint16 GroupSize = 48>
TSGroup& TSparseTable< TVal, GroupSize >::GetGrp1 ( const int &  ValN)
inlineprivate

Definition at line 322 of file shash.h.

322 { return GroupV[GroupNum(ValN)]; }
TVec< TSGroup > GroupV
Definition: shash.h:316
int GroupNum(const int &ValN) const
Definition: shash.h:320
template<class TVal, uint16 GroupSize = 48>
TIter TSparseTable< TVal, GroupSize >::GetI ( const int &  ValN) const
inline

Definition at line 343 of file shash.h.

Referenced by TSparseSet< TKey, GroupSize >::GetI().

343  { Assert(! IsEmpty(ValN));
344  typedef typename TVec<TSGroup>::TIter TVIter;
345  const TVIter GI = GroupV.GetI(GroupNum(ValN));
346  return TIter(GroupV.BegI(), GI, GroupV.EndI(), GI->PosToOffset(PosInGroup(ValN)));
347  }
TVec< TSGroup > GroupV
Definition: shash.h:316
TSparseTableI< TVal, GroupSize > TIter
Definition: shash.h:313
int GroupNum(const int &ValN) const
Definition: shash.h:320
int PosInGroup(const int &ValN) const
Definition: shash.h:319
#define Assert(Cond)
Definition: bd.h:251
TVal * TIter
Random access iterator to TVal.
Definition: ds.h:432
bool IsEmpty(const int &ValN) const
Definition: shash.h:361

Here is the caller graph for this function:

template<class TVal, uint16 GroupSize = 48>
::TSize TSparseTable< TVal, GroupSize >::GetMemUsed ( ) const
inline

Definition at line 334 of file shash.h.

Referenced by TSparseSet< TKey, GroupSize >::GetMemUsed().

334 { return 2*sizeof(TInt)+Vals*sizeof(TVal)+GroupV.GetMemUsed(); }
TVec< TSGroup > GroupV
Definition: shash.h:316
TInt Vals
Definition: shash.h:315
Definition: dt.h:1134

Here is the caller graph for this function:

template<class TVal, uint16 GroupSize = 48>
int TSparseTable< TVal, GroupSize >::GroupNum ( const int &  ValN) const
inlineprivate

Definition at line 320 of file shash.h.

Referenced by TSparseTable< TKey, GroupSize >::Get(), TSparseTable< TKey, GroupSize >::GetGrp1(), TSparseTable< TKey, GroupSize >::GetI(), and TSparseTable< TKey, GroupSize >::IsEmpty().

320 { return ValN / GroupSize; }

Here is the caller graph for this function:

template<class TVal, uint16 GroupSize = 48>
int TSparseTable< TVal, GroupSize >::Groups ( ) const
inline

Definition at line 351 of file shash.h.

Referenced by TSparseTable< TKey, GroupSize >::BegI(), TSparseSet< TKey, GroupSize >::CopyFrom(), TSparseTable< TKey, GroupSize >::GetDiskSz(), and TSparseSet< TKey, GroupSize >::MoveFrom().

351 { return GroupV.Len(); }
TVec< TSGroup > GroupV
Definition: shash.h:316

Here is the caller graph for this function:

template<class TVal, uint16 GroupSize = 48>
bool TSparseTable< TVal, GroupSize >::IsEmpty ( const int &  ValN) const
inline

Definition at line 361 of file shash.h.

Referenced by TSparseTable< TKey, GroupSize >::GetI(), and TSparseSet< TKey, GroupSize >::IsKeyId().

361 { return GroupV[GroupNum(ValN)].IsEmpty(PosInGroup(ValN)); }
TVec< TSGroup > GroupV
Definition: shash.h:316
int GroupNum(const int &ValN) const
Definition: shash.h:320
int PosInGroup(const int &ValN) const
Definition: shash.h:319

Here is the caller graph for this function:

template<class TVal, uint16 GroupSize = 48>
int TSparseTable< TVal, GroupSize >::Len ( ) const
inline

Definition at line 349 of file shash.h.

Referenced by TSparseTable< TKey, GroupSize >::BegI(), and TSparseSet< TKey, GroupSize >::Len().

349 { return Vals; }
TInt Vals
Definition: shash.h:315

Here is the caller graph for this function:

template<class TVal, uint16 GroupSize = 48>
void TSparseTable< TVal, GroupSize >::Load ( TSIn SIn)
inline

Definition at line 328 of file shash.h.

Referenced by TSparseSet< TKey, GroupSize >::Load().

328 { MxVals.Load(SIn); Vals.Load(SIn); GroupV.Load(SIn); }
TVec< TSGroup > GroupV
Definition: shash.h:316
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315
void Load(TSIn &SIn)
Definition: dt.h:1149

Here is the caller graph for this function:

template<class TVal , uint16 GroupSize>
bool TSparseTable< TVal, GroupSize >::operator< ( const TSparseTable< TVal, GroupSize > &  ST) const

Definition at line 387 of file shash.h.

References TSparseTable< TVal, GroupSize >::GroupV, and TSparseTable< TVal, GroupSize >::Vals.

387  {
388  return Vals < ST.Vals || (Vals == ST.Vals && GroupV < ST.GroupV);
389 }
TVec< TSGroup > GroupV
Definition: shash.h:316
TInt Vals
Definition: shash.h:315
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.

References TSparseTable< TVal, GroupSize >::GroupV, TSparseTable< TVal, GroupSize >::MxVals, and TSparseTable< TVal, GroupSize >::Vals.

372  {
373  if (this != &ST) {
374  MxVals = ST.MxVals;
375  Vals = ST.Vals;
376  GroupV = ST.GroupV;
377  }
378  return *this;
379 }
TVec< TSGroup > GroupV
Definition: shash.h:316
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315
template<class TVal , uint16 GroupSize>
bool TSparseTable< TVal, GroupSize >::operator== ( const TSparseTable< TVal, GroupSize > &  ST) const

Definition at line 382 of file shash.h.

References TSparseTable< TVal, GroupSize >::GroupV, TSparseTable< TVal, GroupSize >::MxVals, and TSparseTable< TVal, GroupSize >::Vals.

382  {
383  return Vals == ST.Vals && MxVals == ST.MxVals && GroupV == ST.GroupV;
384 }
TVec< TSGroup > GroupV
Definition: shash.h:316
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315
template<class TVal, uint16 GroupSize = 48>
int TSparseTable< TVal, GroupSize >::PosInGroup ( const int &  ValN) const
inlineprivate

Definition at line 319 of file shash.h.

Referenced by TSparseTable< TKey, GroupSize >::Get(), TSparseTable< TKey, GroupSize >::GetI(), and TSparseTable< TKey, GroupSize >::IsEmpty().

319 { return ValN % GroupSize; }

Here is the caller graph for this function:

template<class TVal, uint16 GroupSize = 48>
void TSparseTable< TVal, GroupSize >::Reserve ( const int  NewVals)
inline

Definition at line 357 of file shash.h.

357 { Resize(NewVals); }
void Resize(const int &NewVals)
Definition: shash.h:403
template<class TVal, uint16 GroupSize = 48>
int TSparseTable< TVal, GroupSize >::Reserved ( ) const
inline

Definition at line 350 of file shash.h.

Referenced by TSparseSet< TKey, GroupSize >::Reserved().

350 { return MxVals; }
TInt MxVals
Definition: shash.h:315

Here is the caller graph for this function:

template<class TVal , uint16 GroupSize>
void TSparseTable< TVal, GroupSize >::Resize ( const int &  NewVals)

Definition at line 403 of file shash.h.

Referenced by TSparseTable< TKey, GroupSize >::Reserve().

403  {
404  // only allow to grow
405  if (NewVals > MxVals) {
406  const int Groups = GetGroups(NewVals);
407  GroupV.Reserve(Groups, Groups);
408  MxVals = NewVals;
409  }
410 }
TVec< TSGroup > GroupV
Definition: shash.h:316
static int GetGroups(const int &Vals)
Definition: shash.h:318
TInt MxVals
Definition: shash.h:315
int Groups() const
Definition: shash.h:351

Here is the caller graph for this function:

template<class TVal, uint16 GroupSize = 48>
void TSparseTable< TVal, GroupSize >::Save ( TSOut SOut) const
inline

Definition at line 329 of file shash.h.

Referenced by TSparseSet< TKey, GroupSize >::Save().

329 { MxVals.Save(SOut); Vals.Save(SOut); GroupV.Save(SOut); }
TVec< TSGroup > GroupV
Definition: shash.h:316
void Save(TSOut &SOut) const
Definition: dt.h:1150
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315

Here is the caller graph for this function:

template<class TVal, uint16 GroupSize>
TVal & TSparseTable< TVal, GroupSize >::Set ( const int &  ValN,
const TVal &  Val 
)

Definition at line 420 of file shash.h.

References Assert, TSparseGroup< TVal, GroupSize >::Len(), and TSparseGroup< TVal, GroupSize >::Set().

420  {
421  Assert(ValN < MxVals);
422  TSGroup& Group = GetGrp1(ValN);
423  const int OldVals = Group.Len();
424  TVal& ValRef = Group.Set(PosInGroup(ValN), Val);
425  Vals += Group.Len() - OldVals;
426  return ValRef;
427 }
const TSGroup & GetGrp1(const int &ValN) const
Definition: shash.h:321
int PosInGroup(const int &ValN) const
Definition: shash.h:319
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315
#define Assert(Cond)
Definition: bd.h:251
TSparseGroup< TVal, GroupSize > TSGroup
Definition: shash.h:312

Here is the call graph for this function:

template<class TVal, uint16 GroupSize>
TVal & TSparseTable< TVal, GroupSize >::Set ( const int &  ValN)

Definition at line 430 of file shash.h.

References Assert, TSparseGroup< TVal, GroupSize >::Len(), and TSparseGroup< TVal, GroupSize >::Set().

430  {
431  Assert(ValN < MxVals);
432  TSGroup& Group = GetGrp1(ValN);
433  const int OldVals = Group.Len();
434  TVal& ValRef = Group.Set(PosInGroup(ValN));
435  Vals += Group.Len() - OldVals;
436  return ValRef;
437 }
const TSGroup & GetGrp1(const int &ValN) const
Definition: shash.h:321
int PosInGroup(const int &ValN) const
Definition: shash.h:319
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315
#define Assert(Cond)
Definition: bd.h:251
TSparseGroup< TVal, GroupSize > TSGroup
Definition: shash.h:312

Here is the call graph for this function:

template<class TVal , uint16 GroupSize>
void TSparseTable< TVal, GroupSize >::Swap ( TSparseTable< TVal, GroupSize > &  ST)

Definition at line 413 of file shash.h.

References TSparseTable< TVal, GroupSize >::GroupV, TSparseTable< TVal, GroupSize >::MxVals, Swap(), and TSparseTable< TVal, GroupSize >::Vals.

413  {
414  ::Swap(MxVals, ST.MxVals);
415  ::Swap(Vals, ST.Vals);
416  GroupV.Swap(ST.GroupV);
417 }
TVec< TSGroup > GroupV
Definition: shash.h:316
TInt MxVals
Definition: shash.h:315
TInt Vals
Definition: shash.h:315
void Swap(TSparseTable &ST)
Definition: shash.h:413

Here is the call graph for this function:

Member Data Documentation


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