COIN-OR::LEMON - Graph Library

Changeset 977:48962802d168 in lemon-0.x for src/lemon/graph_utils.h


Ignore:
Timestamp:
11/10/04 21:14:32 (17 years ago)
Author:
Mihaly Barasz
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1365
Message:
  • enable_if imported from BOOST
  • count{Nodes,Edges} implemented via graph tags
  • some #include bugs fixed
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/graph_utils.h

    r967 r977  
    2121
    2222#include <lemon/invalid.h>
     23#include <lemon/utility.h>
    2324
    2425///\ingroup gutils
     
    3637/// @{
    3738
    38   // counters in the graph
    3939  /// \brief Function to count the items in the graph.
    4040  ///
     
    4444
    4545  template <typename Graph, typename ItemIt>
    46   inline int countItems(const Graph& _g) {
     46  inline int countItems(const Graph& g) {
    4747    int num = 0;
    48     for (ItemIt it(_g); it != INVALID; ++it) {
     48    for (ItemIt it(g); it != INVALID; ++it) {
    4949      ++num;
    5050    }
    5151    return num;
     52  }
     53
     54  // Node counting:
     55
     56  template <typename Graph>
     57  inline
     58  typename enable_if<typename Graph::NodeNumTag, int>::type
     59  _countNodes(const Graph &g) {
     60    return g.nodeNum();
     61  }
     62
     63  template <typename Graph>
     64  inline int _countNodes(Wrap<Graph> w) {
     65    return countItems<Graph, typename Graph::NodeIt>(w.value);
    5266  }
    5367
     
    5771  /// The complexity of the function is O(n) but for some
    5872  /// graph structure it is specialized to run in O(1).
    59 
    60   template <typename Graph>
    61   inline int countNodes(const Graph& _g) {
    62     return countItems<Graph, typename Graph::NodeIt>(_g);
     73  ///
     74  /// \todo refer how to specialize it
     75
     76  template <typename Graph>
     77  inline int countNodes(const Graph& g) {
     78    return _countNodes<Graph>(g);
     79  }
     80
     81  // Edge counting:
     82
     83  template <typename Graph>
     84  inline
     85  typename enable_if<typename Graph::EdgeNumTag, int>::type
     86  _countEdges(const Graph &g) {
     87    return g.edgeNum();
     88  }
     89
     90  template <typename Graph>
     91  inline int _countEdges(Wrap<Graph> w) {
     92    return countItems<Graph, typename Graph::EdgeIt>(w.value);
    6393  }
    6494
     
    6898  /// The complexity of the function is O(e) but for some
    6999  /// graph structure it is specialized to run in O(1).
    70   template <typename Graph>
    71   inline int countEdges(const Graph& _g) {
    72     return countItems<Graph, typename Graph::EdgeIt>(_g);
     100
     101  template <typename Graph>
     102  inline int countEdges(const Graph& g) {
     103    return _countEdges<Graph>(g);
    73104  }
    74105
     
    82113    return countItems<Graph, typename Graph::SymEdgeIt>(_g);
    83114  }
     115
    84116
    85117  template <typename Graph, typename DegIt>
Note: See TracChangeset for help on using the changeset viewer.