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

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

#include <gbase.h>

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 130 of file gbase.h.


Constructor & Destructor Documentation

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

Definition at line 136 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 138 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 139 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 141 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 143 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 153 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 158 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 154 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 162 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 164 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 160 of file gbase.h.

{return Last-First;}
template<class TVal>
TSnapQueue& TSnapQueue< TVal >::operator= ( const TSnapQueue< TVal > &  Queue) [inline]

Definition at line 147 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 150 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 170 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 173 of file gbase.h.

                             {
    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);
  }
template<class TVal>
int TSnapQueue< TVal >::Reserved ( ) const [inline]

Definition at line 165 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 145 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 168 of file gbase.h.

{ return ValV[First]; }

Member Data Documentation

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

Definition at line 133 of file gbase.h.

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

Definition at line 133 of file gbase.h.

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

Definition at line 132 of file gbase.h.

template<class TVal>
TVec<TVal> TSnapQueue< TVal >::ValV [private]

Definition at line 134 of file gbase.h.


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