COIN-OR::LEMON - Graph Library

Changeset 1419:c3244a26adb1 in lemon-0.x


Ignore:
Timestamp:
05/14/05 19:34:31 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1889
Message:

Added backward and forward map.
Converting UndirEdge? -> Edge

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/graph_utils.h

    r1413 r1419  
    1919
    2020#include <iterator>
     21#include <vector>
    2122#include <map>
    2223
     
    267268
    268269  template <typename _Graph, typename _Item>
    269   class ItemSetTraits {
    270   };
     270  class ItemSetTraits {};
    271271 
    272272  template <typename _Graph>
     
    362362  };
    363363
    364 
    365364  /// Provides an immutable and unique id for each item in the graph.
    366365
     
    376375    typedef _Item Key;
    377376
     377    typedef True NeedCopy;
     378
    378379    /// \brief Constructor.
    379380    ///
     
    398399    class InverseMap {
    399400    public:
     401
     402      typedef True NeedCopy;
     403
    400404      /// \brief Constructor.
    401405      ///
     
    694698  class SourceMap {
    695699  public:
     700
     701    typedef True NeedCopy;
     702
    696703    typedef typename Graph::Node Value;
    697704    typedef typename Graph::Edge Key;
     
    732739  class TargetMap {
    733740  public:
     741
     742    typedef True NeedCopy;
     743
    734744    typedef typename Graph::Node Value;
    735745    typedef typename Graph::Edge Key;
     
    763773  }
    764774
     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
    765856
    766857  /// @}
Note: See TracChangeset for help on using the changeset viewer.