diff -r f2ea4aac9ada -r c94ef40a22ce src/lemon/full_graph.h --- a/src/lemon/full_graph.h Mon Oct 25 13:29:46 2004 +0000 +++ b/src/lemon/full_graph.h Wed Oct 27 22:38:50 2004 +0000 @@ -17,20 +17,21 @@ #ifndef LEMON_FULL_GRAPH_H #define LEMON_FULL_GRAPH_H + +#include + +#include + +#include +#include + ///\ingroup graphs ///\file ///\brief FullGraph and SymFullGraph classes. -#include -#include #include -#include -#include - -#include - namespace lemon { /// \addtogroup graphs @@ -48,34 +49,26 @@ ///\todo Don't we need SymEdgeMap? /// ///\author Alpar Juttner - class FullGraph { + class FullGraphBase { int NodeNum; int EdgeNum; public: - typedef FullGraph Graph; + typedef FullGraphBase Graph; class Node; class Edge; - class NodeIt; - class EdgeIt; - class OutEdgeIt; - class InEdgeIt; - - - // Create map registries. - CREATE_MAP_REGISTRIES; - // Create node and edge maps. - CREATE_MAPS(ArrayMap); - public: + FullGraphBase() {} + + ///Creates a full graph with \c n nodes. - FullGraph(int n) : NodeNum(n), EdgeNum(NodeNum*NodeNum) { } + void construct(int n) { NodeNum = n; EdgeNum = n * n; } /// - FullGraph(const FullGraph &_g) - : NodeNum(_g.nodeNum()), EdgeNum(NodeNum*NodeNum) { } + // FullGraphBase(const FullGraphBase &_g) + // : NodeNum(_g.nodeNum()), EdgeNum(NodeNum*NodeNum) { } ///Number of nodes. int nodeNum() const { return NodeNum; } @@ -93,17 +86,9 @@ ///\sa id(Edge) int maxEdgeId() const { return EdgeNum-1; } - Node tail(Edge e) const { return e.n%NodeNum; } - Node head(Edge e) const { return e.n/NodeNum; } + Node tail(Edge e) const { return e.id % NodeNum; } + Node head(Edge e) const { return e.id / NodeNum; } - NodeIt& first(NodeIt& v) const { - v=NodeIt(*this); return v; } - EdgeIt& first(EdgeIt& e) const { - e=EdgeIt(*this); return e; } - OutEdgeIt& first(OutEdgeIt& e, const Node v) const { - e=OutEdgeIt(*this,v); return e; } - InEdgeIt& first(InEdgeIt& e, const Node v) const { - e=InEdgeIt(*this,v); return e; } /// Node ID. @@ -113,7 +98,8 @@ /// /// The ID of the \ref INVALID node is -1. ///\return The ID of the node \c v. - static int id(Node v) { return v.n; } + + static int id(Node v) { return v.id; } /// Edge ID. /// The ID of a valid Edge is a nonnegative integer not greater than @@ -122,7 +108,7 @@ /// /// The ID of the \ref INVALID edge is -1. ///\return The ID of the edge \c e. - static int id(Edge e) { return e.n; } + static int id(Edge e) { return e.id; } /// Finds an edge between two nodes. @@ -134,110 +120,102 @@ /// \return The found edge or INVALID if there is no such an edge. Edge findEdge(Node u,Node v, Edge prev = INVALID) { - return prev.n == -1 ? Edge(*this, u.n, v.n) : INVALID; + return prev.id == -1 ? Edge(*this, u.id, v.id) : INVALID; } class Node { - friend class FullGraph; - template friend class NodeMap; - - friend class Edge; - friend class OutEdgeIt; - friend class InEdgeIt; - friend class SymEdge; + friend class FullGraphBase; protected: - int n; - friend int FullGraph::id(Node v); - Node(int nn) {n=nn;} + int id; + Node(int _id) { id = _id;} public: Node() {} - Node (Invalid) { n=-1; } - bool operator==(const Node i) const {return n==i.n;} - bool operator!=(const Node i) const {return n!=i.n;} - bool operator<(const Node i) const {return n NodeIt. - NodeIt& operator++() { n=(n+2)%(G->NodeNum+1)-1;return *this; } + Edge() { } + Edge (Invalid) { id = -1; } + bool operator==(const Edge edge) const {return id == edge.id;} + bool operator!=(const Edge edge) const {return id != edge.id;} + bool operator<(const Edge edge) const {return id < edge.id;} }; - class Edge { - friend class FullGraph; - template friend class EdgeMap; - - friend class Node; - friend class NodeIt; - protected: - int n; //NodeNum*head+tail; - friend int FullGraph::id(Edge e); + void first(Node& node) const { + node.id = NodeNum-1; + } - Edge(int nn) : n(nn) {} - Edge(const FullGraph &G, int tail, int head) : n(G.NodeNum*head+tail) {} - public: - Edge() { } - Edge (Invalid) { n=-1; } - bool operator==(const Edge i) const {return n==i.n;} - bool operator!=(const Edge i) const {return n!=i.n;} - bool operator<(const Edge i) const {return nNodeNum; if(n>=G->EdgeNum) n=-1; return *this; } - - }; - - class InEdgeIt : public Edge { - const FullGraph *G; - friend class FullGraph; - public: - InEdgeIt() : Edge() { } - InEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { } - InEdgeIt (Invalid i) : Edge(i) { } - InEdgeIt(const FullGraph& _G,Node v) : Edge(v.n*_G.NodeNum), G(&_G) {} - InEdgeIt& operator++() - { if(!((++n)%G->NodeNum)) n=-1; return *this; } - }; + void nextIn(Edge& edge) const { + ++edge.id; + if (edge.id % NodeNum == 0) edge.id = -1; + } }; + + typedef AlterableGraphExtender AlterableFullGraphBase; + typedef IterableGraphExtender IterableFullGraphBase; + typedef IdMappableGraphExtender IdMappableFullGraphBase; + typedef DefaultMappableGraphExtender MappableFullGraphBase; + + class FullGraph : public MappableFullGraphBase { + public: + + FullGraph(int n) { construct(n); } + }; + + template <> + int countNodes(const FullGraph& graph) { + return graph.nodeNum(); + } + + template <> + int countEdges(const FullGraph& graph) { + return graph.edgeNum(); + } + /// @} } //namespace lemon