Count ANodes-BNodes
authordeba
Mon, 03 Apr 2006 08:41:52 +0000
changeset 2029e00114f165f5
parent 2028 d0e8a86a1ff2
child 2030 d769d2eb4d50
Count ANodes-BNodes
lemon/graph_utils.h
     1.1 --- a/lemon/graph_utils.h	Fri Mar 31 12:51:44 2006 +0000
     1.2 +++ b/lemon/graph_utils.h	Mon Apr 03 08:41:52 2006 +0000
     1.3 @@ -147,6 +147,72 @@
     1.4      return _graph_utils_bits::CountNodesSelector<Graph>::count(g);
     1.5    }
     1.6  
     1.7 +  namespace _graph_utils_bits {
     1.8 +    
     1.9 +    template <typename Graph, typename Enable = void>
    1.10 +    struct CountANodesSelector {
    1.11 +      static int count(const Graph &g) {
    1.12 +        return countItems<Graph, typename Graph::ANode>(g);
    1.13 +      }
    1.14 +    };
    1.15 +
    1.16 +    template <typename Graph>
    1.17 +    struct CountANodesSelector<
    1.18 +      Graph, typename 
    1.19 +      enable_if<typename Graph::NodeNumTag, void>::type> 
    1.20 +    {
    1.21 +      static int count(const Graph &g) {
    1.22 +        return g.nodeNum();
    1.23 +      }
    1.24 +    };    
    1.25 +  }
    1.26 +
    1.27 +  /// \brief Function to count the anodes in the graph.
    1.28 +  ///
    1.29 +  /// This function counts the anodes in the graph.
    1.30 +  /// The complexity of the function is O(an) but for some
    1.31 +  /// graph structures it is specialized to run in O(1).
    1.32 +  ///
    1.33 +  /// \todo refer how to specialize it
    1.34 +
    1.35 +  template <typename Graph>
    1.36 +  inline int countANodes(const Graph& g) {
    1.37 +    return _graph_utils_bits::CountANodesSelector<Graph>::count(g);
    1.38 +  }
    1.39 +
    1.40 +  namespace _graph_utils_bits {
    1.41 +    
    1.42 +    template <typename Graph, typename Enable = void>
    1.43 +    struct CountBNodesSelector {
    1.44 +      static int count(const Graph &g) {
    1.45 +        return countItems<Graph, typename Graph::BNode>(g);
    1.46 +      }
    1.47 +    };
    1.48 +
    1.49 +    template <typename Graph>
    1.50 +    struct CountBNodesSelector<
    1.51 +      Graph, typename 
    1.52 +      enable_if<typename Graph::NodeNumTag, void>::type> 
    1.53 +    {
    1.54 +      static int count(const Graph &g) {
    1.55 +        return g.nodeNum();
    1.56 +      }
    1.57 +    };    
    1.58 +  }
    1.59 +
    1.60 +  /// \brief Function to count the bnodes in the graph.
    1.61 +  ///
    1.62 +  /// This function counts the bnodes in the graph.
    1.63 +  /// The complexity of the function is O(bn) but for some
    1.64 +  /// graph structures it is specialized to run in O(1).
    1.65 +  ///
    1.66 +  /// \todo refer how to specialize it
    1.67 +
    1.68 +  template <typename Graph>
    1.69 +  inline int countBNodes(const Graph& g) {
    1.70 +    return _graph_utils_bits::CountBNodesSelector<Graph>::count(g);
    1.71 +  }
    1.72 +
    1.73  
    1.74    // Edge counting:
    1.75