SNAP Library 3.0, User Reference  2016-07-20 17:56:49
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
TLst< TVal > Class Template Reference

#include <ds.h>

Public Types

typedef TLstNd< TVal > * PLstNd
 

Public Member Functions

 TLst ()
 
 TLst (const TLst &)
 
 ~TLst ()
 
 TLst (TSIn &SIn)
 
void Save (TSOut &SOut) const
 
TLstoperator= (const TLst &)
 
void Clr ()
 
bool Empty () const
 
int Len () const
 
PLstNd First () const
 
PLstNd Last () const
 
TVal & FirstVal () const
 
TVal & LastVal () const
 
PLstNd AddFront (const TVal &Val)
 
PLstNd AddBack (const TVal &Val)
 
PLstNd AddFrontSorted (const TVal &Val, const bool &Asc=true)
 
PLstNd AddBackSorted (const TVal &Val, const bool &Asc=true)
 
void PutFront (const PLstNd &Nd)
 
void PutBack (const PLstNd &Nd)
 
PLstNd Ins (const PLstNd &Nd, const TVal &Val)
 
void Del (const TVal &Val)
 
void Del (const PLstNd &Nd)
 
void DelFirst ()
 
void DelLast ()
 
PLstNd SearchForw (const TVal &Val)
 
PLstNd SearchBack (const TVal &Val)
 

Private Attributes

int Nds
 
PLstNd FirstNd
 
PLstNd LastNd
 

Friends

class TLstNd< TVal >
 

Detailed Description

template<class TVal>
class TLst< TVal >

Definition at line 2636 of file ds.h.

Member Typedef Documentation

template<class TVal>
typedef TLstNd<TVal>* TLst< TVal >::PLstNd

Definition at line 2638 of file ds.h.

Constructor & Destructor Documentation

template<class TVal>
TLst< TVal >::TLst ( )
inline

Definition at line 2644 of file ds.h.

2644 : Nds(0), FirstNd(NULL), LastNd(NULL){}
int Nds
Definition: ds.h:2640
PLstNd LastNd
Definition: ds.h:2642
PLstNd FirstNd
Definition: ds.h:2641
template<class TVal>
TLst< TVal >::TLst ( const TLst< TVal > &  )
template<class TVal>
TLst< TVal >::~TLst ( )
inline

Definition at line 2646 of file ds.h.

2646 {Clr();}
void Clr()
Definition: ds.h:2652
template<class TVal >
TLst< TVal >::TLst ( TSIn SIn)
explicit

Definition at line 2683 of file ds.h.

2683  :
2684  Nds(0), FirstNd(NULL), LastNd(NULL){
2685  int CheckNds=0; SIn.Load(CheckNds);
2686  for (int NdN=0; NdN<CheckNds; NdN++){AddBack(TVal(SIn));}
2687  Assert(Nds==CheckNds);
2688 }
int Nds
Definition: ds.h:2640
PLstNd LastNd
Definition: ds.h:2642
PLstNd FirstNd
Definition: ds.h:2641
void Load(bool &Bool)
Definition: fl.h:84
#define Assert(Cond)
Definition: bd.h:251
PLstNd AddBack(const TVal &Val)
Definition: ds.h:2708

Member Function Documentation

template<class TVal>
TLstNd< TVal > * TLst< TVal >::AddBack ( const TVal &  Val)

Definition at line 2708 of file ds.h.

2708  {
2709  PLstNd Nd=new TLstNd<TVal>(LastNd, NULL, Val);
2710  if (LastNd!=NULL){LastNd->NextNd=Nd; LastNd=Nd;}
2711  else {FirstNd=Nd; LastNd=Nd;}
2712  Nds++; return Nd;
2713 }
int Nds
Definition: ds.h:2640
TLstNd * NextNd
Definition: ds.h:2615
Definition: ds.h:2612
PLstNd LastNd
Definition: ds.h:2642
PLstNd FirstNd
Definition: ds.h:2641
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
template<class TVal>
TLstNd< TVal > * TLst< TVal >::AddBackSorted ( const TVal &  Val,
const bool &  Asc = true 
)

Definition at line 2729 of file ds.h.

2729  {
2730  PLstNd Nd=Last();
2731  while ((Nd!=NULL)&&((Asc&&(Val<Nd->Val))||(!Asc&&(Val>Nd->Val)))){
2732  Nd=Nd->Prev();}
2733  return Ins(Nd, Val);
2734 }
PLstNd Ins(const PLstNd &Nd, const TVal &Val)
Definition: ds.h:2765
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
PLstNd Last() const
Definition: ds.h:2660
template<class TVal>
TLstNd< TVal > * TLst< TVal >::AddFront ( const TVal &  Val)

Definition at line 2700 of file ds.h.

