shape_doc 0.1
Graph< T > Class Template Reference

#include <graph.hpp>

List of all members.

Public Member Functions

Friends


Detailed Description

template<class T>
class mmx::shape::Graph< T >

Definition at line 112 of file graph.hpp.


Constructor & Destructor Documentation

Graph ( ) [inline]

Definition at line 126 of file graph.hpp.

    {
      nvertices=nedges=0;
      head=NULL;
    }

Member Function Documentation

GraphDfsIter< T > * createIterator ( ) const

Definition at line 305 of file graph.hpp.

{
  return new GraphDfsIter<T>(this);
}
void delete_edge ( v_val,
e_val 
)

Deletes an edge.

Definition at line 466 of file graph.hpp.

References head.

{
  if(head==NULL)
    return;
  
  gNode<T> *s, *t=head;
  
  while(t!=NULL)
  {                  
    if(t->data==v_val)         
    {                         
      s=t;
      t=t->next;
      while(t!=NULL)
      {               
        if(t->data==e_val)
         {           
           s->next=t->next;
           t->vlist=NULL; 
           delete t;
           nedges--;
           return;
         }
        s=t;
        t=t->next;
      }
      return;                                            
    }
    t=t->vlist;
  }
  
}
void delete_vertex ( val)

Deletes a vertex and all incident edges.

Definition at line 501 of file graph.hpp.

References head.

{
  if(head==NULL)
    return;
  nvertices--;
  
  gNode<T>* e=head;
  
  // Delete edges from other vertices lists
  while(e!=NULL)
     {
       delete_edge(e->data,v_val);
       e=e->vlist;
     }
  
  // Delete incident edges
  e=head;
  while(e!=NULL)
     {
       delete_edge(v_val,e->data);
       e=e->vlist;
     }
  
  //Delete Vertex
  if(head->data==v_val)
  {
    gNode<T>* temp=head;
    head=head->vlist;
    delete temp;
    return;
  }
  
  gNode<T>* p1=head->vlist;
  gNode<T>* p2=head;
  
  while(p1!=NULL)
  {
    if(p1->data==v_val)
    {
      p2->vlist=p1->vlist;
      p1=NULL;
      delete p1;
      return;
    }
    p2=p1;
    p1=p1->vlist;
  }
}
void dfs ( Seq< T > &  out)

DFS traversal (output node data in DFS order)

Definition at line 653 of file graph.hpp.

References head, and gNode< T >::status().

{
  gNode<T>* t=head;
  
  while(t!=NULL)
  {
    t->status(-1);
    t=t->vlist;
  }
  
  t=head;
  while(t!=NULL)
  {
    if (t->status()==-1) 
      dfs_walk(t,out);
    t=t->vlist;
  }
}
void dfs ( func  fp)

DFS traversal (run operation fp on nodes)

Definition at line 602 of file graph.hpp.

References head, and gNode< T >::status().

Referenced by mmx::shape::print_boxes().

{
  gNode<T>* t=head;
  
  while(t!=NULL)
  {
    t.status(-1);
    t=t->vlist;
  }
  
  t=head;
  while(t!=NULL)
  {
    if (t->status()==-1) dfs_walk(t,fp);
    t=t->vlist;
  }
}
gNode< T > * dfs ( test_node  fp)

DFS search (find a node that satisfies test fp)

Definition at line 705 of file graph.hpp.

References head, NODESTACK, and gNode< T >::status().

{
  gNode<T>* t=head;
  
  while(t!=NULL)
  {
    t->status(-1);
    t=t->vlist;
  }
  
  t=head;
  while(t!=NULL)
  {
    if (t->status()==-1) 
    {
      NODESTACK q;
      gNode<T> * s;
      
      q.push(t);
      t->status(0);    // mark as visited
      
      while ( !q.empty() )
      {
        s=q.top();
        q.pop();
        

        if (fp!=NULL)
          if ( (*fp)(s) ) // check node
            return s;
        
        while(t->next!=NULL)
        {
          if (t->next->status()==-1)
          {
            t->status(0); // mark as visited
            q.push(t->next->start); 
          }
          
          t=t->next;
        }
      }
    }
    t=t->vlist;
  }
  
  return NULL;
}
void dfs_walk ( gNode< T > *  s,
Seq< T > &  out 
)

Definition at line 673 of file graph.hpp.

References NODESTACK, and gNode< T >::status().

{
  NODESTACK q;
  gNode<T> * t;
  
  q.push(s);
  
  while ( !q.empty() )
  {
    t=q.top();
    q.pop();
    if ( t->status()==-1)
    {
    out<< t->data; // output node data
    t->status(0); // mark as visited 
    }
     while(t->next!=NULL)
     {
       if ( t->next->status() == -1 )
       {
         q.push(t->next->start); 
       }
       t=t->next;
     }

  }
}
void dfs_walk ( gNode< T > *  s,
func  fp 
)

Definition at line 621 of file graph.hpp.

References NODESTACK, and gNode< T >::status().

{
  NODESTACK q;
  gNode<T> * t;
  
  q.push(s);
  s->status(0);                  // mark as visited
  
  while ( !q.empty() )
  {
    t=q.top();
    q.pop();
    
    if (fp!=NULL) (*fp)(t);       // run operation on node
    //std::cout<< t->data<<std::endl;
    
    while(t->next!=NULL)
    {
      if (t->next->status()==-1)
      {
        t->status(0); // mark as visited 
        q.push(t->next->start); 
      }
      t=t->next;
    }
  }
}
void edge_list ( Seq< T > &  e) const

