# HG changeset patch # User deba # Date 1147427505 0 # Node ID 10681ee9d8ae31a790874022b5f28f90ee5080b6 # Parent d4d1f6ca5c235037de8df1cdc5138576ee83eb67 Extenders modified UGraphBaseExtender => UndirGraphExtender BpUGraphBaseExtender merged into BpUGraphExtender diff -r d4d1f6ca5c23 -r 10681ee9d8ae lemon/bits/base_extender.h --- a/lemon/bits/base_extender.h Tue May 09 14:28:02 2006 +0000 +++ b/lemon/bits/base_extender.h Fri May 12 09:51:45 2006 +0000 @@ -37,7 +37,7 @@ /// /// \brief BaseExtender for the UGraphs template - class UGraphBaseExtender : public Base { + class UndirGraphExtender : public Base { public: @@ -48,7 +48,7 @@ typedef True UndirectedTag; class Edge : public UEdge { - friend class UGraphBaseExtender; + friend class UndirGraphExtender; protected: bool forward; @@ -275,208 +275,6 @@ } }; - - /// \ingroup graphbits - /// - /// \brief BaseExtender for the BpUGraphs - template - class BpUGraphBaseExtender : public Base { - public: - typedef Base Parent; - typedef BpUGraphBaseExtender Graph; - - typedef typename Parent::Node Node; - typedef typename Parent::Edge UEdge; - - - using Parent::first; - using Parent::next; - - using Parent::id; - - class ANode : public Node { - friend class BpUGraphBaseExtender; - public: - ANode() {} - ANode(const Node& node) : Node(node) { - LEMON_ASSERT(Parent::aNode(node) || node == INVALID, - typename Parent::NodeSetError()); - } - ANode(Invalid) : Node(INVALID) {} - }; - - void first(ANode& node) const { - Parent::firstANode(static_cast(node)); - } - void next(ANode& node) const { - Parent::nextANode(static_cast(node)); - } - - int id(const ANode& node) const { - return Parent::aNodeId(node); - } - - class BNode : public Node { - friend class BpUGraphBaseExtender; - public: - BNode() {} - BNode(const Node& node) : Node(node) { - LEMON_ASSERT(Parent::bNode(node) || node == INVALID, - typename Parent::NodeSetError()); - } - BNode(Invalid) : Node(INVALID) {} - }; - - void first(BNode& node) const { - Parent::firstBNode(static_cast(node)); - } - void next(BNode& node) const { - Parent::nextBNode(static_cast(node)); - } - - int id(const BNode& node) const { - return Parent::aNodeId(node); - } - - Node source(const UEdge& edge) const { - return aNode(edge); - } - Node target(const UEdge& edge) const { - return bNode(edge); - } - - void firstInc(UEdge& edge, bool& direction, const Node& node) const { - if (Parent::aNode(node)) { - Parent::firstOut(edge, node); - direction = true; - } else { - Parent::firstIn(edge, node); - direction = static_cast(edge) == INVALID; - } - } - void nextInc(UEdge& edge, bool& direction) const { - if (direction) { - Parent::nextOut(edge); - } else { - Parent::nextIn(edge); - if (edge == INVALID) direction = true; - } - } - - int maxUEdgeId() const { - return Parent::maxEdgeId(); - } - - UEdge uEdgeFromId(int id) const { - return Parent::edgeFromId(id); - } - - class Edge : public UEdge { - friend class BpUGraphBaseExtender; - protected: - bool forward; - - Edge(const UEdge& edge, bool _forward) - : UEdge(edge), forward(_forward) {} - - public: - Edge() {} - Edge (Invalid) : UEdge(INVALID), forward(true) {} - bool operator==(const Edge& i) const { - return UEdge::operator==(i) && forward == i.forward; - } - bool operator!=(const Edge& i) const { - return UEdge::operator!=(i) || forward != i.forward; - } - bool operator<(const Edge& i) const { - return UEdge::operator<(i) || - (!(i.forward(edge)); - edge.forward = true; - } - - void next(Edge& edge) const { - if (!edge.forward) { - Parent::next(static_cast(edge)); - } - edge.forward = !edge.forward; - } - - void firstOut(Edge& edge, const Node& node) const { - if (Parent::aNode(node)) { - Parent::firstOut(edge, node); - edge.forward = true; - } else { - Parent::firstIn(edge, node); - edge.forward = static_cast(edge) == INVALID; - } - } - void nextOut(Edge& edge) const { - if (edge.forward) { - Parent::nextOut(edge); - } else { - Parent::nextIn(edge); - edge.forward = static_cast(edge) == INVALID; - } - } - - void firstIn(Edge& edge, const Node& node) const { - if (Parent::bNode(node)) { - Parent::firstIn(edge, node); - edge.forward = true; - } else { - Parent::firstOut(edge, node); - edge.forward = static_cast(edge) == INVALID; - } - } - void nextIn(Edge& edge) const { - if (edge.forward) { - Parent::nextIn(edge); - } else { - Parent::nextOut(edge); - edge.forward = static_cast(edge) == INVALID; - } - } - - Node source(const Edge& edge) const { - return edge.forward ? Parent::aNode(edge) : Parent::bNode(edge); - } - Node target(const Edge& edge) const { - return edge.forward ? Parent::bNode(edge) : Parent::aNode(edge); - } - - int id(const Edge& edge) const { - return (Parent::id(edge) << 1) + (edge.forward ? 0 : 1); - } - Edge edgeFromId(int id) const { - return Edge(Parent::fromId(id >> 1, UEdge()), (id & 1) == 0); - } - int maxEdgeId() const { - return (Parent::maxId(UEdge()) << 1) + 1; - } - - bool direction(const Edge& edge) const { - return edge.forward; - } - - Edge direct(const UEdge& edge, bool direction) const { - return Edge(edge, direction); - } - - int edgeNum() const { - return 2 * Parent::edgeNum(); - } - - int uEdgeNum() const { - return Parent::edgeNum(); - } - - }; - } #endif diff -r d4d1f6ca5c23 -r 10681ee9d8ae lemon/bits/graph_adaptor_extender.h --- a/lemon/bits/graph_adaptor_extender.h Tue May 09 14:28:02 2006 +0000 +++ b/lemon/bits/graph_adaptor_extender.h Fri May 12 09:51:45 2006 +0000 @@ -453,11 +453,6 @@ typedef typename Parent::Edge Edge; typedef typename Parent::UEdge UEdge; - Node oppositeNode(const UEdge& edge, const Node& node) const { - return source(edge) == node ? - target(edge) : source(edge); - } - int maxId(Node) const { return Parent::maxNodeId(); diff -r d4d1f6ca5c23 -r 10681ee9d8ae lemon/bits/graph_extender.h --- a/lemon/bits/graph_extender.h Tue May 09 14:28:02 2006 +0000 +++ b/lemon/bits/graph_extender.h Fri May 12 09:51:45 2006 +0000 @@ -734,17 +734,193 @@ typedef BpUGraphExtender Graph; typedef typename Parent::Node Node; - typedef typename Parent::BNode BNode; - typedef typename Parent::ANode ANode; - typedef typename Parent::Edge Edge; typedef typename Parent::UEdge UEdge; + + using Parent::first; + using Parent::next; + + using Parent::id; + + class ANode : public Node { + friend class BpUGraphExtender; + public: + ANode() {} + ANode(const Node& node) : Node(node) { + LEMON_ASSERT(Parent::aNode(node) || node == INVALID, + typename Parent::NodeSetError()); + } + ANode(Invalid) : Node(INVALID) {} + }; + + void first(ANode& node) const { + Parent::firstANode(static_cast(node)); + } + void next(ANode& node) const { + Parent::nextANode(static_cast(node)); + } + + int id(const ANode& node) const { + return Parent::aNodeId(node); + } + + class BNode : public Node { + friend class BpUGraphExtender; + public: + BNode() {} + BNode(const Node& node) : Node(node) { + LEMON_ASSERT(Parent::bNode(node) || node == INVALID, + typename Parent::NodeSetError()); + } + BNode(Invalid) : Node(INVALID) {} + }; + + void first(BNode& node) const { + Parent::firstBNode(static_cast(node)); + } + void next(BNode& node) const { + Parent::nextBNode(static_cast(node)); + } + + int id(const BNode& node) const { + return Parent::aNodeId(node); + } + + Node source(const UEdge& edge) const { + return aNode(edge); + } + Node target(const UEdge& edge) const { + return bNode(edge); + } + + void firstInc(UEdge& edge, bool& direction, const Node& node) const { + if (Parent::aNode(node)) { + Parent::firstFromANode(edge, node); + direction = true; + } else { + Parent::firstFromBNode(edge, node); + direction = static_cast(edge) == INVALID; + } + } + void nextInc(UEdge& edge, bool& direction) const { + if (direction) { + Parent::nextFromANode(edge); + } else { + Parent::nextFromBNode(edge); + if (edge == INVALID) direction = true; + } + } + + class Edge : public UEdge { + friend class BpUGraphExtender; + protected: + bool forward; + + Edge(const UEdge& edge, bool _forward) + : UEdge(edge), forward(_forward) {} + + public: + Edge() {} + Edge (Invalid) : UEdge(INVALID), forward(true) {} + bool operator==(const Edge& i) const { + return UEdge::operator==(i) && forward == i.forward; + } + bool operator!=(const Edge& i) const { + return UEdge::operator!=(i) || forward != i.forward; + } + bool operator<(const Edge& i) const { + return UEdge::operator<(i) || + (!(i.forward(edge)); + edge.forward = true; + } + + void next(Edge& edge) const { + if (!edge.forward) { + Parent::next(static_cast(edge)); + } + edge.forward = !edge.forward; + } + + void firstOut(Edge& edge, const Node& node) const { + if (Parent::aNode(node)) { + Parent::firstFromANode(edge, node); + edge.forward = true; + } else { + Parent::firstFromBNode(edge, node); + edge.forward = static_cast(edge) == INVALID; + } + } + void nextOut(Edge& edge) const { + if (edge.forward) { + Parent::nextFromANode(edge); + } else { + Parent::nextFromBNode(edge); + edge.forward = static_cast(edge) == INVALID; + } + } + + void firstIn(Edge& edge, const Node& node) const { + if (Parent::bNode(node)) { + Parent::firstFromBNode(edge, node); + edge.forward = true; + } else { + Parent::firstFromANode(edge, node); + edge.forward = static_cast(edge) == INVALID; + } + } + void nextIn(Edge& edge) const { + if (edge.forward) { + Parent::nextFromBNode(edge); + } else { + Parent::nextFromANode(edge); + edge.forward = static_cast(edge) == INVALID; + } + } + + Node source(const Edge& edge) const { + return edge.forward ? Parent::aNode(edge) : Parent::bNode(edge); + } + Node target(const Edge& edge) const { + return edge.forward ? Parent::bNode(edge) : Parent::aNode(edge); + } + + int id(const Edge& edge) const { + return (Parent::id(static_cast(edge)) << 1) + + (edge.forward ? 0 : 1); + } + Edge edgeFromId(int id) const { + return Edge(Parent::fromUEdgeId(id >> 1), (id & 1) == 0); + } + int maxEdgeId() const { + return (Parent::maxUEdgeId(UEdge()) << 1) + 1; + } + + bool direction(const Edge& edge) const { + return edge.forward; + } + + Edge direct(const UEdge& edge, bool direction) const { + return Edge(edge, direction); + } + + int edgeNum() const { + return 2 * Parent::uEdgeNum(); + } + + int uEdgeNum() const { + return Parent::uEdgeNum(); + } + Node oppositeNode(const UEdge& edge, const Node& node) const { return source(edge) == node ? target(edge) : source(edge); } - using Parent::direct; Edge direct(const UEdge& edge, const Node& node) const { return Edge(edge, node == Parent::source(edge)); } @@ -764,7 +940,7 @@ return Parent::maxANodeId(); } int maxId(Edge) const { - return Parent::maxEdgeId(); + return maxEdgeId(); } int maxId(UEdge) const { return Parent::maxUEdgeId(); diff -r d4d1f6ca5c23 -r 10681ee9d8ae lemon/edge_set.h --- a/lemon/edge_set.h Tue May 09 14:28:02 2006 +0000 +++ b/lemon/edge_set.h Fri May 12 09:51:45 2006 +0000 @@ -337,11 +337,11 @@ /// \ref concept::ErasableUGraph "ErasableUGraph" concept. template class ListUEdgeSet - : public UEdgeSetExtender > > { + : public UEdgeSetExtender > > { public: - typedef UEdgeSetExtender > > Parent; typedef typename Parent::Node Node; @@ -669,11 +669,11 @@ /// \ref concept::ExtendableUGraph "ExtendableUGraph" concept. template class SmartUEdgeSet - : public UEdgeSetExtender > > { + : public UEdgeSetExtender > > { public: - typedef UEdgeSetExtender > > Parent; typedef typename Parent::Node Node; diff -r d4d1f6ca5c23 -r 10681ee9d8ae lemon/full_graph.h --- a/lemon/full_graph.h Tue May 09 14:28:02 2006 +0000 +++ b/lemon/full_graph.h Fri May 12 09:51:45 2006 +0000 @@ -441,7 +441,7 @@ }; - typedef UGraphExtender > + typedef UGraphExtender > ExtendedFullUGraphBase; /// \ingroup graphs @@ -518,18 +518,18 @@ bool operator<(const Node i) const {return id> 1) * _bNodeNum; } - void nextOut(Edge& edge) const { + void nextFromANode(UEdge& edge) const { ++(edge.id); if (edge.id % _bNodeNum == 0) edge.id = -1; } - void firstIn(Edge& edge, const Node& node) const { + void firstFromBNode(UEdge& edge, const Node& node) const { LEMON_ASSERT((node.id & 1) == 1, NodeSetError()); edge.id = (node.id >> 1); } - void nextIn(Edge& edge) const { + void nextFromBNode(UEdge& edge) const { edge.id += _bNodeNum; if (edge.id >= _edgeNum) edge.id = -1; } @@ -604,13 +604,13 @@ _aNodeNum * 2 - 2 : _bNodeNum * 2 - 1; } - static int id(const Edge& edge) { + static int id(const UEdge& edge) { return edge.id; } - static Edge edgeFromId(int id) { - return Edge(id); + static UEdge uEdgeFromId(int id) { + return UEdge(id); } - int maxEdgeId() const { + int maxUEdgeId() const { return _edgeNum - 1; } @@ -634,10 +634,10 @@ return _bNodeNum; } - Node aNode(const Edge& edge) const { + Node aNode(const UEdge& edge) const { return Node((edge.id / _bNodeNum) << 1); } - Node bNode(const Edge& edge) const { + Node bNode(const UEdge& edge) const { return Node(((edge.id % _bNodeNum) << 1) + 1); } @@ -663,13 +663,12 @@ int bNodeNum() const { return _bNodeNum; } typedef True EdgeNumTag; - int edgeNum() const { return _edgeNum; } + int uEdgeNum() const { return _edgeNum; } }; - typedef BpUGraphExtender< BpUGraphBaseExtender< - FullBpUGraphBase> > ExtendedFullBpUGraphBase; + typedef BpUGraphExtender ExtendedFullBpUGraphBase; /// \ingroup graphs diff -r d4d1f6ca5c23 -r 10681ee9d8ae lemon/grid_ugraph.h --- a/lemon/grid_ugraph.h Tue May 09 14:28:02 2006 +0000 +++ b/lemon/grid_ugraph.h Fri May 12 09:51:45 2006 +0000 @@ -347,8 +347,8 @@ }; - typedef UGraphExtender > ExtendedGridUGraphBase; + typedef UGraphExtender > + ExtendedGridUGraphBase; /// \ingroup graphs /// diff -r d4d1f6ca5c23 -r 10681ee9d8ae lemon/list_graph.h --- a/lemon/list_graph.h Tue May 09 14:28:02 2006 +0000 +++ b/lemon/list_graph.h Fri May 12 09:51:45 2006 +0000 @@ -566,8 +566,8 @@ /**************** Undirected List Graph ****************/ - typedef UGraphExtender > ExtendedListUGraphBase; + typedef UGraphExtender > + ExtendedListUGraphBase; /// \addtogroup graphs /// @{ @@ -651,7 +651,7 @@ int first_edge, next_node; }; - struct EdgeT { + struct UEdgeT { int aNode, prev_out, next_out; int bNode, prev_in, next_in; }; @@ -659,7 +659,7 @@ std::vector aNodes; std::vector bNodes; - std::vector edges; + std::vector edges; int first_anode; int first_free_anode; @@ -685,18 +685,18 @@ bool operator<(const Node i) const {return id> 1; edge.id = edges[edge.id].next_out; if (edge.id == -1) { @@ -770,19 +770,19 @@ } } - void firstOut(Edge& edge, const Node& node) const { + void firstFromANode(UEdge& edge, const Node& node) const { LEMON_ASSERT((node.id & 1) == 0, NodeSetError()); edge.id = aNodes[node.id >> 1].first_edge; } - void nextOut(Edge& edge) const { + void nextFromANode(UEdge& edge) const { edge.id = edges[edge.id].next_out; } - void firstIn(Edge& edge, const Node& node) const { + void firstFromBNode(UEdge& edge, const Node& node) const { LEMON_ASSERT((node.id & 1) == 1, NodeSetError()); edge.id = bNodes[node.id >> 1].first_edge; } - void nextIn(Edge& edge) const { + void nextFromBNode(UEdge& edge) const { edge.id = edges[edge.id].next_in; } @@ -797,13 +797,13 @@ aNodes.size() * 2 - 2 : bNodes.size() * 2 - 1; } - static int id(const Edge& edge) { + static int id(const UEdge& edge) { return edge.id; } - static Edge edgeFromId(int id) { - return Edge(id); + static UEdge uEdgeFromId(int id) { + return UEdge(id); } - int maxEdgeId() const { + int maxUEdgeId() const { return edges.size(); } @@ -827,10 +827,10 @@ return bNodes.size(); } - Node aNode(const Edge& edge) const { + Node aNode(const UEdge& edge) const { return Node(edges[edge.id].aNode); } - Node bNode(const Edge& edge) const { + Node bNode(const UEdge& edge) const { return Node(edges[edge.id].bNode); } @@ -874,7 +874,7 @@ return Node((bNodeId << 1) + 1); } - Edge addEdge(const Node& source, const Node& target) { + UEdge addEdge(const Node& source, const Node& target) { LEMON_ASSERT(((source.id ^ target.id) & 1) == 1, NodeSetError()); int edgeId; if (first_free_edge != -1) { @@ -882,7 +882,7 @@ first_free_edge = edges[edgeId].next_out; } else { edgeId = edges.size(); - edges.push_back(EdgeT()); + edges.push_back(UEdgeT()); } if ((source.id & 1) == 0) { edges[edgeId].aNode = source.id; @@ -903,7 +903,7 @@ edges[bNodes[edges[edgeId].bNode >> 1].first_edge].prev_in = edgeId; } bNodes[edges[edgeId].bNode >> 1].first_edge = edgeId; - return Edge(edgeId); + return UEdge(edgeId); } void erase(const Node& node) { @@ -918,7 +918,7 @@ } } - void erase(const Edge& edge) { + void erase(const UEdge& edge) { if (edges[edge.id].prev_out != -1) { edges[edges[edge.id].prev_out].next_out = edges[edge.id].next_out; } else { @@ -953,8 +953,7 @@ }; - typedef BpUGraphExtender< BpUGraphBaseExtender< - ListBpUGraphBase> > ExtendedListBpUGraphBase; + typedef BpUGraphExtender< ListBpUGraphBase > ExtendedListBpUGraphBase; /// \ingroup graphs /// diff -r d4d1f6ca5c23 -r 10681ee9d8ae lemon/smart_graph.h --- a/lemon/smart_graph.h Tue May 09 14:28:02 2006 +0000 +++ b/lemon/smart_graph.h Fri May 12 09:51:45 2006 +0000 @@ -119,8 +119,16 @@ ///\return The ID of the edge \c e. static int id(Edge e) { return e.n; } + /// \brief Returns the node from its \c id. + /// + /// Returns the node from its \c id. If there is not node + /// with the given id the effect of the function is undefinied. static Node nodeFromId(int id) { return Node(id);} + /// \brief Returns the edge from its \c id. + /// + /// Returns the edge from its \c id. If there is not edge + /// with the given id the effect of the function is undefinied. static Edge edgeFromId(int id) { return Edge(id);} Node addNode() { @@ -350,7 +358,7 @@ /**************** Undirected List Graph ****************/ - typedef UGraphExtender > + typedef UGraphExtender > ExtendedSmartUGraphBase; /// \ingroup graphs @@ -388,7 +396,7 @@ NodeT(int _first) : first(_first) {} }; - struct EdgeT { + struct UEdgeT { int aNode, next_out; int bNode, next_in; }; @@ -396,7 +404,7 @@ std::vector aNodes; std::vector bNodes; - std::vector edges; + std::vector edges; public: @@ -414,18 +422,18 @@ bool operator<(const Node i) const {return id> 1].first; } - void nextOut(Edge& edge) const { + void nextFromANode(UEdge& edge) const { edge.id = edges[edge.id].next_out; } - void firstIn(Edge& edge, const Node& node) const { + void firstFromBNode(UEdge& edge, const Node& node) const { LEMON_ASSERT((node.id & 1) == 1, NodeSetError()); edge.id = bNodes[node.id >> 1].first; } - void nextIn(Edge& edge) const { + void nextFromBNode(UEdge& edge) const { edge.id = edges[edge.id].next_in; } @@ -492,13 +500,13 @@ aNodes.size() * 2 - 2 : bNodes.size() * 2 - 1; } - static int id(const Edge& edge) { + static int id(const UEdge& edge) { return edge.id; } - static Edge edgeFromId(int id) { - return Edge(id); + static UEdge uEdgeFromId(int id) { + return UEdge(id); } - int maxEdgeId() const { + int maxUEdgeId() const { return edges.size(); } @@ -522,10 +530,10 @@ return bNodes.size(); } - Node aNode(const Edge& edge) const { + Node aNode(const UEdge& edge) const { return Node(edges[edge.id].aNode); } - Node bNode(const Edge& edge) const { + Node bNode(const UEdge& edge) const { return Node(edges[edge.id].bNode); } @@ -551,9 +559,9 @@ return Node(bNodes.size() * 2 - 1); } - Edge addEdge(const Node& source, const Node& target) { + UEdge addEdge(const Node& source, const Node& target) { LEMON_ASSERT(((source.id ^ target.id) & 1) == 1, NodeSetError()); - EdgeT edgeT; + UEdgeT edgeT; if ((source.id & 1) == 0) { edgeT.aNode = source.id; edgeT.bNode = target.id; @@ -566,7 +574,7 @@ edgeT.next_in = bNodes[edgeT.bNode >> 1].first; bNodes[edgeT.bNode >> 1].first = edges.size(); edges.push_back(edgeT); - return Edge(edges.size() - 1); + return UEdge(edges.size() - 1); } void clear() { @@ -581,13 +589,12 @@ int bNodeNum() const { return bNodes.size(); } typedef True EdgeNumTag; - int edgeNum() const { return edges.size(); } + int uEdgeNum() const { return edges.size(); } }; - typedef BpUGraphExtender< BpUGraphBaseExtender< - SmartBpUGraphBase> > ExtendedSmartBpUGraphBase; + typedef BpUGraphExtender ExtendedSmartBpUGraphBase; /// \ingroup graphs ///