2700  {
2701  PLstNd Nd=new TLstNd<TVal>(NULL, FirstNd, Val);
2702  if (FirstNd!=NULL){FirstNd->PrevNd=Nd; FirstNd=Nd;}
2703  else {FirstNd=Nd; LastNd=Nd;}
2704  Nds++; return Nd;
2705 }
int Nds
Definition: ds.h:2640
Definition: ds.h:2612
PLstNd LastNd
Definition: ds.h:2642
PLstNd FirstNd
Definition: ds.h:2641
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
TLstNd * PrevNd
Definition: ds.h:2614
template<class TVal>
TLstNd< TVal > * TLst< TVal >::AddFrontSorted ( const TVal &  Val,
const bool &  Asc = true 
)

Definition at line 2716 of file ds.h.

2716  {
2717  PLstNd Nd=First();
2718  if (Nd==NULL){
2719  return Ins(Nd, Val);
2720  } else {
2721  while ((Nd!=NULL)&&((Asc&&(Val>Nd()))||(!Asc&&(Val<Nd())))){
2722  Nd=Nd->Next();}
2723  if (Nd==NULL){return Ins(Nd->Last(), Val);}
2724  else {return Ins(Nd->Prev(), Val);}
2725  }
2726 }
PLstNd Ins(const PLstNd &Nd, const TVal &Val)
Definition: ds.h:2765
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
PLstNd First() const
Definition: ds.h:2659
template<class TVal>
void TLst< TVal >::Clr ( )
inline

Definition at line 2652 of file ds.h.

2652  {
2653  PLstNd Nd=FirstNd;
2654  while (Nd!=NULL){PLstNd NextNd=Nd->NextNd; delete Nd; Nd=NextNd;}
2655  Nds=0; FirstNd=NULL; LastNd=NULL;}
int Nds
Definition: ds.h:2640
PLstNd LastNd
Definition: ds.h:2642
PLstNd FirstNd
Definition: ds.h:2641
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
template<class TVal>
void TLst< TVal >::Del ( const TVal &  Val)

Definition at line 2776 of file ds.h.

2776  {
2777  PLstNd Nd=SearchForw(Val);
2778  if (Nd!=NULL){Del(Nd);}
2779 }
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
void Del(const TVal &Val)
Definition: ds.h:2776
PLstNd SearchForw(const TVal &Val)
Definition: ds.h:2792
template<class TVal>
void TLst< TVal >::Del ( const PLstNd Nd)

Definition at line 2782 of file ds.h.

2782  {
2783  Assert(Nd!=NULL);
2784  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
2785  else {Nd->PrevNd->NextNd=Nd->NextNd;}
2786  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
2787  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
2788  Nds--; delete Nd;
2789 }
int Nds
Definition: ds.h:2640
TLstNd * NextNd
Definition: ds.h:2615
PLstNd LastNd
Definition: ds.h:2642
PLstNd FirstNd
Definition: ds.h:2641
#define Assert(Cond)
Definition: bd.h:251
TLstNd * PrevNd
Definition: ds.h:2614
template<class TVal>
void TLst< TVal >::DelFirst ( )
inline

Definition at line 2673 of file ds.h.

2673 { PLstNd DelNd = FirstNd; Del(DelNd); }
PLstNd FirstNd
Definition: ds.h:2641
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
void Del(const TVal &Val)
Definition: ds.h:2776
template<class TVal>
void TLst< TVal >::DelLast ( )
inline

Definition at line 2674 of file ds.h.

2674 { PLstNd DelNd = LastNd; Del(DelNd); }
PLstNd LastNd
Definition: ds.h:2642
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
void Del(const TVal &Val)
Definition: ds.h:2776
template<class TVal>
bool TLst< TVal >::Empty ( ) const
inline

Definition at line 2657 of file ds.h.

2657 {return Nds==0;}
int Nds
Definition: ds.h:2640
template<class TVal>
PLstNd TLst< TVal >::First ( ) const
inline

Definition at line 2659 of file ds.h.

2659 {return FirstNd;}
PLstNd FirstNd
Definition: ds.h:2641
template<class TVal>
TVal& TLst< TVal >::FirstVal ( ) const
inline

Definition at line 2661 of file ds.h.

2661 {return FirstNd->GetVal();}
PLstNd FirstNd
Definition: ds.h:2641
TVal & GetVal()
Definition: ds.h:2629
template<class TVal>
TLstNd< TVal > * TLst< TVal >::Ins ( const PLstNd Nd,
const TVal &  Val 
)

Definition at line 2765 of file ds.h.

2765  {
2766  if (Nd==NULL){return AddFront(Val);}
2767  else if (Nd->NextNd==NULL){return AddBack(Val);}
2768  else {
2769  PLstNd NewNd=new TLstNd<TVal>(Nd, Nd->NextNd, Val);
2770  Nd->NextNd=NewNd; NewNd->NextNd->PrevNd=Nd;
2771  Nds++; return Nd;
2772  }
2773 }
int Nds
Definition: ds.h:2640
TLstNd * NextNd
Definition: ds.h:2615
Definition: ds.h:2612
PLstNd AddFront(const TVal &Val)
Definition: ds.h:2700
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
PLstNd AddBack(const TVal &Val)
Definition: ds.h:2708
TLstNd * PrevNd
Definition: ds.h:2614
template<class TVal>
PLstNd TLst< TVal >::Last ( ) const
inline

