Changes in lemon/core.h [220:a5d8c039f218:319:5e12d7734036] in lemon
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/core.h
r220 r319 25 25 #include <lemon/bits/enable_if.h> 26 26 #include <lemon/bits/traits.h> 27 #include <lemon/assert.h> 27 28 28 29 ///\file 29 30 ///\brief LEMON core utilities. 31 /// 32 ///This header file contains core utilities for LEMON. 33 ///It is automatically included by all graph types, therefore it usually 34 ///do not have to be included directly. 30 35 31 36 namespace lemon { … … 55 60 /// @{ 56 61 57 ///Create sconvenience typedefs for the digraph types and iterators58 59 ///This \c \#define creates convenien ce typedefs for the following types60 /// of \c Digraph: \c Node, \c NodeIt, \c Arc, \c ArcIt, \c InArcIt,62 ///Create convenience typedefs for the digraph types and iterators 63 64 ///This \c \#define creates convenient type definitions for the following 65 ///types of \c Digraph: \c Node, \c NodeIt, \c Arc, \c ArcIt, \c InArcIt, 61 66 ///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap, 62 67 ///\c BoolArcMap, \c IntArcMap, \c DoubleArcMap. … … 79 84 typedef Digraph::ArcMap<double> DoubleArcMap 80 85 81 ///Create sconvenience typedefs for the digraph types and iterators86 ///Create convenience typedefs for the digraph types and iterators 82 87 83 88 ///\see DIGRAPH_TYPEDEFS … … 99 104 typedef typename Digraph::template ArcMap<double> DoubleArcMap 100 105 101 ///Create sconvenience typedefs for the graph types and iterators102 103 ///This \c \#define creates the same convenien ce typedefs as defined106 ///Create convenience typedefs for the graph types and iterators 107 108 ///This \c \#define creates the same convenient type definitions as defined 104 109 ///by \ref DIGRAPH_TYPEDEFS(Graph) and six more, namely it creates 105 110 ///\c Edge, \c EdgeIt, \c IncEdgeIt, \c BoolEdgeMap, \c IntEdgeMap, … … 107 112 /// 108 113 ///\note If the graph type is a dependent type, ie. the graph type depend 109 ///on a template parameter, then use \c TEMPLATE_ DIGRAPH_TYPEDEFS()114 ///on a template parameter, then use \c TEMPLATE_GRAPH_TYPEDEFS() 110 115 ///macro. 111 116 #define GRAPH_TYPEDEFS(Graph) \ … … 118 123 typedef Graph::EdgeMap<double> DoubleEdgeMap 119 124 120 ///Create sconvenience typedefs for the graph types and iterators125 ///Create convenience typedefs for the graph types and iterators 121 126 122 127 ///\see GRAPH_TYPEDEFS … … 133 138 typedef typename Graph::template EdgeMap<double> DoubleEdgeMap 134 139 135 /// \brief Function to count the items in thegraph.136 /// 137 /// This function counts the items (nodes, arcs etc ) in thegraph.138 /// The complexity of the function is O(n)because140 /// \brief Function to count the items in a graph. 141 /// 142 /// This function counts the items (nodes, arcs etc.) in a graph. 143 /// The complexity of the function is linear because 139 144 /// it iterates on all of the items. 140 145 template <typename Graph, typename Item> … … 173 178 /// 174 179 /// This function counts the nodes in the graph. 175 /// The complexity of the function is O(n)but for some176 /// graph structures it is specialized to run in O(1).177 /// 178 /// If the graph contains a \enodeNum() member function and a179 /// \ eNodeNumTag tag then this function calls directly the member180 /// The complexity of the function is <em>O</em>(<em>n</em>), but for some 181 /// graph structures it is specialized to run in <em>O</em>(1). 182 /// 183 /// \note If the graph contains a \c nodeNum() member function and a 184 /// \c NodeNumTag tag then this function calls directly the member 180 185 /// function to query the cardinality of the node set. 181 186 template <typename Graph> … … 209 214 /// 210 215 /// This function counts the arcs in the graph. 211 /// The complexity of the function is O(e)but for some212 /// graph structures it is specialized to run in O(1).213 /// 214 /// If the graph contains a \earcNum() member function and a215 /// \ e EdgeNumTag tag then this function calls directly the member216 /// The complexity of the function is <em>O</em>(<em>m</em>), but for some 217 /// graph structures it is specialized to run in <em>O</em>(1). 218 /// 219 /// \note If the graph contains a \c arcNum() member function and a 220 /// \c ArcNumTag tag then this function calls directly the member 216 221 /// function to query the cardinality of the arc set. 217 222 template <typename Graph> … … 221 226 222 227 // Edge counting: 228 223 229 namespace _core_bits { 224 230 … … 244 250 /// 245 251 /// This function counts the edges in the graph. 246 /// The complexity of the function is O(m)but for some247 /// graph structures it is specialized to run in O(1).248 /// 249 /// If the graph contains a \eedgeNum() member function and a250 /// \ eEdgeNumTag tag then this function calls directly the member252 /// The complexity of the function is <em>O</em>(<em>m</em>), but for some 253 /// graph structures it is specialized to run in <em>O</em>(1). 254 /// 255 /// \note If the graph contains a \c edgeNum() member function and a 256 /// \c EdgeNumTag tag then this function calls directly the member 251 257 /// function to query the cardinality of the edge set. 252 258 template <typename Graph> … … 269 275 /// 270 276 /// This function counts the number of the out-arcs from node \c n 271 /// in the graph .277 /// in the graph \c g. 272 278 template <typename Graph> 273 inline int countOutArcs(const Graph& _g, const typename Graph::Node& _n) {274 return countNodeDegree<Graph, typename Graph::OutArcIt>( _g, _n);279 inline int countOutArcs(const Graph& g, const typename Graph::Node& n) { 280 return countNodeDegree<Graph, typename Graph::OutArcIt>(g, n); 275 281 } 276 282 … … 278 284 /// 279 285 /// This function counts the number of the in-arcs to node \c n 280 /// in the graph .286 /// in the graph \c g. 281 287 template <typename Graph> 282 inline int countInArcs(const Graph& _g, const typename Graph::Node& _n) {283 return countNodeDegree<Graph, typename Graph::InArcIt>( _g, _n);288 inline int countInArcs(const Graph& g, const typename Graph::Node& n) { 289 return countNodeDegree<Graph, typename Graph::InArcIt>(g, n); 284 290 } 285 291 … … 287 293 /// 288 294 /// This function counts the number of the inc-edges to node \c n 289 /// in the graph.295 /// in the undirected graph \c g. 290 296 template <typename Graph> 291 inline int countIncEdges(const Graph& _g, const typename Graph::Node& _n) {292 return countNodeDegree<Graph, typename Graph::IncEdgeIt>( _g, _n);297 inline int countIncEdges(const Graph& g, const typename Graph::Node& n) { 298 return countNodeDegree<Graph, typename Graph::IncEdgeIt>(g, n); 293 299 } 294 300 … … 304 310 305 311 template <typename Digraph, typename Item, typename RefMap, 306 typename ToMap, typename FromMap>312 typename FromMap, typename ToMap> 307 313 class MapCopy : public MapCopyBase<Digraph, Item, RefMap> { 308 314 public: 309 315 310 MapCopy( ToMap& tmap, const FromMap&map)311 : _ tmap(tmap), _map(map) {}316 MapCopy(const FromMap& map, ToMap& tmap) 317 : _map(map), _tmap(tmap) {} 312 318 313 319 virtual void copy(const Digraph& digraph, const RefMap& refMap) { … … 319 325 320 326 private: 327 const FromMap& _map; 321 328 ToMap& _tmap; 322 const FromMap& _map;323 329 }; 324 330 … … 327 333 public: 328 334 329 ItemCopy( It& it, const Item& item) : _it(it), _item(item) {}335 ItemCopy(const Item& item, It& it) : _item(item), _it(it) {} 330 336 331 337 virtual void copy(const Digraph&, const RefMap& refMap) { … … 334 340 335 341 private: 342 Item _item; 336 343 It& _it; 337 Item _item;338 344 }; 339 345 … … 376 382 struct DigraphCopySelector { 377 383 template <typename From, typename NodeRefMap, typename ArcRefMap> 378 static void copy( Digraph &to, const From& from,384 static void copy(const From& from, Digraph &to, 379 385 NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) { 380 386 for (typename From::NodeIt it(from); it != INVALID; ++it) { … … 394 400 { 395 401 template <typename From, typename NodeRefMap, typename ArcRefMap> 396 static void copy( Digraph &to, const From& from,402 static void copy(const From& from, Digraph &to, 397 403 NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) { 398 404 to.build(from, nodeRefMap, arcRefMap); … … 403 409 struct GraphCopySelector { 404 410 template <typename From, typename NodeRefMap, typename EdgeRefMap> 405 static void copy( Graph &to, const From& from,411 static void copy(const From& from, Graph &to, 406 412 NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { 407 413 for (typename From::NodeIt it(from); it != INVALID; ++it) { … … 421 427 { 422 428 template <typename From, typename NodeRefMap, typename EdgeRefMap> 423 static void copy( Graph &to, const From& from,429 static void copy(const From& from, Graph &to, 424 430 NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { 425 431 to.build(from, nodeRefMap, edgeRefMap); … … 432 438 /// 433 439 /// Class to copy a digraph to another digraph (duplicate a digraph). The 434 /// simplest way of using it is through the \c copyDigraph() function.435 /// 436 /// This class not just make a copy of agraph, but it can create440 /// simplest way of using it is through the \c digraphCopy() function. 441 /// 442 /// This class not only make a copy of a digraph, but it can create 437 443 /// references and cross references between the nodes and arcs of 438 /// the two graphs, it can copy maps foruse with the newly created439 /// graph and copy nodes and arcs.440 /// 441 /// To make a copy from a graph, first an instance of DigraphCopy442 /// should be created, then the data belongs to the graph should444 /// the two digraphs, and it can copy maps to use with the newly created 445 /// digraph. 446 /// 447 /// To make a copy from a digraph, first an instance of DigraphCopy 448 /// should be created, then the data belongs to the digraph should 443 449 /// assigned to copy. In the end, the \c run() member should be 444 450 /// called. 445 451 /// 446 /// The next code copies a graph with several data:452 /// The next code copies a digraph with several data: 447 453 ///\code 448 /// DigraphCopy< NewGraph, OrigGraph> dc(new_graph, orig_graph);449 /// // create a referencefor the nodes454 /// DigraphCopy<OrigGraph, NewGraph> cg(orig_graph, new_graph); 455 /// // Create references for the nodes 450 456 /// OrigGraph::NodeMap<NewGraph::Node> nr(orig_graph); 451 /// dc.nodeRef(nr);452 /// // create a cross reference(inverse) for the arcs457 /// cg.nodeRef(nr); 458 /// // Create cross references (inverse) for the arcs 453 459 /// NewGraph::ArcMap<OrigGraph::Arc> acr(new_graph); 454 /// dc.arcCrossRef(acr);455 /// // copy an arc map460 /// cg.arcCrossRef(acr); 461 /// // Copy an arc map 456 462 /// OrigGraph::ArcMap<double> oamap(orig_graph); 457 463 /// NewGraph::ArcMap<double> namap(new_graph); 458 /// dc.arcMap(namap, oamap);459 /// // copy a node464 /// cg.arcMap(oamap, namap); 465 /// // Copy a node 460 466 /// OrigGraph::Node on; 461 467 /// NewGraph::Node nn; 462 /// dc.node(nn, on);463 /// // Execut ions of copy464 /// dc.run();468 /// cg.node(on, nn); 469 /// // Execute copying 470 /// cg.run(); 465 471 ///\endcode 466 template <typename To, typename From>472 template <typename From, typename To> 467 473 class DigraphCopy { 468 474 private: … … 479 485 typedef typename From::template ArcMap<TArc> ArcRefMap; 480 486 481 482 487 public: 483 488 484 485 /// \brief Constructor for the DigraphCopy. 486 /// 487 /// It copies the content of the \c _from digraph into the 488 /// \c _to digraph. 489 DigraphCopy(To& to, const From& from) 489 /// \brief Constructor of DigraphCopy. 490 /// 491 /// Constructor of DigraphCopy for copying the content of the 492 /// \c from digraph into the \c to digraph. 493 DigraphCopy(const From& from, To& to) 490 494 : _from(from), _to(to) {} 491 495 492 /// \brief Destructor of theDigraphCopy493 /// 494 /// Destructor of the DigraphCopy496 /// \brief Destructor of DigraphCopy 497 /// 498 /// Destructor of DigraphCopy. 495 499 ~DigraphCopy() { 496 500 for (int i = 0; i < int(_node_maps.size()); ++i) { … … 503 507 } 504 508 505 /// \brief Cop iesthe node references into the given map.506 /// 507 /// Copies the node references into the given map. The parameter508 /// should be a map, which key type is the Node type of the source509 /// graph, while the value type is the Node type of the510 /// destination graph.509 /// \brief Copy the node references into the given map. 510 /// 511 /// This function copies the node references into the given map. 512 /// The parameter should be a map, whose key type is the Node type of 513 /// the source digraph, while the value type is the Node type of the 514 /// destination digraph. 511 515 template <typename NodeRef> 512 516 DigraphCopy& nodeRef(NodeRef& map) { … … 516 520 } 517 521 518 /// \brief Cop iesthe node cross references into the given map.519 /// 520 /// Copies the node cross references (reverse references) into521 /// the given map. The parameter should be a map, whichkey type522 /// is the Node type of the destinationgraph, while the value type is523 /// the Node type of the sourcegraph.522 /// \brief Copy the node cross references into the given map. 523 /// 524 /// This function copies the node cross references (reverse references) 525 /// into the given map. The parameter should be a map, whose key type 526 /// is the Node type of the destination digraph, while the value type is 527 /// the Node type of the source digraph. 524 528 template <typename NodeCrossRef> 525 529 DigraphCopy& nodeCrossRef(NodeCrossRef& map) { … … 529 533 } 530 534 531 /// \brief Make copy of the given map. 532 /// 533 /// Makes copy of the given map for the newly created digraph. 534 /// The new map's key type is the destination graph's node type, 535 /// and the copied map's key type is the source graph's node type. 536 template <typename ToMap, typename FromMap> 537 DigraphCopy& nodeMap(ToMap& tmap, const FromMap& map) { 535 /// \brief Make a copy of the given node map. 536 /// 537 /// This function makes a copy of the given node map for the newly 538 /// created digraph. 539 /// The key type of the new map \c tmap should be the Node type of the 540 /// destination digraph, and the key type of the original map \c map 541 /// should be the Node type of the source digraph. 542 template <typename FromMap, typename ToMap> 543 DigraphCopy& nodeMap(const FromMap& map, ToMap& tmap) { 538 544 _node_maps.push_back(new _core_bits::MapCopy<From, Node, 539 NodeRefMap, ToMap, FromMap>(tmap,map));545 NodeRefMap, FromMap, ToMap>(map, tmap)); 540 546 return *this; 541 547 } … … 543 549 /// \brief Make a copy of the given node. 544 550 /// 545 /// Makea copy of the given node.546 DigraphCopy& node( TNode& tnode, const Node& snode) {551 /// This function makes a copy of the given node. 552 DigraphCopy& node(const Node& node, TNode& tnode) { 547 553 _node_maps.push_back(new _core_bits::ItemCopy<From, Node, 548 NodeRefMap, TNode>(tnode, snode)); 549 return *this; 550 } 551 552 /// \brief Copies the arc references into the given map. 553 /// 554 /// Copies the arc references into the given map. 554 NodeRefMap, TNode>(node, tnode)); 555 return *this; 556 } 557 558 /// \brief Copy the arc references into the given map. 559 /// 560 /// This function copies the arc references into the given map. 561 /// The parameter should be a map, whose key type is the Arc type of 562 /// the source digraph, while the value type is the Arc type of the 563 /// destination digraph. 555 564 template <typename ArcRef> 556 565 DigraphCopy& arcRef(ArcRef& map) { … … 560 569 } 561 570 562 /// \brief Copies the arc cross references into the given map. 563 /// 564 /// Copies the arc cross references (reverse references) into 565 /// the given map. 571 /// \brief Copy the arc cross references into the given map. 572 /// 573 /// This function copies the arc cross references (reverse references) 574 /// into the given map. The parameter should be a map, whose key type 575 /// is the Arc type of the destination digraph, while the value type is 576 /// the Arc type of the source digraph. 566 577 template <typename ArcCrossRef> 567 578 DigraphCopy& arcCrossRef(ArcCrossRef& map) { … … 571 582 } 572 583 573 /// \brief Make copy of the given map. 574 /// 575 /// Makes copy of the given map for the newly created digraph. 576 /// The new map's key type is the to digraph's arc type, 577 /// and the copied map's key type is the from digraph's arc 578 /// type. 579 template <typename ToMap, typename FromMap> 580 DigraphCopy& arcMap(ToMap& tmap, const FromMap& map) { 584 /// \brief Make a copy of the given arc map. 585 /// 586 /// This function makes a copy of the given arc map for the newly 587 /// created digraph. 588 /// The key type of the new map \c tmap should be the Arc type of the 589 /// destination digraph, and the key type of the original map \c map 590 /// should be the Arc type of the source digraph. 591 template <typename FromMap, typename ToMap> 592 DigraphCopy& arcMap(const FromMap& map, ToMap& tmap) { 581 593 _arc_maps.push_back(new _core_bits::MapCopy<From, Arc, 582 ArcRefMap, ToMap, FromMap>(tmap,map));594 ArcRefMap, FromMap, ToMap>(map, tmap)); 583 595 return *this; 584 596 } … … 586 598 /// \brief Make a copy of the given arc. 587 599 /// 588 /// Makea copy of the given arc.589 DigraphCopy& arc( TArc& tarc, const Arc& sarc) {600 /// This function makes a copy of the given arc. 601 DigraphCopy& arc(const Arc& arc, TArc& tarc) { 590 602 _arc_maps.push_back(new _core_bits::ItemCopy<From, Arc, 591 ArcRefMap, TArc>(tarc, sarc)); 592 return *this; 593 } 594 595 /// \brief Executes the copies. 596 /// 597 /// Executes the copies. 603 ArcRefMap, TArc>(arc, tarc)); 604 return *this; 605 } 606 607 /// \brief Execute copying. 608 /// 609 /// This function executes the copying of the digraph along with the 610 /// copying of the assigned data. 598 611 void run() { 599 612 NodeRefMap nodeRefMap(_from); 600 613 ArcRefMap arcRefMap(_from); 601 614 _core_bits::DigraphCopySelector<To>:: 602 copy(_ to, _from, nodeRefMap, arcRefMap);615 copy(_from, _to, nodeRefMap, arcRefMap); 603 616 for (int i = 0; i < int(_node_maps.size()); ++i) { 604 617 _node_maps[i]->copy(_from, nodeRefMap); … … 611 624 protected: 612 625 613 614 626 const From& _from; 615 627 To& _to; 616 628 617 629 std::vector<_core_bits::MapCopyBase<From, Node, NodeRefMap>* > 618 _node_maps;630 _node_maps; 619 631 620 632 std::vector<_core_bits::MapCopyBase<From, Arc, ArcRefMap>* > 621 _arc_maps;633 _arc_maps; 622 634 623 635 }; … … 625 637 /// \brief Copy a digraph to another digraph. 626 638 /// 627 /// Copy a digraph to another digraph. The complete usage of the628 /// function is detailed in the DigraphCopy class, but a short629 /// example shows a basic work:639 /// This function copies a digraph to another digraph. 640 /// The complete usage of it is detailed in the DigraphCopy class, but 641 /// a short example shows a basic work: 630 642 ///\code 631 /// copyDigraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run();643 /// digraphCopy(src, trg).nodeRef(nr).arcCrossRef(acr).run(); 632 644 ///\endcode 633 645 /// 634 646 /// After the copy the \c nr map will contain the mapping from the 635 647 /// nodes of the \c from digraph to the nodes of the \c to digraph and 636 /// \c ecr will contain the mapping from the arcs of the \c to digraph648 /// \c acr will contain the mapping from the arcs of the \c to digraph 637 649 /// to the arcs of the \c from digraph. 638 650 /// 639 651 /// \see DigraphCopy 640 template <typename To, typename From>641 DigraphCopy< To, From> copyDigraph(To& to, const From& from) {642 return DigraphCopy< To, From>(to, from);652 template <typename From, typename To> 653 DigraphCopy<From, To> digraphCopy(const From& from, To& to) { 654 return DigraphCopy<From, To>(from, to); 643 655 } 644 656 … … 646 658 /// 647 659 /// Class to copy a graph to another graph (duplicate a graph). The 648 /// simplest way of using it is through the \c copyGraph() function.649 /// 650 /// This class not justmake a copy of a graph, but it can create660 /// simplest way of using it is through the \c graphCopy() function. 661 /// 662 /// This class not only make a copy of a graph, but it can create 651 663 /// references and cross references between the nodes, edges and arcs of 652 /// the two graphs, it can copy maps for usewith the newly created653 /// graph and copy nodes, edges and arcs.664 /// the two graphs, and it can copy maps for using with the newly created 665 /// graph. 654 666 /// 655 667 /// To make a copy from a graph, first an instance of GraphCopy … … 660 672 /// The next code copies a graph with several data: 661 673 ///\code 662 /// GraphCopy< NewGraph, OrigGraph> dc(new_graph, orig_graph);663 /// // create a referencefor the nodes674 /// GraphCopy<OrigGraph, NewGraph> cg(orig_graph, new_graph); 675 /// // Create references for the nodes 664 676 /// OrigGraph::NodeMap<NewGraph::Node> nr(orig_graph); 665 /// dc.nodeRef(nr);666 /// // create a cross reference(inverse) for the edges667 /// NewGraph::EdgeMap<OrigGraph:: Arc> ecr(new_graph);668 /// dc.edgeCrossRef(ecr);669 /// // copy an arcmap670 /// OrigGraph:: ArcMap<double> oamap(orig_graph);671 /// NewGraph:: ArcMap<double> namap(new_graph);672 /// dc.arcMap(namap, oamap);673 /// // copy a node677 /// cg.nodeRef(nr); 678 /// // Create cross references (inverse) for the edges 679 /// NewGraph::EdgeMap<OrigGraph::Edge> ecr(new_graph); 680 /// cg.edgeCrossRef(ecr); 681 /// // Copy an edge map 682 /// OrigGraph::EdgeMap<double> oemap(orig_graph); 683 /// NewGraph::EdgeMap<double> nemap(new_graph); 684 /// cg.edgeMap(oemap, nemap); 685 /// // Copy a node 674 686 /// OrigGraph::Node on; 675 687 /// NewGraph::Node nn; 676 /// dc.node(nn, on);677 /// // Execut ions of copy678 /// dc.run();688 /// cg.node(on, nn); 689 /// // Execute copying 690 /// cg.run(); 679 691 ///\endcode 680 template <typename To, typename From>692 template <typename From, typename To> 681 693 class GraphCopy { 682 694 private: … … 697 709 698 710 struct ArcRefMap { 699 ArcRefMap(const To& to, const From& from,711 ArcRefMap(const From& from, const To& to, 700 712 const EdgeRefMap& edge_ref, const NodeRefMap& node_ref) 701 : _ to(to), _from(from),713 : _from(from), _to(to), 702 714 _edge_ref(edge_ref), _node_ref(node_ref) {} 703 715 … … 713 725 } 714 726 727 const From& _from; 715 728 const To& _to; 716 const From& _from;717 729 const EdgeRefMap& _edge_ref; 718 730 const NodeRefMap& _node_ref; 719 731 }; 720 732 721 722 733 public: 723 734 724 725 /// \brief Constructor for the GraphCopy. 726 /// 727 /// It copies the content of the \c _from graph into the 728 /// \c _to graph. 729 GraphCopy(To& to, const From& from) 735 /// \brief Constructor of GraphCopy. 736 /// 737 /// Constructor of GraphCopy for copying the content of the 738 /// \c from graph into the \c to graph. 739 GraphCopy(const From& from, To& to) 730 740 : _from(from), _to(to) {} 731 741 732 /// \brief Destructor of theGraphCopy733 /// 734 /// Destructor of the GraphCopy742 /// \brief Destructor of GraphCopy 743 /// 744 /// Destructor of GraphCopy. 735 745 ~GraphCopy() { 736 746 for (int i = 0; i < int(_node_maps.size()); ++i) { … … 743 753 delete _edge_maps[i]; 744 754 } 745 746 } 747 748 /// \brief Copies the node references into the given map. 749 /// 750 /// Copies the node references into the given map. 755 } 756 757 /// \brief Copy the node references into the given map. 758 /// 759 /// This function copies the node references into the given map. 760 /// The parameter should be a map, whose key type is the Node type of 761 /// the source graph, while the value type is the Node type of the 762 /// destination graph. 751 763 template <typename NodeRef> 752 764 GraphCopy& nodeRef(NodeRef& map) { … … 756 768 } 757 769 758 /// \brief Copies the node cross references into the given map. 759 /// 760 /// Copies the node cross references (reverse references) into 761 /// the given map. 770 /// \brief Copy the node cross references into the given map. 771 /// 772 /// This function copies the node cross references (reverse references) 773 /// into the given map. The parameter should be a map, whose key type 774 /// is the Node type of the destination graph, while the value type is 775 /// the Node type of the source graph. 762 776 template <typename NodeCrossRef> 763 777 GraphCopy& nodeCrossRef(NodeCrossRef& map) { … … 767 781 } 768 782 769 /// \brief Make copy of the given map. 770 /// 771 /// Makes copy of the given map for the newly created graph. 772 /// The new map's key type is the to graph's node type, 773 /// and the copied map's key type is the from graph's node 774 /// type. 775 template <typename ToMap, typename FromMap> 776 GraphCopy& nodeMap(ToMap& tmap, const FromMap& map) { 783 /// \brief Make a copy of the given node map. 784 /// 785 /// This function makes a copy of the given node map for the newly 786 /// created graph. 787 /// The key type of the new map \c tmap should be the Node type of the 788 /// destination graph, and the key type of the original map \c map 789 /// should be the Node type of the source graph. 790 template <typename FromMap, typename ToMap> 791 GraphCopy& nodeMap(const FromMap& map, ToMap& tmap) { 777 792 _node_maps.push_back(new _core_bits::MapCopy<From, Node, 778 NodeRefMap, ToMap, FromMap>(tmap,map));793 NodeRefMap, FromMap, ToMap>(map, tmap)); 779 794 return *this; 780 795 } … … 782 797 /// \brief Make a copy of the given node. 783 798 /// 784 /// Makea copy of the given node.785 GraphCopy& node( TNode& tnode, const Node& snode) {799 /// This function makes a copy of the given node. 800 GraphCopy& node(const Node& node, TNode& tnode) { 786 801 _node_maps.push_back(new _core_bits::ItemCopy<From, Node, 787 NodeRefMap, TNode>(tnode, snode)); 788 return *this; 789 } 790 791 /// \brief Copies the arc references into the given map. 792 /// 793 /// Copies the arc references into the given map. 802 NodeRefMap, TNode>(node, tnode)); 803 return *this; 804 } 805 806 /// \brief Copy the arc references into the given map. 807 /// 808 /// This function copies the arc references into the given map. 809 /// The parameter should be a map, whose key type is the Arc type of 810 /// the source graph, while the value type is the Arc type of the 811 /// destination graph. 794 812 template <typename ArcRef> 795 813 GraphCopy& arcRef(ArcRef& map) { … … 799 817 } 800 818 801 /// \brief Copies the arc cross references into the given map. 802 /// 803 /// Copies the arc cross references (reverse references) into 804 /// the given map. 819 /// \brief Copy the arc cross references into the given map. 820 /// 821 /// This function copies the arc cross references (reverse references) 822 /// into the given map. The parameter should be a map, whose key type 823 /// is the Arc type of the destination graph, while the value type is 824 /// the Arc type of the source graph. 805 825 template <typename ArcCrossRef> 806 826 GraphCopy& arcCrossRef(ArcCrossRef& map) { … … 810 830 } 811 831 812 /// \brief Make copy of the given map. 813 /// 814 /// Makes copy of the given map for the newly created graph. 815 /// The new map's key type is the to graph's arc type, 816 /// and the copied map's key type is the from graph's arc 817 /// type. 818 template <typename ToMap, typename FromMap> 819 GraphCopy& arcMap(ToMap& tmap, const FromMap& map) { 832 /// \brief Make a copy of the given arc map. 833 /// 834 /// This function makes a copy of the given arc map for the newly 835 /// created graph. 836 /// The key type of the new map \c tmap should be the Arc type of the 837 /// destination graph, and the key type of the original map \c map 838 /// should be the Arc type of the source graph. 839 template <typename FromMap, typename ToMap> 840 GraphCopy& arcMap(const FromMap& map, ToMap& tmap) { 820 841 _arc_maps.push_back(new _core_bits::MapCopy<From, Arc, 821 ArcRefMap, ToMap, FromMap>(tmap,map));842 ArcRefMap, FromMap, ToMap>(map, tmap)); 822 843 return *this; 823 844 } … … 825 846 /// \brief Make a copy of the given arc. 826 847 /// 827 /// Makea copy of the given arc.828 GraphCopy& arc( TArc& tarc, const Arc& sarc) {848 /// This function makes a copy of the given arc. 849 GraphCopy& arc(const Arc& arc, TArc& tarc) { 829 850 _arc_maps.push_back(new _core_bits::ItemCopy<From, Arc, 830 ArcRefMap, TArc>(tarc, sarc)); 831 return *this; 832 } 833 834 /// \brief Copies the edge references into the given map. 835 /// 836 /// Copies the edge references into the given map. 851 ArcRefMap, TArc>(arc, tarc)); 852 return *this; 853 } 854 855 /// \brief Copy the edge references into the given map. 856 /// 857 /// This function copies the edge references into the given map. 858 /// The parameter should be a map, whose key type is the Edge type of 859 /// the source graph, while the value type is the Edge type of the 860 /// destination graph. 837 861 template <typename EdgeRef> 838 862 GraphCopy& edgeRef(EdgeRef& map) { … … 842 866 } 843 867 844 /// \brief Copies the edge cross references into the given map. 845 /// 846 /// Copies the edge cross references (reverse 847 /// references) into the given map. 868 /// \brief Copy the edge cross references into the given map. 869 /// 870 /// This function copies the edge cross references (reverse references) 871 /// into the given map. The parameter should be a map, whose key type 872 /// is the Edge type of the destination graph, while the value type is 873 /// the Edge type of the source graph. 848 874 template <typename EdgeCrossRef> 849 875 GraphCopy& edgeCrossRef(EdgeCrossRef& map) { … … 853 879 } 854 880 855 /// \brief Make copy of the given map. 856 /// 857 /// Makes copy of the given map for the newly created graph. 858 /// The new map's key type is the to graph's edge type, 859 /// and the copied map's key type is the from graph's edge 860 /// type. 861 template <typename ToMap, typename FromMap> 862 GraphCopy& edgeMap(ToMap& tmap, const FromMap& map) { 881 /// \brief Make a copy of the given edge map. 882 /// 883 /// This function makes a copy of the given edge map for the newly 884 /// created graph. 885 /// The key type of the new map \c tmap should be the Edge type of the 886 /// destination graph, and the key type of the original map \c map 887 /// should be the Edge type of the source graph. 888 template <typename FromMap, typename ToMap> 889 GraphCopy& edgeMap(const FromMap& map, ToMap& tmap) { 863 890 _edge_maps.push_back(new _core_bits::MapCopy<From, Edge, 864 EdgeRefMap, ToMap, FromMap>(tmap,map));891 EdgeRefMap, FromMap, ToMap>(map, tmap)); 865 892 return *this; 866 893 } … … 868 895 /// \brief Make a copy of the given edge. 869 896 /// 870 /// Makea copy of the given edge.871 GraphCopy& edge( TEdge& tedge, const Edge& sedge) {897 /// This function makes a copy of the given edge. 898 GraphCopy& edge(const Edge& edge, TEdge& tedge) { 872 899 _edge_maps.push_back(new _core_bits::ItemCopy<From, Edge, 873 EdgeRefMap, TEdge>(tedge, sedge)); 874 return *this; 875 } 876 877 /// \brief Executes the copies. 878 /// 879 /// Executes the copies. 900 EdgeRefMap, TEdge>(edge, tedge)); 901 return *this; 902 } 903 904 /// \brief Execute copying. 905 /// 906 /// This function executes the copying of the graph along with the 907 /// copying of the assigned data. 880 908 void run() { 881 909 NodeRefMap nodeRefMap(_from); 882 910 EdgeRefMap edgeRefMap(_from); 883 ArcRefMap arcRefMap(_ to, _from, edgeRefMap, nodeRefMap);911 ArcRefMap arcRefMap(_from, _to, edgeRefMap, nodeRefMap); 884 912 _core_bits::GraphCopySelector<To>:: 885 copy(_ to, _from, nodeRefMap, edgeRefMap);913 copy(_from, _to, nodeRefMap, edgeRefMap); 886 914 for (int i = 0; i < int(_node_maps.size()); ++i) { 887 915 _node_maps[i]->copy(_from, nodeRefMap); … … 901 929 902 930 std::vector<_core_bits::MapCopyBase<From, Node, NodeRefMap>* > 903 _node_maps;931 _node_maps; 904 932 905 933 std::vector<_core_bits::MapCopyBase<From, Arc, ArcRefMap>* > 906 _arc_maps;934 _arc_maps; 907 935 908 936 std::vector<_core_bits::MapCopyBase<From, Edge, EdgeRefMap>* > 909 _edge_maps;937 _edge_maps; 910 938 911 939 }; … … 913 941 /// \brief Copy a graph to another graph. 914 942 /// 915 /// Copy a graph to another graph. The complete usage of the916 /// function is detailed in the GraphCopy class, but a short917 /// example shows a basic work:943 /// This function copies a graph to another graph. 944 /// The complete usage of it is detailed in the GraphCopy class, 945 /// but a short example shows a basic work: 918 946 ///\code 919 /// copyGraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run();947 /// graphCopy(src, trg).nodeRef(nr).edgeCrossRef(ecr).run(); 920 948 ///\endcode 921 949 /// 922 950 /// After the copy the \c nr map will contain the mapping from the 923 951 /// nodes of the \c from graph to the nodes of the \c to graph and 924 /// \c ecr will contain the mapping from the arcs of the \c to graph925 /// to the arcs of the \c from graph.952 /// \c ecr will contain the mapping from the edges of the \c to graph 953 /// to the edges of the \c from graph. 926 954 /// 927 955 /// \see GraphCopy 928 template <typename To, typename From>929 GraphCopy< To, From>930 copyGraph(To& to, const From& from) {931 return GraphCopy< To, From>(to, from);956 template <typename From, typename To> 957 GraphCopy<From, To> 958 graphCopy(const From& from, To& to) { 959 return GraphCopy<From, To>(from, to); 932 960 } 933 961 … … 954 982 struct FindArcSelector< 955 983 Graph, 956 typename enable_if<typename Graph::Find EdgeTag, void>::type>984 typename enable_if<typename Graph::FindArcTag, void>::type> 957 985 { 958 986 typedef typename Graph::Node Node; … … 964 992 } 965 993 966 /// \brief Finds an arc between two nodes of a graph. 967 /// 968 /// Finds an arc from node \c u to node \c v in graph \c g. 994 /// \brief Find an arc between two nodes of a digraph. 995 /// 996 /// This function finds an arc from node \c u to node \c v in the 997 /// digraph \c g. 969 998 /// 970 999 /// If \c prev is \ref INVALID (this is the default value), then … … 975 1004 /// Thus you can iterate through each arc from \c u to \c v as it follows. 976 1005 ///\code 977 /// for(Arc e =findArc(g,u,v);e!=INVALID;e=findArc(g,u,v,e)) {1006 /// for(Arc e = findArc(g,u,v); e != INVALID; e = findArc(g,u,v,e)) { 978 1007 /// ... 979 1008 /// } 980 1009 ///\endcode 981 1010 /// 982 /// \sa ArcLookUp983 /// \sa AllArcLookUp984 /// \sa DynArcLookUp1011 /// \note \ref ConArcIt provides iterator interface for the same 1012 /// functionality. 1013 /// 985 1014 ///\sa ConArcIt 1015 ///\sa ArcLookUp, AllArcLookUp, DynArcLookUp 986 1016 template <typename Graph> 987 1017 inline typename Graph::Arc … … 991 1021 } 992 1022 993 /// \brief Iterator for iterating on arcs connectedthe same nodes.994 /// 995 /// Iterator for iterating on arcs connectedthe same nodes. It is996 /// higher level interface for thefindArc() function. You can1023 /// \brief Iterator for iterating on parallel arcs connecting the same nodes. 1024 /// 1025 /// Iterator for iterating on parallel arcs connecting the same nodes. It is 1026 /// a higher level interface for the \ref findArc() function. You can 997 1027 /// use it the following way: 998 1028 ///\code … … 1003 1033 /// 1004 1034 ///\sa findArc() 1005 ///\sa ArcLookUp 1006 ///\sa AllArcLookUp 1007 ///\sa DynArcLookUp 1035 ///\sa ArcLookUp, AllArcLookUp, DynArcLookUp 1008 1036 template <typename _Graph> 1009 1037 class ConArcIt : public _Graph::Arc { … … 1018 1046 /// \brief Constructor. 1019 1047 /// 1020 /// Construct a new ConArcIt iterating on the arcs which1021 /// connects the \c u and \c v node.1048 /// Construct a new ConArcIt iterating on the arcs that 1049 /// connects nodes \c u and \c v. 1022 1050 ConArcIt(const Graph& g, Node u, Node v) : _graph(g) { 1023 1051 Parent::operator=(findArc(_graph, u, v)); … … 1026 1054 /// \brief Constructor. 1027 1055 /// 1028 /// Construct a new ConArcIt which continues the iterating from 1029 /// the \c e arc. 1056 /// Construct a new ConArcIt that continues the iterating from arc \c a. 1030 1057 ConArcIt(const Graph& g, Arc a) : Parent(a), _graph(g) {} 1031 1058 … … 1088 1115 } 1089 1116 1090 /// \brief Find san edge between two nodes of a graph.1091 /// 1092 /// Finds an edge from node \c u to node \c v in graph \c g.1093 /// If thenode \c u and node \c v is equal then each loop edge1117 /// \brief Find an edge between two nodes of a graph. 1118 /// 1119 /// This function finds an edge from node \c u to node \c v in graph \c g. 1120 /// If node \c u and node \c v is equal then each loop edge 1094 1121 /// will be enumerated once. 1095 1122 /// 1096 1123 /// If \c prev is \ref INVALID (this is the default value), then 1097 /// it finds the first arc from \c u to \c v. Otherwise it looks for 1098 /// the next arc from \c u to \c v after \c prev. 1099 /// \return The found arc or \ref INVALID if there is no such an arc. 1100 /// 1101 /// Thus you can iterate through each arc from \c u to \c v as it follows. 1124 /// it finds the first edge from \c u to \c v. Otherwise it looks for 1125 /// the next edge from \c u to \c v after \c prev. 1126 /// \return The found edge or \ref INVALID if there is no such an edge. 1127 /// 1128 /// Thus you can iterate through each edge between \c u and \c v 1129 /// as it follows. 1102 1130 ///\code 1103 /// for(Edge e = findEdge(g,u,v); e != INVALID; 1104 /// e = findEdge(g,u,v,e)) { 1131 /// for(Edge e = findEdge(g,u,v); e != INVALID; e = findEdge(g,u,v,e)) { 1105 1132 /// ... 1106 1133 /// } 1107 1134 ///\endcode 1108 1135 /// 1136 /// \note \ref ConEdgeIt provides iterator interface for the same 1137 /// functionality. 1138 /// 1109 1139 ///\sa ConEdgeIt 1110 1111 1140 template <typename Graph> 1112 1141 inline typename Graph::Edge … … 1116 1145 } 1117 1146 1118 /// \brief Iterator for iterating on edges connectedthe same nodes.1119 /// 1120 /// Iterator for iterating on edges connected the same nodes. It is1121 /// higher level interface for the findEdge() function. You can1147 /// \brief Iterator for iterating on parallel edges connecting the same nodes. 1148 /// 1149 /// Iterator for iterating on parallel edges connecting the same nodes. 1150 /// It is a higher level interface for the findEdge() function. You can 1122 1151 /// use it the following way: 1123 1152 ///\code 1124 /// for (ConEdgeIt<Graph> it(g, src, trg); it != INVALID; ++it) {1153 /// for (ConEdgeIt<Graph> it(g, u, v); it != INVALID; ++it) { 1125 1154 /// ... 1126 1155 /// } … … 1140 1169 /// \brief Constructor. 1141 1170 /// 1142 /// Construct a new ConEdgeIt iterating on the edges which1143 /// connects the \c u and \c v node.1171 /// Construct a new ConEdgeIt iterating on the edges that 1172 /// connects nodes \c u and \c v. 1144 1173 ConEdgeIt(const Graph& g, Node u, Node v) : _graph(g) { 1145 1174 Parent::operator=(findEdge(_graph, u, v)); … … 1148 1177 /// \brief Constructor. 1149 1178 /// 1150 /// Construct a new ConEdgeIt which continues the iterating from 1151 /// the \c e edge. 1179 /// Construct a new ConEdgeIt that continues iterating from edge \c e. 1152 1180 ConEdgeIt(const Graph& g, Edge e) : Parent(e), _graph(g) {} 1153 1181 … … 1165 1193 1166 1194 1167 ///Dynamic arc look 1195 ///Dynamic arc look-up between given endpoints. 1168 1196 1169 1197 ///Using this class, you can find an arc in a digraph from a given 1170 ///source to a given target in amortized time <em>O (log d)</em>,1198 ///source to a given target in amortized time <em>O</em>(log<em>d</em>), 1171 1199 ///where <em>d</em> is the out-degree of the source node. 1172 1200 /// 1173 1201 ///It is possible to find \e all parallel arcs between two nodes with 1174 ///the \c findFirst() and \c findNext() members.1175 /// 1176 /// See the \ref ArcLookUp and \ref AllArcLookUp classes if your1177 /// digraph is not changed so frequently.1178 /// 1179 ///This class uses a self-adjusting binary search tree, Sleator's1180 /// and Tarjan's Splay tree forguarantee the logarithmic amortized1181 ///time bound for arc look ups. This class also guarantees the1202 ///the \c operator() member. 1203 /// 1204 ///This is a dynamic data structure. Consider to use \ref ArcLookUp or 1205 ///\ref AllArcLookUp if your digraph is not changed so frequently. 1206 /// 1207 ///This class uses a self-adjusting binary search tree, the Splay tree 1208 ///of Sleator and Tarjan to guarantee the logarithmic amortized 1209 ///time bound for arc look-ups. This class also guarantees the 1182 1210 ///optimal time bound in a constant factor for any distribution of 1183 1211 ///queries. … … 1381 1409 _right.set(e, _right[arc]); 1382 1410 _parent.set(_right[arc], e); 1411 _parent.set(e, _parent[arc]); 1383 1412 1384 1413 if (_parent[arc] != INVALID) { … … 1419 1448 for(NodeIt n(_g);n!=INVALID;++n) { 1420 1449 std::vector<Arc> v; 1421 for(OutArcIt e(_g,n);e!=INVALID;++e) v.push_back(e);1422 if (v.size()) {1450 for(OutArcIt a(_g,n);a!=INVALID;++a) v.push_back(a); 1451 if (!v.empty()) { 1423 1452 std::sort(v.begin(),v.end(),ArcLess(_g)); 1424 1453 Arc head = refreshRec(v,0,v.size()-1); … … 1502 1531 ///Find an arc between two nodes. 1503 1532 1504 ///Find an arc between two nodes in time <em>O(</em>log<em>d)</em>, where 1505 /// <em>d</em> is the number of outgoing arcs of \c s. 1506 ///\param s The source node 1507 ///\param t The target node 1508 ///\return An arc from \c s to \c t if there exists, 1509 ///\ref INVALID otherwise. 1510 Arc operator()(Node s, Node t) const 1511 { 1512 Arc a = _head[s]; 1513 while (true) { 1514 if (_g.target(a) == t) { 1533 ///Find an arc between two nodes. 1534 ///\param s The source node. 1535 ///\param t The target node. 1536 ///\param p The previous arc between \c s and \c t. It it is INVALID or 1537 ///not given, the operator finds the first appropriate arc. 1538 ///\return An arc from \c s to \c t after \c p or 1539 ///\ref INVALID if there is no more. 1540 /// 1541 ///For example, you can count the number of arcs from \c u to \c v in the 1542 ///following way. 1543 ///\code 1544 ///DynArcLookUp<ListDigraph> ae(g); 1545 ///... 1546 ///int n = 0; 1547 ///for(Arc a = ae(u,v); a != INVALID; a = ae(u,v,a)) n++; 1548 ///\endcode 1549 /// 1550 ///Finding the arcs take at most <em>O</em>(log<em>d</em>) 1551 ///amortized time, specifically, the time complexity of the lookups 1552 ///is equal to the optimal search tree implementation for the 1553 ///current query distribution in a constant factor. 1554 /// 1555 ///\note This is a dynamic data structure, therefore the data 1556 ///structure is updated after each graph alteration. Thus although 1557 ///this data structure is theoretically faster than \ref ArcLookUp 1558 ///and \ref AllArcLookUp, it often provides worse performance than 1559 ///them. 1560 Arc operator()(Node s, Node t, Arc p = INVALID) const { 1561 if (p == INVALID) { 1562 Arc a = _head[s]; 1563 if (a == INVALID) return INVALID; 1564 Arc r = INVALID; 1565 while (true) { 1566 if (_g.target(a) < t) { 1567 if (_right[a] == INVALID) { 1568 const_cast<DynArcLookUp&>(*this).splay(a); 1569 return r; 1570 } else { 1571 a = _right[a]; 1572 } 1573 } else { 1574 if (_g.target(a) == t) { 1575 r = a; 1576 } 1577 if (_left[a] == INVALID) { 1578 const_cast<DynArcLookUp&>(*this).splay(a); 1579 return r; 1580 } else { 1581 a = _left[a]; 1582 } 1583 } 1584 } 1585 } else { 1586 Arc a = p; 1587 if (_right[a] != INVALID) { 1588 a = _right[a]; 1589 while (_left[a] != INVALID) { 1590 a = _left[a]; 1591 } 1515 1592 const_cast<DynArcLookUp&>(*this).splay(a); 1516 return a; 1517 } else if (t < _g.target(a)) { 1518 if (_left[a] == INVALID) { 1519 const_cast<DynArcLookUp&>(*this).splay(a); 1593 } else { 1594 while (_parent[a] != INVALID && _right[_parent[a]] == a) { 1595 a = _parent[a]; 1596 } 1597 if (_parent[a] == INVALID) { 1520 1598 return INVALID; 1521 1599 } else { 1522 a = _left[a]; 1600 a = _parent[a]; 1601 const_cast<DynArcLookUp&>(*this).splay(a); 1523 1602 } 1524 } else { 1525 if (_right[a] == INVALID) { 1526 const_cast<DynArcLookUp&>(*this).splay(a); 1527 return INVALID; 1528 } else { 1529 a = _right[a]; 1530 } 1531 } 1532 } 1533 } 1534 1535 ///Find the first arc between two nodes. 1536 1537 ///Find the first arc between two nodes in time 1538 /// <em>O(</em>log<em>d)</em>, where <em>d</em> is the number of 1539 /// outgoing arcs of \c s. 1540 ///\param s The source node 1541 ///\param t The target node 1542 ///\return An arc from \c s to \c t if there exists, \ref INVALID 1543 /// otherwise. 1544 Arc findFirst(Node s, Node t) const 1545 { 1546 Arc a = _head[s]; 1547 Arc r = INVALID; 1548 while (true) { 1549 if (_g.target(a) < t) { 1550 if (_right[a] == INVALID) { 1551 const_cast<DynArcLookUp&>(*this).splay(a); 1552 return r; 1553 } else { 1554 a = _right[a]; 1555 } 1556 } else { 1557 if (_g.target(a) == t) { 1558 r = a; 1559 } 1560 if (_left[a] == INVALID) { 1561 const_cast<DynArcLookUp&>(*this).splay(a); 1562 return r; 1563 } else { 1564 a = _left[a]; 1565 } 1566 } 1567 } 1568 } 1569 1570 ///Find the next arc between two nodes. 1571 1572 ///Find the next arc between two nodes in time 1573 /// <em>O(</em>log<em>d)</em>, where <em>d</em> is the number of 1574 /// outgoing arcs of \c s. 1575 ///\param s The source node 1576 ///\param t The target node 1577 ///\return An arc from \c s to \c t if there exists, \ref INVALID 1578 /// otherwise. 1579 1580 ///\note If \c e is not the result of the previous \c findFirst() 1581 ///operation then the amorized time bound can not be guaranteed. 1582 #ifdef DOXYGEN 1583 Arc findNext(Node s, Node t, Arc a) const 1584 #else 1585 Arc findNext(Node, Node t, Arc a) const 1586 #endif 1587 { 1588 if (_right[a] != INVALID) { 1589 a = _right[a]; 1590 while (_left[a] != INVALID) { 1591 a = _left[a]; 1592 } 1593 const_cast<DynArcLookUp&>(*this).splay(a); 1594 } else { 1595 while (_parent[a] != INVALID && _right[_parent[a]] == a) { 1596 a = _parent[a]; 1597 } 1598 if (_parent[a] == INVALID) { 1599 return INVALID; 1600 } else { 1601 a = _parent[a]; 1602 const_cast<DynArcLookUp&>(*this).splay(a); 1603 } 1604 } 1605 if (_g.target(a) == t) return a; 1606 else return INVALID; 1603 } 1604 if (_g.target(a) == t) return a; 1605 else return INVALID; 1606 } 1607 1607 } 1608 1608 1609 1609 }; 1610 1610 1611 ///Fast arc look 1611 ///Fast arc look-up between given endpoints. 1612 1612 1613 1613 ///Using this class, you can find an arc in a digraph from a given 1614 ///source to a given target in time <em>O (log d)</em>,1614 ///source to a given target in time <em>O</em>(log<em>d</em>), 1615 1615 ///where <em>d</em> is the out-degree of the source node. 1616 1616 /// … … 1618 1618 ///Use \ref AllArcLookUp for this purpose. 1619 1619 /// 1620 ///\warning This class is static, so you should refresh() (or at least1621 /// refresh(Node)) this data structure1622 /// whenever the digraph changes. This is a time consuming (superlinearly1623 /// proportional (<em>O(m</em>log<em>m)</em>) to the number of arcs).1620 ///\warning This class is static, so you should call refresh() (or at 1621 ///least refresh(Node)) to refresh this data structure whenever the 1622 ///digraph changes. This is a time consuming (superlinearly proportional 1623 ///(<em>O</em>(<em>m</em> log<em>m</em>)) to the number of arcs). 1624 1624 /// 1625 1625 ///\tparam G The type of the underlying digraph. … … 1670 1670 } 1671 1671 public: 1672 ///Refresh the data structure at a node.1672 ///Refresh the search data structure at a node. 1673 1673 1674 1674 ///Build up the search database of node \c n. 1675 1675 /// 1676 ///It runs in time <em>O (d</em>log<em>d)</em>, where <em>d</em> is1677 /// the number of the outgoing arcs of \c n.1676 ///It runs in time <em>O</em>(<em>d</em> log<em>d</em>), where <em>d</em> 1677 ///is the number of the outgoing arcs of \c n. 1678 1678 void refresh(Node n) 1679 1679 { … … 1691 1691 ///\ref refresh(Node) "refresh(n)" for each node \c n. 1692 1692 /// 1693 ///It runs in time <em>O (m</em>log<em>D)</em>, where <em>m</em> is1694 ///the number of the arcs of \c nand <em>D</em> is the maximum1693 ///It runs in time <em>O</em>(<em>m</em> log<em>D</em>), where <em>m</em> is 1694 ///the number of the arcs in the digraph and <em>D</em> is the maximum 1695 1695 ///out-degree of the digraph. 1696 1697 1696 void refresh() 1698 1697 { … … 1702 1701 ///Find an arc between two nodes. 1703 1702 1704 ///Find an arc between two nodes in time <em>O (</em>log<em>d)</em>, where1705 /// <em>d</em> is the number of outgoing arcs of \c s.1706 ///\param s The source node 1707 ///\param t The target node 1703 ///Find an arc between two nodes in time <em>O</em>(log<em>d</em>), 1704 ///where <em>d</em> is the number of outgoing arcs of \c s. 1705 ///\param s The source node. 1706 ///\param t The target node. 1708 1707 ///\return An arc from \c s to \c t if there exists, 1709 1708 ///\ref INVALID otherwise. … … 1711 1710 ///\warning If you change the digraph, refresh() must be called before using 1712 1711 ///this operator. If you change the outgoing arcs of 1713 ///a single node \c n, then 1714 ///\ref refresh(Node) "refresh(n)" is enough. 1715 /// 1712 ///a single node \c n, then \ref refresh(Node) "refresh(n)" is enough. 1716 1713 Arc operator()(Node s, Node t) const 1717 1714 { … … 1725 1722 }; 1726 1723 1727 ///Fast look 1724 ///Fast look-up of all arcs between given endpoints. 1728 1725 1729 1726 ///This class is the same as \ref ArcLookUp, with the addition 1730 ///that it makes it possible to find all arcs between given endpoints. 1731 /// 1732 ///\warning This class is static, so you should refresh() (or at least 1733 ///refresh(Node)) this data structure 1734 ///whenever the digraph changes. This is a time consuming (superlinearly 1735 ///proportional (<em>O(m</em>log<em>m)</em>) to the number of arcs). 1727 ///that it makes it possible to find all parallel arcs between given 1728 ///endpoints. 1729 /// 1730 ///\warning This class is static, so you should call refresh() (or at 1731 ///least refresh(Node)) to refresh this data structure whenever the 1732 ///digraph changes. This is a time consuming (superlinearly proportional 1733 ///(<em>O</em>(<em>m</em> log<em>m</em>)) to the number of arcs). 1736 1734 /// 1737 1735 ///\tparam G The type of the underlying digraph. … … 1757 1755 else { 1758 1756 next=refreshNext(_right[head],next); 1759 // _next[head]=next;1760 1757 _next[head]=( next!=INVALID && _g.target(next)==_g.target(head)) 1761 1758 ? next : INVALID; … … 1782 1779 ///Build up the search database of node \c n. 1783 1780 /// 1784 ///It runs in time <em>O (d</em>log<em>d)</em>, where <em>d</em> is1781 ///It runs in time <em>O</em>(<em>d</em> log<em>d</em>), where <em>d</em> is 1785 1782 ///the number of the outgoing arcs of \c n. 1786 1787 1783 void refresh(Node n) 1788 1784 { … … 1796 1792 ///\ref refresh(Node) "refresh(n)" for each node \c n. 1797 1793 /// 1798 ///It runs in time <em>O (m</em>log<em>D)</em>, where <em>m</em> is1799 ///the number of the arcs of \c nand <em>D</em> is the maximum1794 ///It runs in time <em>O</em>(<em>m</em> log<em>D</em>), where <em>m</em> is 1795 ///the number of the arcs in the digraph and <em>D</em> is the maximum 1800 1796 ///out-degree of the digraph. 1801 1802 1797 void refresh() 1803 1798 { … … 1808 1803 1809 1804 ///Find an arc between two nodes. 1810 ///\param s The source node 1811 ///\param t The target node 1805 ///\param s The source node. 1806 ///\param t The target node. 1812 1807 ///\param prev The previous arc between \c s and \c t. It it is INVALID or 1813 1808 ///not given, the operator finds the first appropriate arc. … … 1820 1815 ///AllArcLookUp<ListDigraph> ae(g); 1821 1816 ///... 1822 ///int n =0;1823 ///for(Arc e=ae(u,v);e!=INVALID;e=ae(u,v,e)) n++;1817 ///int n = 0; 1818 ///for(Arc a = ae(u,v); a != INVALID; a=ae(u,v,a)) n++; 1824 1819 ///\endcode 1825 1820 /// 1826 ///Finding the first arc take <em>O (</em>log<em>d)</em> time, where1827 /// <em>d</em> is the number of outgoing arcs of \c s. Then,the1821 ///Finding the first arc take <em>O</em>(log<em>d</em>) time, 1822 ///where <em>d</em> is the number of outgoing arcs of \c s. Then the 1828 1823 ///consecutive arcs are found in constant time. 1829 1824 /// 1830 1825 ///\warning If you change the digraph, refresh() must be called before using 1831 1826 ///this operator. If you change the outgoing arcs of 1832 ///a single node \c n, then 1833 ///\ref refresh(Node) "refresh(n)" is enough. 1827 ///a single node \c n, then \ref refresh(Node) "refresh(n)" is enough. 1834 1828 /// 1835 1829 #ifdef DOXYGEN
Note: See TracChangeset
for help on using the changeset viewer.