SNAP Library 2.4, User Reference  2015-05-11 19:40:56
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 2588 of file ds.h.

Member Typedef Documentation

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

Definition at line 2590 of file ds.h.

Constructor & Destructor Documentation

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

Definition at line 2596 of file ds.h.

2596 : Nds(0), FirstNd(NULL), LastNd(NULL){}
int Nds
Definition: ds.h:2592
PLstNd LastNd
Definition: ds.h:2594
PLstNd FirstNd
Definition: ds.h:2593
template<class TVal>
TLst< TVal >::TLst ( const TLst< TVal > &  )
template<class TVal>
TLst< TVal >::~TLst ( )
inline

Definition at line 2598 of file ds.h.

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

Definition at line 2635 of file ds.h.

2635  :
2636  Nds(0), FirstNd(NULL), LastNd(NULL){
2637  int CheckNds=0; SIn.Load(CheckNds);
2638  for (int NdN=0; NdN<CheckNds; NdN++){AddBack(TVal(SIn));}
2639  Assert(Nds==CheckNds);
2640 }
int Nds
Definition: ds.h:2592
PLstNd LastNd
Definition: ds.h:2594
PLstNd FirstNd
Definition: ds.h:2593
void Load(bool &Bool)
Definition: fl.h:84
#define Assert(Cond)
Definition: bd.h:251
PLstNd AddBack(const TVal &Val)
Definition: ds.h:2660

Member Function Documentation

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

Definition at line 2660 of file ds.h.

2660  {
2661  PLstNd Nd=new TLstNd<TVal>(LastNd, NULL, Val);
2662  if (LastNd!=NULL){LastNd->NextNd=Nd; LastNd=Nd;}
2663  else {FirstNd=Nd; LastNd=Nd;}
2664  Nds++; return Nd;
2665 }
int Nds
Definition: ds.h:2592
TLstNd * NextNd
Definition: ds.h:2567
Definition: ds.h:2564
PLstNd LastNd
Definition: ds.h:2594
PLstNd FirstNd
Definition: ds.h:2593
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
template<class TVal>
TLstNd< TVal > * TLst< TVal >::AddBackSorted ( const TVal &  Val,
const bool &  Asc = true 
)

Definition at line 2681 of file ds.h.

2681  {
2682  PLstNd Nd=Last();
2683  while ((Nd!=NULL)&&((Asc&&(Val<Nd->Val))||(!Asc&&(Val>Nd->Val)))){
2684  Nd=Nd->Prev();}
2685  return Ins(Nd, Val);
2686 }
PLstNd Ins(const PLstNd &Nd, const TVal &Val)
Definition: ds.h:2717
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
PLstNd Last() const
Definition: ds.h:2612
template<class TVal>
TLstNd< TVal > * TLst< TVal >::AddFront ( const TVal &  Val)

Definition at line 2652 of file ds.h.

2652  {
2653  PLstNd Nd=new TLstNd<TVal>(NULL, FirstNd, Val);
2654  if (FirstNd!=NULL){FirstNd->PrevNd=Nd; FirstNd=Nd;}
2655  else {FirstNd=Nd; LastNd=Nd;}
2656  Nds++; return Nd;
2657 }
int Nds
Definition: ds.h:2592
Definition: ds.h:2564
PLstNd LastNd
Definition: ds.h:2594
PLstNd FirstNd
Definition: ds.h:2593
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
TLstNd * PrevNd
Definition: ds.h:2566
template<class TVal>
TLstNd< TVal > * TLst< TVal >::AddFrontSorted ( const TVal &  Val,
const bool &  Asc = true 
)

Definition at line 2668 of file ds.h.

2668  {
2669  PLstNd Nd=First();
2670  if (Nd==NULL){
2671  return Ins(Nd, Val);
2672  } else {
2673  while ((Nd!=NULL)&&((Asc&&(Val>Nd()))||(!Asc&&(Val<Nd())))){
2674  Nd=Nd->Next();}
2675  if (Nd==NULL){return Ins(Nd->Last(), Val);}
2676  else {return Ins(Nd->Prev(), Val);}
2677  }
2678 }
PLstNd Ins(const PLstNd &Nd, const TVal &Val)
Definition: ds.h:2717
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
PLstNd First() const
Definition: ds.h:2611
template<class TVal>
void TLst< TVal >::Clr ( )
inline

Definition at line 2604 of file ds.h.

2604  {
2605  PLstNd Nd=FirstNd;
2606  while (Nd!=NULL){PLstNd NextNd=Nd->NextNd; delete Nd; Nd=NextNd;}
2607  Nds=0; FirstNd=NULL; LastNd=NULL;}
int Nds
Definition: ds.h:2592
PLstNd LastNd
Definition: ds.h:2594
PLstNd FirstNd
Definition: ds.h:2593
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
template<class TVal>
void TLst< TVal >::Del ( const TVal &  Val)

Definition at line 2728 of file ds.h.

2728  {
2729  PLstNd Nd=SearchForw(Val);
2730  if (Nd!=NULL){Del(Nd);}
2731 }
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
void Del(const TVal &Val)
Definition: ds.h:2728
PLstNd SearchForw(const TVal &Val)
Definition: ds.h:2744
template<class TVal>
void TLst< TVal >::Del ( const PLstNd Nd)

Definition at line 2734 of file ds.h.

2734  {
2735  Assert(Nd!=NULL);
2736  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
2737  else {Nd->PrevNd->NextNd=Nd->NextNd;}
2738  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
2739  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
2740  Nds--; delete Nd;
2741 }
int Nds
Definition: ds.h:2592
TLstNd * NextNd
Definition: ds.h:2567
PLstNd LastNd
Definition: ds.h:2594
PLstNd FirstNd
Definition: ds.h:2593
#define Assert(Cond)
Definition: bd.h:251
TLstNd * PrevNd
Definition: ds.h:2566
template<class TVal>
void TLst< TVal >::DelFirst ( )
inline

