Changeset 986:e997802b855c in lemon-0.x for src/work/sage_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/sage_graph.h
r921 r986 97 97 struct edge_item { 98 98 int id; 99 node_item* _ tail;100 node_item* _ head;99 node_item* _source; 100 node_item* _target; 101 101 edge_item* _next_out; 102 102 edge_item* _prev_out; … … 122 122 } 123 123 124 edge_item* _add_edge(node_item* _ tail, node_item* _head) {124 edge_item* _add_edge(node_item* _source, node_item* _target) { 125 125 edge_item* e=new edge_item; 126 126 e->id=edge_id++; 127 e->_ tail=_tail;128 e->_ head=_head;127 e->_source=_source; 128 e->_target=_target; 129 129 130 e->_prev_out=_ tail->_last_out_edge;131 if (_ tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;132 _ tail->_last_out_edge=e;133 if (!_ tail->_first_out_edge) _tail->_first_out_edge=e;130 e->_prev_out=_source->_last_out_edge; 131 if (_source->_last_out_edge) (_source->_last_out_edge)->_next_out=e; 132 _source->_last_out_edge=e; 133 if (!_source->_first_out_edge) _source->_first_out_edge=e; 134 134 e->_next_out=0; 135 135 136 e->_prev_in=_ head->_last_in_edge;137 if (_ head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;138 _ head->_last_in_edge=e;139 if (!_ head->_first_in_edge) { _head->_first_in_edge=e; }136 e->_prev_in=_target->_last_in_edge; 137 if (_target->_last_in_edge) (_target->_last_in_edge)->_next_in=e; 138 _target->_last_in_edge=e; 139 if (!_target->_first_in_edge) { _target->_first_in_edge=e; } 140 140 e->_next_in=0; 141 141 … … 157 157 void _delete_edge(edge_item* e) { 158 158 if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else 159 (e->_ tail)->_last_out_edge=e->_prev_out;159 (e->_source)->_last_out_edge=e->_prev_out; 160 160 if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else 161 (e->_ tail)->_first_out_edge=e->_next_out;161 (e->_source)->_first_out_edge=e->_next_out; 162 162 if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else 163 (e->_ head)->_last_in_edge=e->_prev_in;163 (e->_target)->_last_in_edge=e->_prev_in; 164 164 if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else 165 (e->_ head)->_first_in_edge=e->_next_in;165 (e->_target)->_first_in_edge=e->_next_in; 166 166 167 167 delete e; … … 169 169 } 170 170 171 void _set_ tail(edge_item* e, node_item* _tail) {171 void _set_source(edge_item* e, node_item* _source) { 172 172 if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else 173 (e->_ tail)->_last_out_edge=e->_prev_out;173 (e->_source)->_last_out_edge=e->_prev_out; 174 174 if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else 175 (e->_ tail)->_first_out_edge=e->_next_out;175 (e->_source)->_first_out_edge=e->_next_out; 176 176 177 e->_ tail=_tail;177 e->_source=_source; 178 178 179 e->_prev_out=_ tail->_last_out_edge;180 if (_ tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;181 _ tail->_last_out_edge=e;182 if (!_ tail->_first_out_edge) _tail->_first_out_edge=e;179 e->_prev_out=_source->_last_out_edge; 180 if (_source->_last_out_edge) (_source->_last_out_edge)->_next_out=e; 181 _source->_last_out_edge=e; 182 if (!_source->_first_out_edge) _source->_first_out_edge=e; 183 183 e->_next_out=0; 184 184 } 185 185 186 void _set_ head(edge_item* e, node_item* _head) {186 void _set_target(edge_item* e, node_item* _target) { 187 187 if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else 188 (e->_ head)->_last_in_edge=e->_prev_in;188 (e->_target)->_last_in_edge=e->_prev_in; 189 189 if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else 190 (e->_ head)->_first_in_edge=e->_next_in;190 (e->_target)->_first_in_edge=e->_next_in; 191 191 192 e->_ head=_head;192 e->_target=_target; 193 193 194 e->_prev_in=_ head->_last_in_edge;195 if (_ head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;196 _ head->_last_in_edge=e;197 if (!_ head->_first_in_edge) { _head->_first_in_edge=e; }194 e->_prev_in=_target->_last_in_edge; 195 if (_target->_last_in_edge) (_target->_last_in_edge)->_next_in=e; 196 _target->_last_in_edge=e; 197 if (!_target->_first_in_edge) { _target->_first_in_edge=e; } 198 198 e->_next_in=0; 199 199 } … … 222 222 //InEdgeIt firstInEdge(const Node v) const { return InEdgeIt(v); } 223 223 //SymEdgeIt firstSymEdge(const Node v) const { return SymEdgeIt(v); } 224 Node tail(Edge e) const { return e.tailNode(); }225 Node head(Edge e) const { return e.headNode(); }224 Node source(Edge e) const { return e.sourceNode(); } 225 Node target(Edge e) const { return e.targetNode(); } 226 226 227 227 Node aNode(const OutEdgeIt& e) const { return e.aNode(); } … … 252 252 SymEdgeIt& first(SymEdgeIt& e, Node v) const { 253 253 e=SymEdgeIt(*this, v); return e; } 254 //void get Tail(Node& n, const Edge& e) const { n=tail(e); }255 //void get Head(Node& n, const Edge& e) const { n=head(e); }254 //void getSource(Node& n, const Edge& e) const { n=source(e); } 255 //void getTarget(Node& n, const Edge& e) const { n=target(e); } 256 256 257 257 //void getANode(Node& n, const OutEdgeIt& e) const { n=e.aNode(); } … … 330 330 } 331 331 332 void set Tail(Edge e, Node tail) {333 _set_ tail(e.edge, tail.node);334 } 335 336 void set Head(Edge e, Node head) {337 _set_ head(e.edge, head.node);332 void setSource(Edge e, Node source) { 333 _set_source(e.edge, source.node); 334 } 335 336 void setTarget(Edge e, Node target) { 337 _set_target(e.edge, target.node); 338 338 } 339 339 … … 349 349 // friend std::ostream& operator<<(std::ostream& os, const Edge& i) { 350 350 // if (i.valid()) 351 // os << "(" << i.edge->_ tail->id << "--" << i.edge->id << "->" << i.edge->_head->id << ")";351 // os << "(" << i.edge->_source->id << "--" << i.edge->id << "->" << i.edge->_target->id << ")"; 352 352 // else 353 353 // os << "invalid"; … … 420 420 friend bool operator!=(Edge u, Edge v) { return v.edge!=u.edge; } 421 421 protected: 422 Node tailNode() const { return Node(edge->_tail); }423 Node headNode() const { return Node(edge->_head); }422 Node sourceNode() const { return Node(edge->_source); } 423 Node targetNode() const { return Node(edge->_target); } 424 424 public: 425 425 friend std::ostream& operator<<(std::ostream& os, const Edge& i); … … 441 441 public: 442 442 EdgeIt& operator++() { 443 node_item* v=edge->_ tail;443 node_item* v=edge->_source; 444 444 edge=edge->_next_out; 445 445 while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; } … … 457 457 OutEdgeIt& operator++() { edge=edge->_next_out; return *this; } 458 458 protected: 459 Node aNode() const { return Node(edge->_ tail); }460 Node bNode() const { return Node(edge->_ head); }459 Node aNode() const { return Node(edge->_source); } 460 Node bNode() const { return Node(edge->_target); } 461 461 }; 462 462 … … 470 470 InEdgeIt& operator++() { edge=edge->_next_in; return *this; } 471 471 protected: 472 Node aNode() const { return Node(edge->_ head); }473 Node bNode() const { return Node(edge->_ tail); }472 Node aNode() const { return Node(edge->_target); } 473 Node bNode() const { return Node(edge->_source); } 474 474 }; 475 475 … … 496 496 SymEdgeIt& operator++() { 497 497 if (out_or_in) { 498 node_item* v=edge->_ tail;498 node_item* v=edge->_source; 499 499 edge=edge->_next_out; 500 500 if (!edge) { out_or_in=0; edge=v->_first_in_edge; } … … 506 506 protected: 507 507 Node aNode() const { 508 return (out_or_in) ? Node(edge->_ tail) : Node(edge->_head); }508 return (out_or_in) ? Node(edge->_source) : Node(edge->_target); } 509 509 Node bNode() const { 510 return (out_or_in) ? Node(edge->_ head) : Node(edge->_tail); }510 return (out_or_in) ? Node(edge->_target) : Node(edge->_source); } 511 511 }; 512 512 }; … … 524 524 std::ostream& operator<<(std::ostream& os, const SageGraph::Edge& i) { 525 525 if (i.valid()) 526 os << "(" << i. tailNode() << "--" << i.edge->id << "->"527 << i. headNode() << ")";526 os << "(" << i.sourceNode() << "--" << i.edge->id << "->" 527 << i.targetNode() << ")"; 528 528 else 529 529 os << "invalid";
Note: See TracChangeset
for help on using the changeset viewer.