src/lemon/graph_utils.h
changeset 1428 9ba88ddc629c
parent 1413 3f45d58969d4
equal deleted inserted replaced
13:8477bfeb497c 14:3bacff0fb093
    16 
    16 
    17 #ifndef LEMON_GRAPH_UTILS_H
    17 #ifndef LEMON_GRAPH_UTILS_H
    18 #define LEMON_GRAPH_UTILS_H
    18 #define LEMON_GRAPH_UTILS_H
    19 
    19 
    20 #include <iterator>
    20 #include <iterator>
       
    21 #include <vector>
    21 #include <map>
    22 #include <map>
    22 
    23 
    23 #include <lemon/invalid.h>
    24 #include <lemon/invalid.h>
    24 #include <lemon/utility.h>
    25 #include <lemon/utility.h>
    25 #include <lemon/maps.h>
    26 #include <lemon/maps.h>
   264      
   265      
   265   };
   266   };
   266 
   267 
   267 
   268 
   268   template <typename _Graph, typename _Item>
   269   template <typename _Graph, typename _Item>
   269   class ItemSetTraits {
   270   class ItemSetTraits {};
   270   };
       
   271   
   271   
   272   template <typename _Graph>
   272   template <typename _Graph>
   273   class ItemSetTraits<_Graph, typename _Graph::Node> {
   273   class ItemSetTraits<_Graph, typename _Graph::Node> {
   274   public:
   274   public:
   275     
   275     
   359     typedef typename Map::ConstReference ConstReference;
   359     typedef typename Map::ConstReference ConstReference;
   360     typedef typename Map::Pointer Pointer;
   360     typedef typename Map::Pointer Pointer;
   361     typedef typename Map::ConstPointer ConstPointer;
   361     typedef typename Map::ConstPointer ConstPointer;
   362   };
   362   };
   363 
   363 
   364 
       
   365   /// Provides an immutable and unique id for each item in the graph.
   364   /// Provides an immutable and unique id for each item in the graph.
   366 
   365 
   367   /// The IdMap class provides an unique and immutable mapping for each item
   366   /// The IdMap class provides an unique and immutable mapping for each item
   368   /// in the graph.
   367   /// in the graph.
   369   ///
   368   ///
   373     typedef _Graph Graph;
   372     typedef _Graph Graph;
   374     typedef int Value;
   373     typedef int Value;
   375     typedef _Item Item;
   374     typedef _Item Item;
   376     typedef _Item Key;
   375     typedef _Item Key;
   377 
   376 
       
   377     typedef True NeedCopy;
       
   378 
   378     /// \brief Constructor.
   379     /// \brief Constructor.
   379     ///
   380     ///
   380     /// Constructor for creating id map.
   381     /// Constructor for creating id map.
   381     IdMap(const Graph& _graph) : graph(&_graph) {}
   382     IdMap(const Graph& _graph) : graph(&_graph) {}
   382 
   383 
   395     ///
   396     ///
   396     /// The class represents the inverse of the map.
   397     /// The class represents the inverse of the map.
   397     /// \see inverse()
   398     /// \see inverse()
   398     class InverseMap {
   399     class InverseMap {
   399     public:
   400     public:
       
   401 
       
   402       typedef True NeedCopy;
       
   403 
   400       /// \brief Constructor.
   404       /// \brief Constructor.
   401       ///
   405       ///
   402       /// Constructor for creating an id-to-item map.
   406       /// Constructor for creating an id-to-item map.
   403       InverseMap(const Graph& _graph) : graph(&_graph) {}
   407       InverseMap(const Graph& _graph) : graph(&_graph) {}
   404 
   408 
   691   /// The SourceMap gives back the source Node of the given edge. 
   695   /// The SourceMap gives back the source Node of the given edge. 
   692   /// \author Balazs Dezso
   696   /// \author Balazs Dezso
   693   template <typename Graph>
   697   template <typename Graph>
   694   class SourceMap {
   698   class SourceMap {
   695   public:
   699   public:
       
   700 
       
   701     typedef True NeedCopy;
       
   702 
   696     typedef typename Graph::Node Value;
   703     typedef typename Graph::Node Value;
   697     typedef typename Graph::Edge Key;
   704     typedef typename Graph::Edge Key;
   698 
   705 
   699     /// \brief Constructor
   706     /// \brief Constructor
   700     ///
   707     ///
   729   /// The TargetMap gives back the target Node of the given edge. 
   736   /// The TargetMap gives back the target Node of the given edge. 
   730   /// \author Balazs Dezso
   737   /// \author Balazs Dezso
   731   template <typename Graph>
   738   template <typename Graph>
   732   class TargetMap {
   739   class TargetMap {
   733   public:
   740   public:
       
   741 
       
   742     typedef True NeedCopy;
       
   743 
   734     typedef typename Graph::Node Value;
   744     typedef typename Graph::Node Value;
   735     typedef typename Graph::Edge Key;
   745     typedef typename Graph::Edge Key;
   736 
   746 
   737     /// \brief Constructor
   747     /// \brief Constructor
   738     ///
   748     ///
   760   template <typename Graph>
   770   template <typename Graph>
   761   inline TargetMap<Graph> targetMap(const Graph& graph) {
   771   inline TargetMap<Graph> targetMap(const Graph& graph) {
   762     return TargetMap<Graph>(graph);
   772     return TargetMap<Graph>(graph);
   763   }
   773   }
   764 
   774 
       
   775   /// \brief Returns the "forward" directed edge view of undirected edge.
       
   776   ///
       
   777   /// Returns the "forward" directed edge view of undirected edge.
       
   778   /// \author Balazs Dezso
       
   779   template <typename Graph>
       
   780   class ForwardMap {
       
   781   public:
       
   782 
       
   783     typedef True NeedCopy;
       
   784 
       
   785     typedef typename Graph::Edge Value;
       
   786     typedef typename Graph::UndirEdge Key;
       
   787 
       
   788     /// \brief Constructor
       
   789     ///
       
   790     /// Constructor
       
   791     /// \param _graph The graph that the map belongs to.
       
   792     ForwardMap(const Graph& _graph) : graph(_graph) {}
       
   793 
       
   794     /// \brief The subscript operator.
       
   795     ///
       
   796     /// The subscript operator.
       
   797     /// \param key An undirected edge 
       
   798     /// \return The "forward" directed edge view of undirected edge 
       
   799     Value operator[](const Key& key) const {
       
   800       return graph.edgeWithSource(key, graph.source(key));
       
   801     }
       
   802 
       
   803   private:
       
   804     const Graph& graph;
       
   805   };
       
   806 
       
   807   /// \brief Returns a \ref ForwardMap class
       
   808 
       
   809   /// This function just returns an \ref ForwardMap class.
       
   810   /// \relates ForwardMap
       
   811   template <typename Graph>
       
   812   inline ForwardMap<Graph> forwardMap(const Graph& graph) {
       
   813     return ForwardMap<Graph>(graph);
       
   814   }
       
   815 
       
   816   /// \brief Returns the "backward" directed edge view of undirected edge.
       
   817   ///
       
   818   /// Returns the "backward" directed edge view of undirected edge.
       
   819   /// \author Balazs Dezso
       
   820   template <typename Graph>
       
   821   class BackwardMap {
       
   822   public:
       
   823     typedef True NeedCopy;
       
   824 
       
   825     typedef typename Graph::Edge Value;
       
   826     typedef typename Graph::UndirEdge Key;
       
   827 
       
   828     /// \brief Constructor
       
   829     ///
       
   830     /// Constructor
       
   831     /// \param _graph The graph that the map belongs to.
       
   832     BackwardMap(const Graph& _graph) : graph(_graph) {}
       
   833 
       
   834     /// \brief The subscript operator.
       
   835     ///
       
   836     /// The subscript operator.
       
   837     /// \param key An undirected edge 
       
   838     /// \return The "backward" directed edge view of undirected edge 
       
   839     Value operator[](const Key& key) const {
       
   840       return graph.edgeWithSource(key, graph.target(key));
       
   841     }
       
   842 
       
   843   private:
       
   844     const Graph& graph;
       
   845   };
       
   846 
       
   847   /// \brief Returns a \ref BackwardMap class
       
   848 
       
   849   /// This function just returns an \ref BackwardMap class.
       
   850   /// \relates BackwardMap
       
   851   template <typename Graph>
       
   852   inline BackwardMap<Graph> backwardMap(const Graph& graph) {
       
   853     return BackwardMap<Graph>(graph);
       
   854   }
       
   855 
   765 
   856 
   766   /// @}
   857   /// @}
   767 
   858 
   768 } //END OF NAMESPACE LEMON
   859 } //END OF NAMESPACE LEMON
   769 
   860