SNAP Library 2.3, User Reference  2014-06-16 11:58:46
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
TSnapQueue< TVal > Class Template Reference

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

#include <gbase.h>

Public Member Functions

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

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.

161 : MxFirst(1024), First(0), Last(0), ValV(MxFirst, 0) { }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158
TInt Last
Definition: gbase.h:158
TInt MxFirst
Definition: gbase.h:157
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.

163 : MxFirst(1024+MxVals/10), First(0), Last(0), ValV(TInt::GetMx(MxFirst, MxVals), 0) { }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158
static int GetMx(const int &Int1, const int &Int2)
Definition: dt.h:1089
TInt Last
Definition: gbase.h:158
TInt MxFirst
Definition: gbase.h:157
template<class TVal>
TSnapQueue< TVal >::TSnapQueue ( const int &  MxVals,
const int &  MaxFirst 
)
inline

Definition at line 164 of file gbase.h.

164  : MxFirst(MaxFirst),
165  First(0), Last(0), ValV(TInt::GetMx(MxFirst, MxVals), 0) { }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158
static int GetMx(const int &Int1, const int &Int2)
Definition: dt.h:1089
TInt Last
Definition: gbase.h:158
TInt MxFirst
Definition: gbase.h:157
template<class TVal>
TSnapQueue< TVal >::TSnapQueue ( const TSnapQueue< TVal > &  Queue)
inline

Definition at line 166 of file gbase.h.

166 : MxFirst(Queue.MxFirst), First(Queue.First), Last(Queue.Last), ValV(Queue.ValV) { }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158
TInt Last
Definition: gbase.h:158
TInt MxFirst
Definition: gbase.h:157
template<class TVal>
TSnapQueue< TVal >::TSnapQueue ( TSIn SIn)
inlineexplicit

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

Definition at line 168 of file gbase.h.

168 : MxFirst(SIn), First(SIn), Last(SIn), ValV(SIn) { }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158
TInt Last
Definition: gbase.h:158
TInt MxFirst
Definition: gbase.h:157

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.

178 { ValV.Clr(DoDel); First=Last=0; }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158
TInt Last
Definition: gbase.h:158
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:953
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.

183 {return First==Last;}
TInt First
Definition: gbase.h:158
TInt Last
Definition: gbase.h:158
template<class TVal>
void TSnapQueue< TVal >::Gen ( const int &  MxVals,
const int &  MaxFirst = 1024 
)
inline

Definition at line 179 of file gbase.h.

179  {
180  MxFirst=MaxFirst; First=Last=0; ValV.Gen(MxVals, 0); }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158
TInt Last
Definition: gbase.h:158
TInt MxFirst
Definition: gbase.h:157
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
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.

187 { return First; }
TInt First
Definition: gbase.h:158
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.

189 { return Last; }
TInt Last
Definition: gbase.h:158
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.

185 {return Last-First;}
TInt First
Definition: gbase.h:158
TInt Last
Definition: gbase.h:158
template<class TVal>
TSnapQueue& TSnapQueue< TVal >::operator= ( const TSnapQueue< TVal > &  Queue)
inline

Definition at line 172 of file gbase.h.

172  { if (this != &Queue) { MxFirst=Queue.MxFirst;
173  First=Queue.First; Last=Queue.Last; ValV=Queue.ValV; } return *this; }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158
TInt Last
Definition: gbase.h:158
TInt MxFirst
Definition: gbase.h:157
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.

175 { return ValV[First+ValN]; }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158
template<class TVal>
void TSnapQueue< TVal >::Pop ( )
inline

Removes the first element from the queue.

Definition at line 195 of file gbase.h.

195  { First++;
196  if (First==Last) { ValV.Clr(false); First=Last=0; } }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158
TInt Last
Definition: gbase.h:158
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:953
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.

198  {
199  if (First>0 && (First > MxFirst || ValV.Len() == ValV.Reserved()) && ! ValV.Empty()) {
200  //printf("[move cc queue.Len:%d-->%d]", ValV.Len(),Len()); TExeTm Tm;
201  memmove(ValV.BegI(), ValV.GetI(First), sizeof(TVal)*Len());
202  ValV.Del(Len(), ValV.Len()-1); Last-=First; First=0;
203  //printf("[%s]\n", Tm.GetStr()); fflush(stdout);
204  }
205  //if (ValV.Len() == ValV.Reserved()){ printf("[resizeCCQ]"); fflush(stdout); }
206  Last++; ValV.Add(Val);
207  }
TSizeTy Reserved() const
Returns the size of allocated storage capacity.
Definition: ds.h:537
TVec< TVal > ValV
Definition: gbase.h:159
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
Definition: ds.h:1094
TInt First
Definition: gbase.h:158
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TInt Last
Definition: gbase.h:158
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:530
TInt MxFirst
Definition: gbase.h:157
int Len() const
Returns the number of elements in the queue.
Definition: gbase.h:185
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
Definition: ds.h:550
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
Definition: ds.h:554
template<class TVal>
int TSnapQueue< TVal >::Reserved ( ) const
inline

Definition at line 190 of file gbase.h.

190 { return ValV.Reserved(); }
TSizeTy Reserved() const
Returns the size of allocated storage capacity.
Definition: ds.h:537
TVec< TVal > ValV
Definition: gbase.h:159
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.

170 { MxFirst.Save(SOut); First.Save(SOut); Last.Save(SOut); ValV.Save(SOut); }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158
void Save(TSOut &SOut) const
Definition: dt.h:1057
TInt Last
Definition: gbase.h:158
void Save(TSOut &SOut) const
Definition: ds.h:885
TInt MxFirst
Definition: gbase.h:157
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.

193 { return ValV[First]; }
TVec< TVal > ValV
Definition: gbase.h:159
TInt First
Definition: gbase.h:158

Member Data Documentation

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

Definition at line 158 of file gbase.h.

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

Definition at line 158 of file gbase.h.

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

Definition at line 157 of file gbase.h.

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

Definition at line 159 of file gbase.h.


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