Definition at line 2625 of file ds.h.

2625 { PLstNd DelNd = FirstNd; Del(DelNd); }
PLstNd FirstNd
Definition: ds.h:2593
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
void Del(const TVal &Val)
Definition: ds.h:2728
template<class TVal>
void TLst< TVal >::DelLast ( )
inline

Definition at line 2626 of file ds.h.

2626 { PLstNd DelNd = LastNd; Del(DelNd); }
PLstNd LastNd
Definition: ds.h:2594
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
void Del(const TVal &Val)
Definition: ds.h:2728
template<class TVal>
bool TLst< TVal >::Empty ( ) const
inline

Definition at line 2609 of file ds.h.

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

Definition at line 2611 of file ds.h.

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

Definition at line 2613 of file ds.h.

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

Definition at line 2717 of file ds.h.

2717  {
2718  if (Nd==NULL){return AddFront(Val);}
2719  else if (Nd->NextNd==NULL){return AddBack(Val);}
2720  else {
2721  PLstNd NewNd=new TLstNd<TVal>(Nd, Nd->NextNd, Val);
2722  Nd->NextNd=NewNd; NewNd->NextNd->PrevNd=Nd;
2723  Nds++; return Nd;
2724  }
2725 }
int Nds
Definition: ds.h:2592
TLstNd * NextNd
Definition: ds.h:2567
Definition: ds.h:2564
PLstNd AddFront(const TVal &Val)
Definition: ds.h:2652
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
PLstNd AddBack(const TVal &Val)
Definition: ds.h:2660
TLstNd * PrevNd
Definition: ds.h:2566
template<class TVal>
PLstNd TLst< TVal >::Last ( ) const
inline

Definition at line 2612 of file ds.h.

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

Definition at line 2614 of file ds.h.

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

Definition at line 2610 of file ds.h.

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

Definition at line 2703 of file ds.h.

2703  {
2704  Assert(Nd!=NULL);
2705  // unchain
2706  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
2707  else {Nd->PrevNd->NextNd=Nd->NextNd;}
2708  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
2709  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
2710  // add to back
2711  Nd->PrevNd=LastNd; Nd->NextNd=NULL;
2712  if (LastNd!=NULL){LastNd->NextNd=Nd; LastNd=Nd;}
2713  else {FirstNd=Nd; LastNd=Nd;}
2714 }
TLstNd * NextNd
Definition: ds.h:2567
PLstNd LastNd
Definition: ds.h:2594
PLstNd FirstNd
Definition: ds.h:2593
#define Assert(Cond)
Definition: bd.h:251
TLstNd * PrevNd
Definition: ds.h:2566
template<class TVal >
void TLst< TVal >::PutFront ( const PLstNd Nd)

Definition at line 2689 of file ds.h.

2689  {
2690  Assert(Nd!=NULL);
2691  // unchain
2692  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
2693  else {Nd->PrevNd->NextNd=Nd->NextNd;}
2694  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
2695  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
2696  // add to front
2697  Nd->PrevNd=NULL; Nd->NextNd=FirstNd;
2698  if (FirstNd!=NULL){FirstNd->PrevNd=Nd; FirstNd=Nd;}
2699  else {FirstNd=Nd; LastNd=Nd;}
2700 }
TLstNd * NextNd
Definition: ds.h:2567
PLstNd LastNd
Definition: ds.h:2594
PLstNd FirstNd
Definition: ds.h:2593
#define Assert(Cond)
Definition: bd.h:251
TLstNd * PrevNd
Definition: ds.h:2566
template<class TVal >
void TLst< TVal >::Save ( TSOut SOut) const

Definition at line 2643 of file ds.h.

2643  {
2644  SOut.Save(Nds);
2645  PLstNd Nd=FirstNd; int CheckNds=0;
2646  while (Nd!=NULL){
2647  Nd->Val.Save(SOut); Nd=Nd->NextNd; CheckNds++;}
2648  IAssert(Nds==CheckNds);
2649 }
#define IAssert(Cond)
Definition: bd.h:262
int Nds
Definition: ds.h:2592
TVal Val
Definition: ds.h:2568
PLstNd FirstNd
Definition: ds.h:2593
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
void Save(const bool &Bool)
Definition: fl.h:173
template<class TVal>
TLstNd< TVal > * TLst< TVal >::SearchBack ( const TVal &  Val)

Definition at line 2754 of file ds.h.

2754  {
2755  PLstNd Nd=Last();
2756  while (Nd!=NULL){
2757  if (Nd->GetVal()==Val){return Nd;}
2758  Nd=Nd->Prev();
2759  }
2760  return NULL;
2761 }
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
PLstNd Last() const
Definition: ds.h:2612
template<class TVal>
TLstNd< TVal > * TLst< TVal >::SearchForw ( const TVal &  Val)

Definition at line 2744 of file ds.h.

2744  {
2745  PLstNd Nd=First();
2746  while (Nd!=NULL){
2747  if (Nd->GetVal()==Val){return Nd;}
2748  Nd=Nd->Next();
2749  }
2750  return NULL;
2751 }
TLstNd< TVal > * PLstNd
Definition: ds.h:2590
PLstNd First() const
Definition: ds.h:2611

Friends And Related Function Documentation

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

Definition at line 2631 of file ds.h.

Member Data Documentation

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

Definition at line 2593 of file ds.h.

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

Definition at line 2594 of file ds.h.

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

Definition at line 2592 of file ds.h.


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