SNAP Library 2.2, Developer 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
TSnapQueue< TVal > Class Template Reference

Fast Queue used by the TBreathFS (uses memcpy to move objects TVal around). More...

#include <gbase.h>

Collaboration diagram for TSnapQueue< TVal >:

List of all members.

Public Member Functions

 TSnapQueue ()
 TSnapQueue (const int &MxVals)
 Constructor that reserves enough memory for a queue with MxVals elements.
 TSnapQueue (const int &MxVals, const int &MaxFirst)
 TSnapQueue (const TSnapQueue &Queue)
 TSnapQueue (TSIn &SIn)
 Constructor that loads the queue from a (binary) stream SIn.
void Save (TSOut &SOut) const
 Saves the queue to a (binary) stream SOut.
TSnapQueueoperator= (const TSnapQueue &Queue)
const TVal & operator[] (const int &ValN) const
 Returns the value of the ValN element in the queue, but does not remove the element.
void Clr (const bool &DoDel=true)
 Deletes all elements from the queue.
void Gen (const int &MxVals, const int &MaxFirst=1024)
bool Empty () const
 Tests whether the queue is empty (contains no elements).
int Len () const
 Returns the number of elements in the queue.
int GetFirst () const
 Returns the location of the first element in the queue.
int GetLast () const
 Returns the location of the last element in the queue.
int Reserved () const
const TVal & Top () const
 Returns the value of the first element in the queue, but does not remove the element.
void Pop ()
 Removes the first element from the queue.
void Push (const TVal &Val)
 Adds an element at the end of the queue.

Private Attributes

TInt MxFirst
TInt First
TInt Last
TVec< TVal > ValV

Detailed Description

template<class TVal>
class TSnapQueue< TVal >

Fast Queue used by the TBreathFS (uses memcpy to move objects TVal around).

Definition at line 155 of file gbase.h.


Constructor & Destructor Documentation

template<class TVal>
TSnapQueue< TVal >::TSnapQueue ( ) [inline]

Definition at line 161 of file gbase.h.

: MxFirst(1024), First(0), Last(0), ValV(MxFirst, 0) { }
template<class TVal>
TSnapQueue< TVal >::TSnapQueue ( const int &  MxVals) [inline]

Constructor that reserves enough memory for a queue with MxVals elements.

Definition at line 163 of file gbase.h.

: MxFirst(1024+MxVals/10), First(0), Last(0), ValV(TInt::GetMx(MxFirst, MxVals), 0) { }
template<class TVal>
TSnapQueue< TVal >::TSnapQueue ( const int &  MxVals,
const int &  MaxFirst 
) [inline]

Definition at line 164 of file gbase.h.

                                                     : MxFirst(MaxFirst),
    First(0), Last(0), ValV(TInt::GetMx(MxFirst, MxVals), 0) { }
template<class TVal>
TSnapQueue< TVal >::TSnapQueue ( const TSnapQueue< TVal > &  Queue) [inline]

Definition at line 166 of file gbase.h.

: MxFirst(Queue.MxFirst), First(Queue.First), Last(Queue.Last), ValV(Queue.ValV) { }
template<class TVal>
TSnapQueue< TVal >::TSnapQueue ( TSIn SIn) [inline, explicit]

Constructor that loads the queue from a (binary) stream SIn.

Definition at line 168 of file gbase.h.

: MxFirst(SIn), First(SIn), Last(SIn), ValV(SIn) { }

Member Function Documentation

template<class TVal>
void TSnapQueue< TVal >::Clr ( const bool &  DoDel = true) [inline]

Deletes all elements from the queue.

Definition at line 178 of file gbase.h.

{ ValV.Clr(DoDel);  First=Last=0; }
template<class TVal>
bool TSnapQueue< TVal >::Empty ( ) const [inline]

Tests whether the queue is empty (contains no elements).

Definition at line 183 of file gbase.h.

{return First==Last;}
template<class TVal>
void TSnapQueue< TVal >::Gen ( const int &  MxVals,
const int &  MaxFirst = 1024 
) [inline]

Definition at line 179 of file gbase.h.

                                                        {
    MxFirst=MaxFirst; First=Last=0; ValV.Gen(MxVals, 0); }
template<class TVal>
int TSnapQueue< TVal >::GetFirst ( ) const [inline]

Returns the location of the first element in the queue.

Definition at line 187 of file gbase.h.

{ return First; }
template<class TVal>
int TSnapQueue< TVal >::GetLast ( ) const [inline]

Returns the location of the last element in the queue.

Definition at line 189 of file gbase.h.

{ return Last; }
template<class TVal>
int TSnapQueue< TVal >::Len ( ) const [inline]

Returns the number of elements in the queue.

Definition at line 185 of file gbase.h.

Referenced by TSnapQueue< int >::Push().

{return Last-First;}

Here is the caller graph for this function:

template<class TVal>
TSnapQueue& TSnapQueue< TVal >::operator= ( const TSnapQueue< TVal > &  Queue) [inline]

Definition at line 172 of file gbase.h.

                                                 { if (this != &Queue) { MxFirst=Queue.MxFirst;
    First=Queue.First; Last=Queue.Last; ValV=Queue.ValV; } return *this; }
template<class TVal>
const TVal& TSnapQueue< TVal >::operator[] ( const int &  ValN) const [inline]

Returns the value of the ValN element in the queue, but does not remove the element.

Definition at line 175 of file gbase.h.

{ return ValV[First+ValN]; }
template<class TVal>
void TSnapQueue< TVal >::Pop ( ) [inline]

Removes the first element from the queue.

Definition at line 195 of file gbase.h.

             { First++;
    if (First==Last) { ValV.Clr(false); First=Last=0; } }
template<class TVal>
void TSnapQueue< TVal >::Push ( const TVal &  Val) [inline]

Adds an element at the end of the queue.

Definition at line 198 of file gbase.h.

Referenced by TSnap::GetNodeWcc(), TSnap::GetTreeSig(), and TSnap::IsWeaklyConn().

                             {
    if (First>0 && (First > MxFirst || ValV.Len() == ValV.Reserved()) && ! ValV.Empty()) {
      //printf("[move cc queue.Len:%d-->%d]", ValV.Len(),Len()); TExeTm Tm;
      memmove(ValV.BegI(), ValV.GetI(First), sizeof(TVal)*Len());
      ValV.Del(Len(), ValV.Len()-1);  Last-=First;  First=0;
      //printf("[%s]\n", Tm.GetStr()); fflush(stdout);
    }
    //if (ValV.Len() == ValV.Reserved()){ printf("[resizeCCQ]"); fflush(stdout); }
    Last++;  ValV.Add(Val);
  }

Here is the caller graph for this function:

template<class TVal>
int TSnapQueue< TVal >::Reserved ( ) const [inline]

Definition at line 190 of file gbase.h.

{ return ValV.Reserved(); }
template<class TVal>
void TSnapQueue< TVal >::Save ( TSOut SOut) const [inline]

Saves the queue to a (binary) stream SOut.

Definition at line 170 of file gbase.h.

{ MxFirst.Save(SOut); First.Save(SOut); Last.Save(SOut); ValV.Save(SOut); }
template<class TVal>
const TVal& TSnapQueue< TVal >::Top ( ) const [inline]

Returns the value of the first element in the queue, but does not remove the element.

Definition at line 193 of file gbase.h.

{ return ValV[First]; }

Member Data Documentation

template<class TVal>
TInt TSnapQueue< TVal >::MxFirst [private]

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