Changeset 986:e997802b855c in lemon-0.x for src/work/marci/experiment/list_graph.h
- Timestamp:
- 11/13/04 13:53:28 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1376
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/marci/experiment/list_graph.h
r921 r986 123 123 //ListGraph* G; 124 124 int id; 125 node_item* _ tail;126 node_item* _ head;125 node_item* _source; 126 node_item* _target; 127 127 edge_item* _next_out; 128 128 edge_item* _prev_out; … … 150 150 } 151 151 152 edge_item* _add_edge(node_item* _ tail, node_item* _head) {152 edge_item* _add_edge(node_item* _source, node_item* _target) { 153 153 edge_item* e=new edge_item; 154 154 e->id=edge_id++; 155 e->_ tail=_tail;156 e->_ head=_head;157 158 e->_prev_out=_ tail->_last_out_edge;159 if (_ tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;160 _ tail->_last_out_edge=e;161 if (!_ tail->_first_out_edge) _tail->_first_out_edge=e;155 e->_source=_source; 156 e->_target=_target; 157 158 e->_prev_out=_source->_last_out_edge; 159 if (_source->_last_out_edge) (_source->_last_out_edge)->_next_out=e; 160 _source->_last_out_edge=e; 161 if (!_source->_first_out_edge) _source->_first_out_edge=e; 162 162 e->_next_out=0; 163 163 164 e->_prev_in=_ head->_last_in_edge;165 if (_ head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;166 _ head->_last_in_edge=e;167 if (!_ head->_first_in_edge) { _head->_first_in_edge=e; }164 e->_prev_in=_target->_last_in_edge; 165 if (_target->_last_in_edge) (_target->_last_in_edge)->_next_in=e; 166 _target->_last_in_edge=e; 167 if (!_target->_first_in_edge) { _target->_first_in_edge=e; } 168 168 e->_next_in=0; 169 169 … … 185 185 void _delete_edge(edge_item* e) { 186 186 if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else 187 (e->_ tail)->_last_out_edge=e->_prev_out;187 (e->_source)->_last_out_edge=e->_prev_out; 188 188 if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else 189 (e->_ tail)->_first_out_edge=e->_next_out;189 (e->_source)->_first_out_edge=e->_next_out; 190 190 if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else 191 (e->_ head)->_last_in_edge=e->_prev_in;191 (e->_target)->_last_in_edge=e->_prev_in; 192 192 if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else 193 (e->_ head)->_first_in_edge=e->_next_in;193 (e->_target)->_first_in_edge=e->_next_in; 194 194 195 195 delete e; … … 197 197 } 198 198 199 void _set_ tail(edge_item* e, node_item* _tail) {199 void _set_source(edge_item* e, node_item* _source) { 200 200 if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else 201 (e->_ tail)->_last_out_edge=e->_prev_out;201 (e->_source)->_last_out_edge=e->_prev_out; 202 202 if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else 203 (e->_ tail)->_first_out_edge=e->_next_out;204 205 e->_ tail=_tail;206 207 e->_prev_out=_ tail->_last_out_edge;208 if (_ tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;209 _ tail->_last_out_edge=e;210 if (!_ tail->_first_out_edge) _tail->_first_out_edge=e;203 (e->_source)->_first_out_edge=e->_next_out; 204 205 e->_source=_source; 206 207 e->_prev_out=_source->_last_out_edge; 208 if (_source->_last_out_edge) (_source->_last_out_edge)->_next_out=e; 209 _source->_last_out_edge=e; 210 if (!_source->_first_out_edge) _source->_first_out_edge=e; 211 211 e->_next_out=0; 212 212 } 213 213 214 void _set_ head(edge_item* e, node_item* _head) {214 void _set_target(edge_item* e, node_item* _target) { 215 215 if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else 216 (e->_ head)->_last_in_edge=e->_prev_in;216 (e->_target)->_last_in_edge=e->_prev_in; 217 217 if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else 218 (e->_ head)->_first_in_edge=e->_next_in;219 220 e->_ head=_head;221 222 e->_prev_in=_ head->_last_in_edge;223 if (_ head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;224 _ head->_last_in_edge=e;225 if (!_ head->_first_in_edge) { _head->_first_in_edge=e; }218 (e->_target)->_first_in_edge=e->_next_in; 219 220 e->_target=_target; 221 222 e->_prev_in=_target->_last_in_edge; 223 if (_target->_last_in_edge) (_target->_last_in_edge)->_next_in=e; 224 _target->_last_in_edge=e; 225 if (!_target->_first_in_edge) { _target->_first_in_edge=e; } 226 226 e->_next_in=0; 227 227 } … … 248 248 //InEdgeIt firstInEdge(const Node v) const { return InEdgeIt(v); } 249 249 //SymEdgeIt firstSymEdge(const Node v) const { return SymEdgeIt(v); } 250 Node tail(Edge e) const { return e.tailNode(); }251 Node head(Edge e) const { return e.headNode(); }250 Node source(Edge e) const { return e.sourceNode(); } 251 Node target(Edge e) const { return e.targetNode(); } 252 252 253 253 Node aNode(const OutEdgeIt& e) const { return e.aNode(); } … … 278 278 SymEdgeIt& /*getF*/first(SymEdgeIt& e, Node v) const { 279 279 e=SymEdgeIt(*this, v); return e; } 280 //void get Tail(Node& n, const Edge& e) const { n=tail(e); }281 //void get Head(Node& n, const Edge& e) const { n=head(e); }280 //void getSource(Node& n, const Edge& e) const { n=source(e); } 281 //void getTarget(Node& n, const Edge& e) const { n=target(e); } 282 282 283 283 //void getANode(Node& n, const OutEdgeIt& e) const { n=e.aNode(); } … … 346 346 } 347 347 348 void set Tail(Edge e, Node tail) {349 _set_ tail(e.edge, tail.node);350 } 351 352 void set Head(Edge e, Node head) {353 _set_ head(e.edge, head.node);348 void setSource(Edge e, Node source) { 349 _set_source(e.edge, source.node); 350 } 351 352 void setTarget(Edge e, Node target) { 353 _set_target(e.edge, target.node); 354 354 } 355 355 … … 360 360 } 361 361 friend std::ostream& operator<<(std::ostream& os, const Edge& i) { 362 os << "(" << i.edge->_ tail->id << "--" << i.edge->id << "->" << i.edge->_head->id << ")";362 os << "(" << i.edge->_source->id << "--" << i.edge->id << "->" << i.edge->_target->id << ")"; 363 363 return os; 364 364 } … … 427 427 friend bool operator!=(Edge u, Edge v) { return v.edge!=u.edge; } 428 428 protected: 429 Node tailNode() const { return Node(edge->_tail); }430 Node headNode() const { return Node(edge->_head); }429 Node sourceNode() const { return Node(edge->_source); } 430 Node targetNode() const { return Node(edge->_target); } 431 431 public: 432 432 friend std::ostream& operator<<(std::ostream& os, const Edge& i); … … 448 448 EdgeIt(edge_item* _e) : Edge(_e) { } 449 449 EdgeIt& operator++() { 450 node_item* v=edge->_ tail;450 node_item* v=edge->_source; 451 451 edge=edge->_next_out; 452 452 while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; } … … 468 468 OutEdgeIt& operator++() { edge=edge->_next_out; return *this; } 469 469 protected: 470 Node aNode() const { return Node(edge->_ tail); }471 Node bNode() const { return Node(edge->_ head); }470 Node aNode() const { return Node(edge->_source); } 471 Node bNode() const { return Node(edge->_target); } 472 472 }; 473 473 … … 485 485 InEdgeIt& operator++() { edge=edge->_next_in; return *this; } 486 486 protected: 487 Node aNode() const { return Node(edge->_ head); }488 Node bNode() const { return Node(edge->_ tail); }487 Node aNode() const { return Node(edge->_target); } 488 Node bNode() const { return Node(edge->_source); } 489 489 }; 490 490 … … 511 511 SymEdgeIt& operator++() { 512 512 if (out_or_in) { 513 node_item* v=edge->_ tail;513 node_item* v=edge->_source; 514 514 edge=edge->_next_out; 515 515 if (!edge) { out_or_in=0; edge=v->_first_in_edge; } … … 521 521 protected: 522 522 Node aNode() const { 523 return (out_or_in) ? Node(edge->_ tail) : Node(edge->_head); }523 return (out_or_in) ? Node(edge->_source) : Node(edge->_target); } 524 524 Node bNode() const { 525 return (out_or_in) ? Node(edge->_ head) : Node(edge->_tail); }525 return (out_or_in) ? Node(edge->_target) : Node(edge->_source); } 526 526 }; 527 527
Note: See TracChangeset
for help on using the changeset viewer.