Definition at line 2660 of file ds.h.

2660 {return LastNd;}
PLstNd LastNd
Definition: ds.h:2642
template<class TVal>
TVal& TLst< TVal >::LastVal ( ) const
inline

Definition at line 2662 of file ds.h.

2662 {return LastNd->GetVal();}
PLstNd LastNd
Definition: ds.h:2642
TVal & GetVal()
Definition: ds.h:2629
template<class TVal>
int TLst< TVal >::Len ( ) const
inline

Definition at line 2658 of file ds.h.

2658 {return Nds;}
int Nds
Definition: ds.h:2640
template<class TVal>
TLst& TLst< TVal >::operator= ( const TLst< TVal > &  )
template<class TVal >
void TLst< TVal >::PutBack ( const PLstNd Nd)

Definition at line 2751 of file ds.h.

2751  {
2752  Assert(Nd!=NULL);
2753  // unchain
2754  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
2755  else {Nd->PrevNd->NextNd=Nd->NextNd;}
2756  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
2757  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
2758  // add to back
2759  Nd->PrevNd=LastNd; Nd->NextNd=NULL;
2760  if (LastNd!=NULL){LastNd->NextNd=Nd; LastNd=Nd;}
2761  else {FirstNd=Nd; LastNd=Nd;}
2762 }
TLstNd * NextNd
Definition: ds.h:2615
PLstNd LastNd
Definition: ds.h:2642
PLstNd FirstNd
Definition: ds.h:2641
#define Assert(Cond)
Definition: bd.h:251
TLstNd * PrevNd
Definition: ds.h:2614
template<class TVal >
void TLst< TVal >::PutFront ( const PLstNd Nd)

Definition at line 2737 of file ds.h.

2737  {
2738  Assert(Nd!=NULL);
2739  // unchain
2740  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
2741  else {Nd->PrevNd->NextNd=Nd->NextNd;}
2742  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
2743  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
2744  // add to front
2745  Nd->PrevNd=NULL; Nd->NextNd=FirstNd;
2746  if (FirstNd!=NULL){FirstNd->PrevNd=Nd; FirstNd=Nd;}
2747  else {FirstNd=Nd; LastNd=Nd;}
2748 }
TLstNd * NextNd
Definition: ds.h:2615
PLstNd LastNd
Definition: ds.h:2642
PLstNd FirstNd
Definition: ds.h:2641
#define Assert(Cond)
Definition: bd.h:251
TLstNd * PrevNd
Definition: ds.h:2614
template<class TVal >
void TLst< TVal >::Save ( TSOut SOut) const

Definition at line 2691 of file ds.h.

2691  {
2692  SOut.Save(Nds);
2693  PLstNd Nd=FirstNd; int CheckNds=0;
2694  while (Nd!=NULL){
2695  Nd->Val.Save(SOut); Nd=Nd->NextNd; CheckNds++;}
2696  IAssert(Nds==CheckNds);
2697 }
#define IAssert(Cond)
Definition: bd.h:262
int Nds
Definition: ds.h:2640
TVal Val
Definition: ds.h:2616
PLstNd FirstNd
Definition: ds.h:2641
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
void Save(const bool &Bool)
Definition: fl.h:173
template<class TVal>
TLstNd< TVal > * TLst< TVal >::SearchBack ( const TVal &  Val)

Definition at line 2802 of file ds.h.

2802  {
2803  PLstNd Nd=Last();
2804  while (Nd!=NULL){
2805  if (Nd->GetVal()==Val){return Nd;}
2806  Nd=Nd->Prev();
2807  }
2808  return NULL;
2809 }
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
PLstNd Last() const
Definition: ds.h:2660
template<class TVal>
TLstNd< TVal > * TLst< TVal >::SearchForw ( const TVal &  Val)

Definition at line 2792 of file ds.h.

2792  {
2793  PLstNd Nd=First();
2794  while (Nd!=NULL){
2795  if (Nd->GetVal()==Val){return Nd;}
2796  Nd=Nd->Next();
2797  }
2798  return NULL;
2799 }
TLstNd< TVal > * PLstNd
Definition: ds.h:2638
PLstNd First() const
Definition: ds.h:2659

Friends And Related Function Documentation

template<class TVal>
friend class TLstNd< TVal >
friend

Definition at line 2679 of file ds.h.

Member Data Documentation

template<class TVal>
PLstNd TLst< TVal >::FirstNd
private

Definition at line 2641 of file ds.h.

template<class TVal>
PLstNd TLst< TVal >::LastNd
private

Definition at line 2642 of file ds.h.

template<class TVal>
int TLst< TVal >::Nds
private

Definition at line 2640 of file ds.h.


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