lemon/graph_utils.h
changeset 1454 e0177bbe75a9
parent 1453 08c8db58080e
child 1459 2ee881cf30a8
equal deleted inserted replaced
1:c908eb3be115 2:a3216579bb04
   861 
   861 
   862   ///\todo Undocumented
   862   ///\todo Undocumented
   863   ///
   863   ///
   864   template <typename _Graph>
   864   template <typename _Graph>
   865   class InDegMap  :
   865   class InDegMap  :
   866     protected _Graph::AlterationNotifier<typename _Graph::Node>::
   866     protected _Graph::template AlterationNotifier<typename _Graph::Node>::
   867     ObserverBase,
   867     ObserverBase,
   868     protected _Graph::AlterationNotifier<typename _Graph::Edge>::
   868     protected _Graph::template AlterationNotifier<typename _Graph::Edge>::
   869     ObserverBase
   869     ObserverBase
   870   {
   870   {
   871     typename _Graph::template NodeMap<int> deg;
   871     typename _Graph::template NodeMap<int> deg;
   872     const _Graph* graph;
   872     const _Graph* graph;
   873   public:
   873   public:
   877     /// \brief Constructor.
   877     /// \brief Constructor.
   878     ///
   878     ///
   879     /// Constructor for creating in-degree map.
   879     /// Constructor for creating in-degree map.
   880     InDegMap(const _Graph& _graph) : graph(_graph), deg(graph,0)
   880     InDegMap(const _Graph& _graph) : graph(_graph), deg(graph,0)
   881     {
   881     {
   882       typename _Graph::AlterationNotifier<typename _Graph::Node>::ObserverBase::
   882       typename _Graph::template AlterationNotifier<typename _Graph::Node>
   883 	attach(graph->getNotifier(typename _Graph::Node()));
   883 	::ObserverBase::attach(graph->getNotifier(typename _Graph::Node()));
   884       typename _Graph::AlterationNotifier<typename _Graph::Edge>::ObserverBase::
   884       typename _Graph::template AlterationNotifier<typename _Graph::Edge>
   885 	attach(graph->getNotifier(typename _Graph::Edge()));
   885 	::ObserverBase::attach(graph->getNotifier(typename _Graph::Edge()));
   886 
   886 
   887       for(typename _Graph::NodeIt n(g);n!=INVALID;++n)
   887       for(typename _Graph::NodeIt n(graph);n!=INVALID;++n)
   888 	for(typename _Graph::InEdgeIt e(g,n);e!=INVALID;++e)
   888 	for(typename _Graph::InEdgeIt e(graph,n);e!=INVALID;++e)
   889 	  deg[e]++;
   889 	  deg[e]++;
   890     }
   890     }
   891 
   891 
   892     ~InDegMap() 
   892     ~InDegMap() 
   893     {
   893     {
   894       typename _Graph::AlterationNotifier<typename _Graph::Node>::
   894       typename _Graph::template AlterationNotifier<typename _Graph::Node>::
   895 	ObserverBase::detach();
   895 	ObserverBase::detach();
   896       typename _Graph::AlterationNotifier<typename _Graph::Edge>::
   896       typename _Graph::template AlterationNotifier<typename _Graph::Edge>::
   897 	ObserverBase::detach();
   897 	ObserverBase::detach();
   898     }
   898     }
   899     
   899     
   900     /// Gives back the in degree of a Node.
   900     /// Gives back the in degree of a Node.
   901     int operator[](const Key& k) const { return deg[k];}
   901     int operator[](const Key& k) const { return deg[k];}
   902 
   902 
   903   protected:
   903   protected:
   904     virtual void add(const typename _Graph::Node& n) {
   904     virtual void add(const typename _Graph::Node& n) {
   905       ///\bug Which 'add' comes before to other?
   905       ///\bug Which 'add' comes before to other?
   906       deg[n]=0;
   906       deg[n]=0;
   907     };
   907     }
   908     virtual void erase(const typename _Graph::Node&) 
   908     virtual void erase(const typename _Graph::Node&) 
   909     {
   909     {
   910     }
   910     }
   911     virtual void add(const typename _Graph::Edge& n) {
   911     virtual void add(const typename _Graph::Edge& e) {
   912       deg[graph.target(e)]++;
   912       deg[graph.target(e)]++;
   913     };
   913     }
   914     virtual void erase(const typename _Graph::Edge&) 
   914     virtual void erase(const typename _Graph::Edge& e) {
   915     {
       
   916       deg[graph.target(e)]--;
   915       deg[graph.target(e)]--;
   917     }
   916     }
   918 
   917 
   919 
   918 
   920   };
   919   };