82 int _edge_num; |
82 int _edge_num; |
83 |
83 |
84 node_item* _first_node; |
84 node_item* _first_node; |
85 node_item* _last_node; |
85 node_item* _last_node; |
86 |
86 |
87 class node_item { |
87 struct node_item { |
88 friend class ListGraph; |
|
89 template <typename T> friend class NodeMap; |
|
90 |
|
91 friend class Node; |
|
92 friend class NodeIt; |
|
93 friend class Edge; |
|
94 friend class EdgeIt; |
|
95 friend class OutEdgeIt; |
|
96 friend class InEdgeIt; |
|
97 friend class SymEdgeIt; |
|
98 friend std::ostream& operator<<(std::ostream& os, const Node& i); |
|
99 friend std::ostream& operator<<(std::ostream& os, const Edge& i); |
|
100 //ListGraph* G; |
|
101 int id; |
88 int id; |
102 edge_item* _first_out_edge; |
89 edge_item* _first_out_edge; |
103 edge_item* _last_out_edge; |
90 edge_item* _last_out_edge; |
104 edge_item* _first_in_edge; |
91 edge_item* _first_in_edge; |
105 edge_item* _last_in_edge; |
92 edge_item* _last_in_edge; |
106 node_item* _next_node; |
93 node_item* _next_node; |
107 node_item* _prev_node; |
94 node_item* _prev_node; |
108 public: |
95 }; |
109 node_item() { } |
96 |
110 }; |
97 struct edge_item { |
111 |
|
112 class edge_item { |
|
113 friend class ListGraph; |
|
114 template <typename T> friend class EdgeMap; |
|
115 |
|
116 friend class Node; |
|
117 friend class NodeIt; |
|
118 friend class Edge; |
|
119 friend class EdgeIt; |
|
120 friend class OutEdgeIt; |
|
121 friend class InEdgeIt; |
|
122 friend class SymEdgeIt; |
|
123 friend std::ostream& operator<<(std::ostream& os, const Edge& i); |
|
124 //ListGraph* G; |
|
125 int id; |
98 int id; |
126 node_item* _tail; |
99 node_item* _tail; |
127 node_item* _head; |
100 node_item* _head; |
128 edge_item* _next_out; |
101 edge_item* _next_out; |
129 edge_item* _prev_out; |
102 edge_item* _prev_out; |
130 edge_item* _next_in; |
103 edge_item* _next_in; |
131 edge_item* _prev_in; |
104 edge_item* _prev_in; |
132 public: |
|
133 edge_item() { } |
|
134 }; |
105 }; |
135 |
106 |
136 node_item* _add_node() { |
107 node_item* _add_node() { |
137 node_item* p=new node_item; |
108 node_item* p=new node_item; |
138 p->id=node_id++; |
109 p->id=node_id++; |
544 Node bNode() const { |
515 Node bNode() const { |
545 return (out_or_in) ? Node(edge->_head) : Node(edge->_tail); } |
516 return (out_or_in) ? Node(edge->_head) : Node(edge->_tail); } |
546 }; |
517 }; |
547 }; |
518 }; |
548 |
519 |
|
520 inline |
549 std::ostream& operator<<(std::ostream& os, const ListGraph::Node& i) { |
521 std::ostream& operator<<(std::ostream& os, const ListGraph::Node& i) { |
550 if (i.valid()) |
522 if (i.valid()) |
551 os << i.node->id; |
523 os << i.node->id; |
552 else |
524 else |
553 os << "invalid"; |
525 os << "invalid"; |
554 return os; |
526 return os; |
555 } |
527 } |
|
528 |
|
529 inline |
556 std::ostream& operator<<(std::ostream& os, const ListGraph::Edge& i) { |
530 std::ostream& operator<<(std::ostream& os, const ListGraph::Edge& i) { |
557 if (i.valid()) |
531 if (i.valid()) |
558 os << "(" << i.edge->_tail->id << "--" << i.edge->id << "->" << i.edge->_head->id << ")"; |
532 os << "(" << i.tailNode() << "--" << i.edge->id << "->" |
|
533 << i.headNode() << ")"; |
559 else |
534 else |
560 os << "invalid"; |
535 os << "invalid"; |
561 return os; |
536 return os; |
562 } |
537 } |
563 |
538 |