1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/deba/edge_map_base.h Mon Mar 29 21:43:27 2004 +0000
1.3 @@ -0,0 +1,29 @@
1.4 +#ifndef EDGE_MAP_BASE_H
1.5 +#define EDGE_MAP_BASE_H
1.6 +
1.7 +template <class G, class K>
1.8 +class EdgeMapBase {
1.9 +public:
1.10 + typedef G Graph;
1.11 + typedef K KeyType;
1.12 +
1.13 +
1.14 + MapBase() : graph(0) {}
1.15 + MapBase(Graph& g) : graph(&g) {graph.edge_maps.add(*this);}
1.16 +
1.17 + virtual ~MapBase() {graph.edge_maps.erase(*this);}
1.18 +
1.19 +protected:
1.20 +
1.21 + Graph* graph;
1.22 +
1.23 + int graph_index;
1.24 +
1.25 +
1.26 + virtual void add(const KeyType&) = 0;
1.27 + virtual void erase(const KeyType&) = 0;
1.28 +
1.29 + friend class Graph;
1.30 +};
1.31 +
1.32 +#endif
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/work/deba/edge_map_register.h Mon Mar 29 21:43:27 2004 +0000
2.3 @@ -0,0 +1,52 @@
2.4 +#ifndef EDGE_MAP_REGISTER_H
2.5 +#define EDGE_MAP_REGISTER_H
2.6 +
2.7 +#include <vector>
2.8 +
2.9 +template <typename G, typename E>
2.10 +class EdgeMapRegister {
2.11 +public:
2.12 + typedef G Graph;
2.13 + typedef E Edge
2.14 +
2.15 + typedef EdgeMapBase<Graph, Edge> EdgeMapBase;
2.16 +
2.17 +protected:
2.18 + typedef std::vector<EdgeMapBase*> Container;
2.19 +
2.20 + Container container;
2.21 +
2.22 + void add(EdgeMapBase& map_base) {
2.23 + if (map_base.graph) {
2.24 + map_base.graph->edge_maps.erase(map_base);
2.25 + }
2.26 + container.push_back(&map_base);
2.27 + map_base.graph_index = container.size()-1;
2.28 + }
2.29 +
2.30 + void erase(EdgeMapBase& map_base) {
2.31 + if (map_base.graph != this) return;
2.32 + container.back()->graph_index = map_base.graph_index;
2.33 + container[map_base.graph_index] = container.back();
2.34 + container.pop_back();
2.35 + map_base.graph = 0;
2.36 + }
2.37 +
2.38 + void addEdge(Edge& edge) {
2.39 + typename Container::iterator it;
2.40 + for (it = container.begin(); it != container.end(); ++it) {
2.41 + (*it)->add(edge);
2.42 + }
2.43 + }
2.44 +
2.45 + void eraseEdge(Edge& edge) {
2.46 + typename Container::iterator it;
2.47 + for (it = container.begin(); it != container.end(); ++it) {
2.48 + (*it)->erase(edge);
2.49 + }
2.50 + }
2.51 +
2.52 + friend class EdgeMapBase;
2.53 +};
2.54 +
2.55 +#endif
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/src/work/deba/node_map_base.h Mon Mar 29 21:43:27 2004 +0000
3.3 @@ -0,0 +1,30 @@
3.4 +#ifndef NODE_MAP_BASE_H
3.5 +#define NODE_MAP_BASE_H
3.6 +
3.7 +template <class G, class K>
3.8 +class NodeMapBase {
3.9 +public:
3.10 + typedef G Graph;
3.11 +
3.12 + typedef K KeyType;
3.13 +
3.14 +
3.15 + MapBase() : graph(0) {}
3.16 + MapBase(Graph& g) : graph(&g) {graph.node_maps.add(*this);}
3.17 +
3.18 + virtual ~MapBase() {graph.node_maps.erase(*this);}
3.19 +
3.20 +protected:
3.21 +
3.22 + Graph* graph;
3.23 +
3.24 + int graph_index;
3.25 +
3.26 +
3.27 + virtual void add(const KeyType&) = 0;
3.28 + virtual void erase(const KeyType&) = 0;
3.29 +
3.30 + friend class Graph;
3.31 +};
3.32 +
3.33 +#endif
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/src/work/deba/test_graph.h Mon Mar 29 21:43:27 2004 +0000
4.3 @@ -0,0 +1,565 @@
4.4 +// -*- c++ -*-
4.5 +#ifndef HUGO_LIST_GRAPH_H
4.6 +#define HUGO_LIST_GRAPH_H
4.7 +
4.8 +#include <iostream>
4.9 +#include <vector>
4.10 +
4.11 +#include <invalid.h>
4.12 +
4.13 +namespace hugo {
4.14 +
4.15 + template <typename It>
4.16 + int count(It it) {
4.17 + int i=0;
4.18 + for( ; it.valid(); ++it) { ++i; }
4.19 + return i;
4.20 + }
4.21 +
4.22 + class ListGraph {
4.23 + class node_item;
4.24 + class edge_item;
4.25 + public:
4.26 + class Node;
4.27 + class NodeIt;
4.28 + class Edge;
4.29 + class EdgeIt;
4.30 + class OutEdgeIt;
4.31 + class InEdgeIt;
4.32 + class SymEdgeIt;
4.33 +
4.34 + template <typename T> class NodeMap;
4.35 + template <typename T> class EdgeMap;
4.36 + private:
4.37 + template <typename T> friend class NodeMap;
4.38 + template <typename T> friend class EdgeMap;
4.39 +
4.40 + template <typename T>
4.41 + class NodeMap {
4.42 + const ListGraph& G;
4.43 + std::vector<T> container;
4.44 + public:
4.45 + typedef T ValueType;
4.46 + typedef Node KeyType;
4.47 + NodeMap(const ListGraph& _G) : G(_G), container(G.node_id) { }
4.48 + NodeMap(const ListGraph& _G, T a) :
4.49 + G(_G), container(G.node_id, a) { }
4.50 + void set(Node n, T a) { container[/*G.id(n)*/n.node->id]=a; }
4.51 + T get(Node n) const { return container[/*G.id(n)*/n.node->id]; }
4.52 + typename std::vector<T>::reference operator[](Node n) {
4.53 + return container[/*G.id(n)*/n.node->id]; }
4.54 + typename std::vector<T>::const_reference operator[](Node n) const {
4.55 + return container[/*G.id(n)*/n.node->id];
4.56 + }
4.57 + void update() { container.resize(G.node_id); }
4.58 + void update(T a) { container.resize(G.node_id, a); }
4.59 + };
4.60 +
4.61 + template <typename T>
4.62 + class EdgeMap {
4.63 + const ListGraph& G;
4.64 + std::vector<T> container;
4.65 + public:
4.66 + typedef T ValueType;
4.67 + typedef Edge KeyType;
4.68 + EdgeMap(const ListGraph& _G) : G(_G), container(G.edge_id) { }
4.69 + EdgeMap(const ListGraph& _G, T a) :
4.70 + G(_G), container(G.edge_id, a) { }
4.71 + void set(Edge e, T a) { container[/*G.id(e)*/e.edge->id]=a; }
4.72 + T get(Edge e) const { return container[/*G.id(e)*/e.edge->id]; }
4.73 + typename std::vector<T>::reference operator[](Edge e) {
4.74 + return container[/*G.id(e)*/e.edge->id]; }
4.75 + typename std::vector<T>::const_reference operator[](Edge e) const {
4.76 + return container[/*G.id(e)*/e.edge->id];
4.77 + }
4.78 + void update() { container.resize(G.edge_id); }
4.79 + void update(T a) { container.resize(G.edge_id, a); }
4.80 + };
4.81 +
4.82 + int node_id;
4.83 + int edge_id;
4.84 + int _node_num;
4.85 + int _edge_num;
4.86 +
4.87 + node_item* _first_node;
4.88 + node_item* _last_node;
4.89 +
4.90 + class node_item {
4.91 + friend class ListGraph;
4.92 + template <typename T> friend class NodeMap;
4.93 +
4.94 + friend class Node;
4.95 + friend class NodeIt;
4.96 + friend class Edge;
4.97 + friend class EdgeIt;
4.98 + friend class OutEdgeIt;
4.99 + friend class InEdgeIt;
4.100 + friend class SymEdgeIt;
4.101 + friend std::ostream& operator<<(std::ostream& os, const Node& i);
4.102 + friend std::ostream& operator<<(std::ostream& os, const Edge& i);
4.103 + //ListGraph* G;
4.104 + int id;
4.105 + edge_item* _first_out_edge;
4.106 + edge_item* _last_out_edge;
4.107 + edge_item* _first_in_edge;
4.108 + edge_item* _last_in_edge;
4.109 + node_item* _next_node;
4.110 + node_item* _prev_node;
4.111 + public:
4.112 + node_item() { }
4.113 + };
4.114 +
4.115 + class edge_item {
4.116 + friend class ListGraph;
4.117 + template <typename T> friend class EdgeMap;
4.118 +
4.119 + friend class Node;
4.120 + friend class NodeIt;
4.121 + friend class Edge;
4.122 + friend class EdgeIt;
4.123 + friend class OutEdgeIt;
4.124 + friend class InEdgeIt;
4.125 + friend class SymEdgeIt;
4.126 + friend std::ostream& operator<<(std::ostream& os, const Edge& i);
4.127 + //ListGraph* G;
4.128 + int id;
4.129 + node_item* _tail;
4.130 + node_item* _head;
4.131 + edge_item* _next_out;
4.132 + edge_item* _prev_out;
4.133 + edge_item* _next_in;
4.134 + edge_item* _prev_in;
4.135 + public:
4.136 + edge_item() { }
4.137 + };
4.138 +
4.139 + node_item* _add_node() {
4.140 + node_item* p=new node_item;
4.141 + p->id=node_id++;
4.142 + p->_first_out_edge=0;
4.143 + p->_last_out_edge=0;
4.144 + p->_first_in_edge=0;
4.145 + p->_last_in_edge=0;
4.146 + p->_prev_node=_last_node;
4.147 + p->_next_node=0;
4.148 + if (_last_node) _last_node->_next_node=p;
4.149 + _last_node=p;
4.150 + if (!_first_node) _first_node=p;
4.151 +
4.152 + ++_node_num;
4.153 + return p;
4.154 + }
4.155 +
4.156 + edge_item* _add_edge(node_item* _tail, node_item* _head) {
4.157 + edge_item* e=new edge_item;
4.158 + e->id=edge_id++;
4.159 + e->_tail=_tail;
4.160 + e->_head=_head;
4.161 +
4.162 + e->_prev_out=_tail->_last_out_edge;
4.163 + if (_tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;
4.164 + _tail->_last_out_edge=e;
4.165 + if (!_tail->_first_out_edge) _tail->_first_out_edge=e;
4.166 + e->_next_out=0;
4.167 +
4.168 + e->_prev_in=_head->_last_in_edge;
4.169 + if (_head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;
4.170 + _head->_last_in_edge=e;
4.171 + if (!_head->_first_in_edge) { _head->_first_in_edge=e; }
4.172 + e->_next_in=0;
4.173 +
4.174 + ++_edge_num;
4.175 + return e;
4.176 + }
4.177 +
4.178 + //deletes a node which has no out edge and no in edge
4.179 + void _delete_node(node_item* v) {
4.180 + if (v->_next_node) (v->_next_node)->_prev_node=v->_prev_node; else
4.181 + _last_node=v->_prev_node;
4.182 + if (v->_prev_node) (v->_prev_node)->_next_node=v->_next_node; else
4.183 + _first_node=v->_next_node;
4.184 +
4.185 + delete v;
4.186 + --_node_num;
4.187 + }
4.188 +
4.189 + void _delete_edge(edge_item* e) {
4.190 + if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else
4.191 + (e->_tail)->_last_out_edge=e->_prev_out;
4.192 + if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else
4.193 + (e->_tail)->_first_out_edge=e->_next_out;
4.194 + if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else
4.195 + (e->_head)->_last_in_edge=e->_prev_in;
4.196 + if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else
4.197 + (e->_head)->_first_in_edge=e->_next_in;
4.198 +
4.199 + delete e;
4.200 + --_edge_num;
4.201 + }
4.202 +
4.203 + void _set_tail(edge_item* e, node_item* _tail) {
4.204 + if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else
4.205 + (e->_tail)->_last_out_edge=e->_prev_out;
4.206 + if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else
4.207 + (e->_tail)->_first_out_edge=e->_next_out;
4.208 +
4.209 + e->_tail=_tail;
4.210 +
4.211 + e->_prev_out=_tail->_last_out_edge;
4.212 + if (_tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;
4.213 + _tail->_last_out_edge=e;
4.214 + if (!_tail->_first_out_edge) _tail->_first_out_edge=e;
4.215 + e->_next_out=0;
4.216 + }
4.217 +
4.218 + void _set_head(edge_item* e, node_item* _head) {
4.219 + if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else
4.220 + (e->_head)->_last_in_edge=e->_prev_in;
4.221 + if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else
4.222 + (e->_head)->_first_in_edge=e->_next_in;
4.223 +
4.224 + e->_head=_head;
4.225 +
4.226 + e->_prev_in=_head->_last_in_edge;
4.227 + if (_head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;
4.228 + _head->_last_in_edge=e;
4.229 + if (!_head->_first_in_edge) { _head->_first_in_edge=e; }
4.230 + e->_next_in=0;
4.231 + }
4.232 +
4.233 + public:
4.234 +
4.235 + /* default constructor */
4.236 +
4.237 + ListGraph() : node_id(0), edge_id(0), _node_num(0), _edge_num(0), _first_node(0), _last_node(0) { }
4.238 +
4.239 + ~ListGraph() {
4.240 + while (first<NodeIt>().valid()) erase(first<NodeIt>());
4.241 + }
4.242 +
4.243 + int nodeNum() const { return _node_num; }
4.244 + int edgeNum() const { return _edge_num; }
4.245 +
4.246 + /* functions to construct iterators from the graph, or from each other */
4.247 +
4.248 + //NodeIt firstNode() const { return NodeIt(*this); }
4.249 + //EdgeIt firstEdge() const { return EdgeIt(*this); }
4.250 +
4.251 + //OutEdgeIt firstOutEdge(const Node v) const { return OutEdgeIt(v); }
4.252 + //InEdgeIt firstInEdge(const Node v) const { return InEdgeIt(v); }
4.253 + //SymEdgeIt firstSymEdge(const Node v) const { return SymEdgeIt(v); }
4.254 + Node tail(Edge e) const { return e.tailNode(); }
4.255 + Node head(Edge e) const { return e.headNode(); }
4.256 +
4.257 + Node aNode(const OutEdgeIt& e) const { return e.aNode(); }
4.258 + Node aNode(const InEdgeIt& e) const { return e.aNode(); }
4.259 + Node aNode(const SymEdgeIt& e) const { return e.aNode(); }
4.260 +
4.261 + Node bNode(const OutEdgeIt& e) const { return e.bNode(); }
4.262 + Node bNode(const InEdgeIt& e) const { return e.bNode(); }
4.263 + Node bNode(const SymEdgeIt& e) const { return e.bNode(); }
4.264 +
4.265 + //Node invalid_node() { return Node(); }
4.266 + //Edge invalid_edge() { return Edge(); }
4.267 + //OutEdgeIt invalid_out_edge() { return OutEdgeIt(); }
4.268 + //InEdgeIt invalid_in_edge() { return InEdgeIt(); }
4.269 + //SymEdgeIt invalid_sym_edge() { return SymEdgeIt(); }
4.270 +
4.271 + /* same methods in other style */
4.272 + /* for experimental purpose */
4.273 +
4.274 + NodeIt& /*getF*/first(NodeIt& v) const {
4.275 + v=NodeIt(*this); return v; }
4.276 + EdgeIt& /*getF*/first(EdgeIt& e) const {
4.277 + e=EdgeIt(*this); return e; }
4.278 + OutEdgeIt& /*getF*/first(OutEdgeIt& e, Node v) const {
4.279 + e=OutEdgeIt(*this, v); return e; }
4.280 + InEdgeIt& /*getF*/first(InEdgeIt& e, Node v) const {
4.281 + e=InEdgeIt(*this, v); return e; }
4.282 + SymEdgeIt& /*getF*/first(SymEdgeIt& e, Node v) const {
4.283 + e=SymEdgeIt(*this, v); return e; }
4.284 + //void getTail(Node& n, const Edge& e) const { n=tail(e); }
4.285 + //void getHead(Node& n, const Edge& e) const { n=head(e); }
4.286 +
4.287 + //void getANode(Node& n, const OutEdgeIt& e) const { n=e.aNode(); }
4.288 + //void getANode(Node& n, const InEdgeIt& e) const { n=e.aNode(); }
4.289 + //void getANode(Node& n, const SymEdgeIt& e) const { n=e.aNode(); }
4.290 + //void getBNode(Node& n, const OutEdgeIt& e) const { n=e.bNode(); }
4.291 + //void getBNode(Node& n, const InEdgeIt& e) const { n=e.bNode(); }
4.292 + //void getBNode(Node& n, const SymEdgeIt& e) const { n=e.bNode(); }
4.293 + //void get_invalid(Node& n) { n=Node(); }
4.294 + //void get_invalid(Edge& e) { e=Edge(); }
4.295 + //void get_invalid(OutEdgeIt& e) { e=OutEdgeIt(); }
4.296 + //void get_invalid(InEdgeIt& e) { e=InEdgeIt(); }
4.297 + //void get_invalid(SymEdgeIt& e) { e=SymEdgeIt(); }
4.298 +
4.299 + template< typename It >
4.300 + It first() const {
4.301 + It e;
4.302 + /*getF*/first(e);
4.303 + return e;
4.304 + }
4.305 +
4.306 + template< typename It >
4.307 + It first(Node v) const {
4.308 + It e;
4.309 + /*getF*/first(e, v);
4.310 + return e;
4.311 + }
4.312 +
4.313 + bool valid(Node n) const { return n.valid(); }
4.314 + bool valid(Edge e) const { return e.valid(); }
4.315 +
4.316 + template <typename It> It getNext(It it) const {
4.317 + It tmp(it); return next(tmp); }
4.318 + template <typename It> It& next(It& it) const { return ++it; }
4.319 +
4.320 +
4.321 + /* for getting id's of graph objects */
4.322 + /* these are important for the implementation of property vectors */
4.323 +
4.324 + int id(Node v) const { return v.node->id; }
4.325 + int id(Edge e) const { return e.edge->id; }
4.326 +
4.327 + /* adding nodes and edges */
4.328 +
4.329 + Node addNode() { return Node(_add_node()); }
4.330 + Edge addEdge(Node u, Node v) {
4.331 + return Edge(_add_edge(u.node, v.node));
4.332 + }
4.333 +
4.334 + void erase(Node i) {
4.335 + while (first<OutEdgeIt>(i).valid()) erase(first<OutEdgeIt>(i));
4.336 + while (first<InEdgeIt>(i).valid()) erase(first<InEdgeIt>(i));
4.337 + _delete_node(i.node);
4.338 + }
4.339 +
4.340 + void erase(Edge e) { _delete_edge(e.edge); }
4.341 +
4.342 + void clear() {
4.343 + while (first<NodeIt>().valid()) erase(first<NodeIt>());
4.344 + }
4.345 +
4.346 + void setTail(Edge e, Node tail) {
4.347 + _set_tail(e.edge, tail.node);
4.348 + }
4.349 +
4.350 + void setHead(Edge e, Node head) {
4.351 + _set_head(e.edge, head.node);
4.352 + }
4.353 +
4.354 + /* stream operations, for testing purpose */
4.355 +
4.356 + friend std::ostream& operator<<(std::ostream& os, const Node& i) {
4.357 + os << i.node->id; return os;
4.358 + }
4.359 + friend std::ostream& operator<<(std::ostream& os, const Edge& i) {
4.360 + os << "(" << i.edge->_tail->id << "--" << i.edge->id << "->" << i.edge->_head->id << ")";
4.361 + return os;
4.362 + }
4.363 +
4.364 + class Node {
4.365 + friend class ListGraph;
4.366 + template <typename T> friend class NodeMap;
4.367 +
4.368 + friend class Edge;
4.369 + friend class OutEdgeIt;
4.370 + friend class InEdgeIt;
4.371 + friend class SymEdgeIt;
4.372 + //public: //FIXME: It is required by op= of NodeIt
4.373 + protected:
4.374 + node_item* node;
4.375 + protected:
4.376 + friend int ListGraph::id(Node v) const;
4.377 + public:
4.378 + Node() /*: node(0)*/ { }
4.379 + Node(const Invalid&) : node(0) { }
4.380 + protected:
4.381 + Node(node_item* _node) : node(_node) { }
4.382 + bool valid() const { return (node); }
4.383 + public:
4.384 + //void makeInvalid() { node=0; }
4.385 + friend bool operator==(Node u, Node v) { return v.node==u.node; }
4.386 + friend bool operator!=(Node u, Node v) { return v.node!=u.node; }
4.387 + friend std::ostream& operator<<(std::ostream& os, const Node& i);
4.388 + };
4.389 +
4.390 + class NodeIt : public Node {
4.391 + friend class ListGraph;
4.392 + //protected:
4.393 + public: //for everybody but marci
4.394 + NodeIt(const ListGraph& G) : Node(G._first_node) { }
4.395 + public:
4.396 + NodeIt() : Node() { }
4.397 + NodeIt(const Invalid& i) : Node(i) { }
4.398 + protected:
4.399 + NodeIt(node_item* v) : Node(v) { }
4.400 + NodeIt& operator++() { node=node->_next_node; return *this; }
4.401 + //FIXME::
4.402 + // NodeIt& operator=(const Node& e)
4.403 + // { node=e.node; return *this; }
4.404 + };
4.405 +
4.406 + class Edge {
4.407 + friend class ListGraph;
4.408 + template <typename T> friend class EdgeMap;
4.409 +
4.410 + friend class Node;
4.411 + friend class NodeIt;
4.412 + protected:
4.413 + edge_item* edge;
4.414 + friend int ListGraph::id(Edge e) const;
4.415 + public:
4.416 + Edge() /*: edge(0)*/ { }
4.417 + Edge(const Invalid&) : edge(0) { }
4.418 + //Edge() { }
4.419 + protected:
4.420 + Edge(edge_item* _edge) : edge(_edge) { }
4.421 + bool valid() const { return (edge); }
4.422 + public:
4.423 + //void makeInvalid() { edge=0; }
4.424 + friend bool operator==(Edge u, Edge v) { return v.edge==u.edge; }
4.425 + friend bool operator!=(Edge u, Edge v) { return v.edge!=u.edge; }
4.426 + protected:
4.427 + Node tailNode() const { return Node(edge->_tail); }
4.428 + Node headNode() const { return Node(edge->_head); }
4.429 + public:
4.430 + friend std::ostream& operator<<(std::ostream& os, const Edge& i);
4.431 + };
4.432 +
4.433 + class EdgeIt : public Edge {
4.434 + friend class ListGraph;
4.435 + //protected:
4.436 + public: //for alpar
4.437 + EdgeIt(const ListGraph& G) {
4.438 + node_item* v=G._first_node;
4.439 + if (v) edge=v->_first_out_edge; else edge=0;
4.440 + while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
4.441 + }
4.442 + public:
4.443 + EdgeIt() : Edge() { }
4.444 + EdgeIt(const Invalid& i) : Edge(i) { }
4.445 + protected:
4.446 + EdgeIt(edge_item* _e) : Edge(_e) { }
4.447 + EdgeIt& operator++() {
4.448 + node_item* v=edge->_tail;
4.449 + edge=edge->_next_out;
4.450 + while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
4.451 + return *this;
4.452 + }
4.453 + };
4.454 +
4.455 + class OutEdgeIt : public Edge {
4.456 + friend class ListGraph;
4.457 + //node_item* v;
4.458 + //protected:
4.459 + protected: //for alpar
4.460 + OutEdgeIt(const Node& _v) /*: v(_v.node)*/ { edge=_v.node->_first_out_edge; }
4.461 + public:
4.462 + OutEdgeIt() : Edge()/*, v(0)*/ { }
4.463 + OutEdgeIt(const Invalid& i) : Edge(i) { }
4.464 + OutEdgeIt(const ListGraph&, Node _v) /*: v(_v.node)*/ { edge=_v.node->_first_out_edge; }
4.465 + protected:
4.466 + OutEdgeIt& operator++() { edge=edge->_next_out; return *this; }
4.467 + protected:
4.468 + Node aNode() const { return Node(edge->_tail); }
4.469 + Node bNode() const { return Node(edge->_head); }
4.470 + };
4.471 +
4.472 + class InEdgeIt : public Edge {
4.473 + friend class ListGraph;
4.474 + //node_item* v;
4.475 + //protected:
4.476 + protected: //for alpar
4.477 + InEdgeIt(const Node& _v) /*: v(_v.node)*/ { edge=_v.node->_first_in_edge; }
4.478 + public:
4.479 + InEdgeIt() : Edge()/*, v(0)*/ { }
4.480 + InEdgeIt(const Invalid& i) : Edge(i) { }
4.481 + InEdgeIt(const ListGraph&, Node _v) /*: v(_v.node)*/ { edge=_v.node->_first_in_edge; }
4.482 + protected:
4.483 + InEdgeIt& operator++() { edge=edge->_next_in; return *this; }
4.484 + protected:
4.485 + Node aNode() const { return Node(edge->_head); }
4.486 + Node bNode() const { return Node(edge->_tail); }
4.487 + };
4.488 +
4.489 + class SymEdgeIt : public Edge {
4.490 + friend class ListGraph;
4.491 + bool out_or_in; //1 iff out, 0 iff in
4.492 + //node_item* v;
4.493 + //protected:
4.494 + public: //for alpar
4.495 + SymEdgeIt(const Node& _v) /*: v(_v.node)*/ {
4.496 + out_or_in=1;
4.497 + edge=_v.node->_first_out_edge;
4.498 + if (!edge) { edge=_v.node->_first_in_edge; out_or_in=0; }
4.499 + }
4.500 + public:
4.501 + SymEdgeIt() : Edge() /*, v(0)*/ { }
4.502 + SymEdgeIt(const Invalid& i) : Edge(i) { }
4.503 + SymEdgeIt(const ListGraph&, Node _v) /*: v(_v.node)*/ {
4.504 + out_or_in=1;
4.505 + edge=_v.node->_first_out_edge;
4.506 + if (!edge) { edge=_v.node->_first_in_edge; out_or_in=0; }
4.507 + }
4.508 + protected:
4.509 + SymEdgeIt& operator++() {
4.510 + if (out_or_in) {
4.511 + node_item* v=edge->_tail;
4.512 + edge=edge->_next_out;
4.513 + if (!edge) { out_or_in=0; edge=v->_first_in_edge; }
4.514 + } else {
4.515 + edge=edge->_next_in;
4.516 + }
4.517 + return *this;
4.518 + }
4.519 + protected:
4.520 + Node aNode() const {
4.521 + return (out_or_in) ? Node(edge->_tail) : Node(edge->_head); }
4.522 + Node bNode() const {
4.523 + return (out_or_in) ? Node(edge->_head) : Node(edge->_tail); }
4.524 + };
4.525 +
4.526 + };
4.527 +
4.528 +// template< typename T >
4.529 +// T ListGraph::first() const {
4.530 +// std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>();" << std::endl;
4.531 +// return T();
4.532 +// }
4.533 +
4.534 +// template<>
4.535 +// ListGraph::NodeIt ListGraph::first<ListGraph::NodeIt>() const {
4.536 +// return firstNode();
4.537 +// }
4.538 +
4.539 +// template<>
4.540 +// ListGraph::EdgeIt ListGraph::first<ListGraph::EdgeIt>() const {
4.541 +// return firstEdge();
4.542 +// }
4.543 +
4.544 +// template< typename T >
4.545 +// T ListGraph::first(ListGraph::Node v) const {
4.546 +// std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>(ListGRaph::Node);" << std::endl;
4.547 +// return T();
4.548 +// }
4.549 +
4.550 +// template<>
4.551 +// ListGraph::OutEdgeIt ListGraph::first<ListGraph::OutEdgeIt>(const ListGraph::Node v) const {
4.552 +// return firstOutEdge(v);
4.553 +// }
4.554 +
4.555 +// template<>
4.556 +// ListGraph::InEdgeIt ListGraph::first<ListGraph::InEdgeIt>(const ListGraph::Node v) const {
4.557 +// return firstInEdge(v);
4.558 +// }
4.559 +
4.560 +// template<>
4.561 +// ListGraph::SymEdgeIt ListGraph::first<ListGraph::SymEdgeIt>(const ListGraph::Node v) const {
4.562 +// return firstSymEdge(v);
4.563 +// }
4.564 +
4.565 +
4.566 +} //namespace hugo
4.567 +
4.568 +#endif //HUGO_LIST_GRAPH_H
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/src/work/deba/vector_edge_map.h Mon Mar 29 21:43:27 2004 +0000
5.3 @@ -0,0 +1,29 @@
5.4 +#ifndef VECTOR_EDGE_MAP_H
5.5 +#define VECTOR_EDGE_MAP_H
5.6 +
5.7 +#include <vector>
5.8 +
5.9 +#include "edge_map_base.h"
5.10 +
5.11 +template <typename G, typename E, typename V>
5.12 +class VectorEdgeMap : public EdgeMapBase<G, E>{
5.13 +public:
5.14 + typedef V ValueType;
5.15 +
5.16 + VectorEdgeMap(Graph& g) : EdgeMapBase<G, E>(g) {}
5.17 +
5.18 + void add(const E& edge) {
5.19 + if (edge->id >= container.size()) {
5.20 + container.resize(edge->id);
5.21 + }
5.22 + }
5.23 +
5.24 + void erase(const E&) {}
5.25 +
5.26 +private:
5.27 + typedef vector<ValueType> Container;
5.28 +
5.29 + Container container;
5.30 +}
5.31 +
5.32 +#endif
5.33 \ No newline at end of file