143 /// \todo refer how to specialize it |
143 /// \todo refer how to specialize it |
144 |
144 |
145 template <typename Graph> |
145 template <typename Graph> |
146 inline int countNodes(const Graph& g) { |
146 inline int countNodes(const Graph& g) { |
147 return _graph_utils_bits::CountNodesSelector<Graph>::count(g); |
147 return _graph_utils_bits::CountNodesSelector<Graph>::count(g); |
|
148 } |
|
149 |
|
150 namespace _graph_utils_bits { |
|
151 |
|
152 template <typename Graph, typename Enable = void> |
|
153 struct CountANodesSelector { |
|
154 static int count(const Graph &g) { |
|
155 return countItems<Graph, typename Graph::ANode>(g); |
|
156 } |
|
157 }; |
|
158 |
|
159 template <typename Graph> |
|
160 struct CountANodesSelector< |
|
161 Graph, typename |
|
162 enable_if<typename Graph::NodeNumTag, void>::type> |
|
163 { |
|
164 static int count(const Graph &g) { |
|
165 return g.nodeNum(); |
|
166 } |
|
167 }; |
|
168 } |
|
169 |
|
170 /// \brief Function to count the anodes in the graph. |
|
171 /// |
|
172 /// This function counts the anodes in the graph. |
|
173 /// The complexity of the function is O(an) but for some |
|
174 /// graph structures it is specialized to run in O(1). |
|
175 /// |
|
176 /// \todo refer how to specialize it |
|
177 |
|
178 template <typename Graph> |
|
179 inline int countANodes(const Graph& g) { |
|
180 return _graph_utils_bits::CountANodesSelector<Graph>::count(g); |
|
181 } |
|
182 |
|
183 namespace _graph_utils_bits { |
|
184 |
|
185 template <typename Graph, typename Enable = void> |
|
186 struct CountBNodesSelector { |
|
187 static int count(const Graph &g) { |
|
188 return countItems<Graph, typename Graph::BNode>(g); |
|
189 } |
|
190 }; |
|
191 |
|
192 template <typename Graph> |
|
193 struct CountBNodesSelector< |
|
194 Graph, typename |
|
195 enable_if<typename Graph::NodeNumTag, void>::type> |
|
196 { |
|
197 static int count(const Graph &g) { |
|
198 return g.nodeNum(); |
|
199 } |
|
200 }; |
|
201 } |
|
202 |
|
203 /// \brief Function to count the bnodes in the graph. |
|
204 /// |
|
205 /// This function counts the bnodes in the graph. |
|
206 /// The complexity of the function is O(bn) but for some |
|
207 /// graph structures it is specialized to run in O(1). |
|
208 /// |
|
209 /// \todo refer how to specialize it |
|
210 |
|
211 template <typename Graph> |
|
212 inline int countBNodes(const Graph& g) { |
|
213 return _graph_utils_bits::CountBNodesSelector<Graph>::count(g); |
148 } |
214 } |
149 |
215 |
150 |
216 |
151 // Edge counting: |
217 // Edge counting: |
152 |
218 |