Definition at line 389 of file graph.hpp.

References head.

{
  gNode<T>*s, *t=head;
  while( t!=NULL)
  {
    s=t;
    while ( s->next!=NULL)
    {
      e<< t->data << s->next->data ;
      s=s->next;
    }
    t=t->vlist;
  }
}
gNode< T > * get_start_node ( )

Definition at line 552 of file graph.hpp.

References head.

{
  return head;
}
bool member ( val) const [inline]

Definition at line 445 of file graph.hpp.

References head.

                            {
  gNode<T> *t=head;
  while( t!=NULL)
    if(t->data==val)
      return true;
    else
      t=t->vlist;
  return false;
}
unsigned nbe ( ) const [inline]

Definition at line 143 of file graph.hpp.

{ return nedges;   };
unsigned nbv ( ) const [inline]

Definition at line 142 of file graph.hpp.

{ return nvertices;};
Seq< T > neighbors ( e)

Definition at line 406 of file graph.hpp.

References head.

{
    Seq<T> e;
    gNode<T>*s, *t=head;
    while( t!=NULL)
    {
      if(t->data==v_val)
      {         
        s=t;
           while ( s->next!=NULL)
           {
             //e<< t->data << s->next->data ;
             e<< s->next->data ;
             s=s->next;
           }
      }
      t=t->vlist;
    }
    return e;
}
T next ( val) const [inline]

Definition at line 429 of file graph.hpp.

References head.

                          {
  gNode<T> *t=head;
  while( t!=NULL){
    if(t->data==val)
    {   if (t->next==NULL)
        std::cout<<"no neighbor!"<<std::endl;
      return t->next->data;
    }
    t=t->vlist;
  }
  std::cout<< "Node not in graph."<<std::endl;
  return NULL;
}
void print ( ) [inline]

Print rep of graph - for testing.

Definition at line 171 of file graph.hpp.

    {
      std::cout<< "Graph: "<< std::endl;
      gNode<T> *s, *t=head;
      while(t!=NULL)
      {
        std::cout<< t->data<<" ===> ";
        s=t->next;
        while(s!=NULL)
        {   std::cout<< s->data<<", "; s=s->next;}
        std::cout<< std::endl;
        t=t->vlist;
      }
      std::cout<< std::endl;
    }
void push_edge ( v_val,
e_val 
)

Insert edge.

Definition at line 337 of file graph.hpp.

References head.

Referenced by Graph< Point * >::push_uedge().

{
  if(head==NULL)
    return;
  nedges++;
  
  gNode<T>* t=head;
  
  while(t!=NULL) //find vertex v
  {
     if(t->data==v_val)
     {  
       gNode<T>* temp=new gNode<T>(e_val);
       
       while(t->next!=NULL)
         t=t->next;
       t->next=temp;// add e to v's neighbors
       
       t=head;//update node info
       while(t!=NULL)
       {
         if(t->data==e_val)
         {
           temp->me=t->me;
           t->me=temp;               
           //temp->vlist=t->vlist;
           temp->start=t;
         }
         t=t->vlist;
       }
       
       return;
     }
     t=t->vlist;
  }
}
void push_uedge ( v_val,
e_val 
) [inline]

Definition at line 138 of file graph.hpp.

Referenced by voronoi2d< C, V >::insert_regular().

    {push_edge(v_val,e_val); push_edge(e_val,v_val);};
gNode< T > * push_vertex ( val,
int  i = 0 
)

Insert vertex.

Definition at line 312 of file graph.hpp.

References gNode< T >::aux(), and head.

Referenced by voronoi2d< C, V >::insert_regular().

{
 gNode<T>* temp=new gNode<T>(val);
 temp->aux(i);

   nvertices++;
   if(head==NULL)
    {
     head=temp;
     head->me=temp;
     return temp;
    }

   gNode<T>* t=head;
   while(t->vlist!=NULL)
    t=t->vlist;

   t->vlist=temp;
   temp->start=temp;
   temp->me=temp;
   return temp;
}
bool set_start_node ( T &  val)

Definition at line 558 of file graph.hpp.

References head.

{
  gNode<T>* k=head;
  
  while(k->vlist!=NULL)  //check that vertex exists
  {
    if(k->vlist->data==val)
      break;
    k=k->vlist;
  }
  if (k->vlist==NULL) return false;
  
  gNode<T> *u= k->vlist;
  k->vlist  = u->vlist;
  u->vlist  = this->head;
  this->head= u;
}
bool set_start_node ( T &  v_val,
T &  e_val 
)

Definition at line 577 of file graph.hpp.

References head.

{
  gNode<T>* k=this->head->next;
  
  if (!set_start_node(v_val)) return false;
  
  while(k->next!=NULL)
  {
    if(k->next->data==e_val)
      break;
    k=k->next;
  }
  if (k->next==NULL) return false;
  
  gNode<T> *u= k->next;
  k->next  = u->next;
  u->next  = this->head->next;
  this->head->next= u;
}
void vertex_list ( Seq< T > &  v) const

Fills sequence v with node data.

Definition at line 376 of file graph.hpp.

References head.

{
  gNode<T>* t= head;
  
  while(t!=NULL)
  {
    v << t->data;
    t=t->vlist;
  }
}

Friends And Related Function Documentation

friend class GraphDfsIter< T > [friend]

Definition at line 114 of file graph.hpp.


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