# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1251217789 -7200
# Node ID 6959186d3612eee5b995e5f2073ed9409fd7c5ce
# Parent a3de05c56e7e87f6c030016f32ba7ef664519f70
Extend the interface of StaticDigraph (#68)
with index(), arc() and node() functions similarly to
other static graph structures.
diff --git a/lemon/static_graph.h b/lemon/static_graph.h
a
|
b
|
|
235 | 235 | /// However it only provides build() and clear() functions and does not |
236 | 236 | /// support any other modification of the digraph. |
237 | 237 | /// |
| 238 | /// Since this digraph structure is completely static, its nodes and arcs |
| 239 | /// can be indexed with integers from the ranges <tt>[0..nodeNum()-1]</tt> |
| 240 | /// and <tt>[0..arcNum()-1]</tt>, respectively. |
| 241 | /// The index of an item is the same as its ID, it can be obtained |
| 242 | /// using the corresponding \ref index() or \ref concepts::Digraph::id() |
| 243 | /// "id()" function. A node or arc with a certain index can be obtained |
| 244 | /// using node() or arc(). |
| 245 | /// |
238 | 246 | /// This type fully conforms to the \ref concepts::Digraph "Digraph concept". |
239 | 247 | /// Most of its member functions and nested classes are documented |
240 | 248 | /// only in the concept class. |
… |
… |
|
247 | 255 | |
248 | 256 | public: |
249 | 257 | |
250 | | /// \brief Clear the digraph. |
| 258 | /// \brief Constructor |
251 | 259 | /// |
252 | | /// This function erases all nodes and arcs from the digraph. |
253 | | void clear() { |
254 | | Parent::clear(); |
255 | | } |
256 | | |
| 260 | /// Default constructor. |
| 261 | StaticDigraph() : Parent() {} |
| 262 | |
| 263 | /// \brief The node with the given index. |
| 264 | /// |
| 265 | /// This function returns the node with the given index. |
| 266 | /// \sa index() |
| 267 | Node node(int ix) const { return Parent::nodeFromId(ix); } |
| 268 | |
| 269 | /// \brief The arc with the given index. |
| 270 | /// |
| 271 | /// This function returns the arc with the given index. |
| 272 | /// \sa index() |
| 273 | Arc arc(int ix) const { return Parent::arcFromId(ix); } |
| 274 | |
| 275 | /// \brief The index of the given node. |
| 276 | /// |
| 277 | /// This function returns the index of the the given node. |
| 278 | /// \sa node() |
| 279 | int index(Node node) const { return Parent::id(node); } |
| 280 | |
| 281 | /// \brief The index of the given arc. |
| 282 | /// |
| 283 | /// This function returns the index of the the given arc. |
| 284 | /// \sa arc() |
| 285 | int index(Arc arc) const { return Parent::id(arc); } |
| 286 | |
| 287 | /// \brief Number of nodes. |
| 288 | /// |
| 289 | /// This function returns the number of nodes. |
| 290 | int nodeNum() const { return node_num; } |
| 291 | |
| 292 | /// \brief Number of arcs. |
| 293 | /// |
| 294 | /// This function returns the number of arcs. |
| 295 | int arcNum() const { return arc_num; } |
| 296 | |
257 | 297 | /// \brief Build the digraph copying another digraph. |
258 | 298 | /// |
259 | 299 | /// This function builds the digraph copying another digraph of any |
… |
… |
|
284 | 324 | Parent::build(digraph, nodeRef, arcRef); |
285 | 325 | } |
286 | 326 | |
| 327 | /// \brief Clear the digraph. |
| 328 | /// |
| 329 | /// This function erases all nodes and arcs from the digraph. |
| 330 | void clear() { |
| 331 | Parent::clear(); |
| 332 | } |
287 | 333 | |
288 | 334 | protected: |
289 | 335 | |
diff --git a/test/digraph_test.cc b/test/digraph_test.cc
a
|
b
|
|
445 | 445 | checkArcIds(G); |
446 | 446 | checkGraphNodeMap(G); |
447 | 447 | checkGraphArcMap(G); |
| 448 | |
| 449 | int n = G.nodeNum(); |
| 450 | int m = G.arcNum(); |
| 451 | check(G.index(G.node(n-1)) == n-1, "Wrong index."); |
| 452 | check(G.index(G.arc(m-1)) == m-1, "Wrong index."); |
448 | 453 | } |
449 | 454 | |
450 | 455 | void checkFullDigraph(int num) { |