Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
edge.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file edge.cpp
1 /* This software is distributed under the GNU Lesser General Public License */
2 //==========================================================================
3 //
4 // edge.cpp
5 //
6 //==========================================================================
7 // $Id: edge.cpp,v 1.17 2001/11/07 13:58:09 pick Exp $
8 
9 #include <GTL/node_data.h>
10 #include <GTL/edge_data.h>
11 #include <cassert>
12 #include <iostream>
13 
14 #ifdef __GTL_MSVCC
15 # ifdef _DEBUG
16 # ifndef SEARCH_MEMORY_LEAKS_ENABLED
17 # error SEARCH NOT ENABLED
18 # endif
19 # define new DEBUG_NEW
20 # undef THIS_FILE
21  static char THIS_FILE[] = __FILE__;
22 # endif // _DEBUG
23 #endif // __GTL_MSVCC
24 
26 
27 //--------------------------------------------------------------------------
28 // edge
29 //--------------------------------------------------------------------------
30 
32  data(0)
33 {
34 }
35 
36 GTL_EXTERN ostream& operator<< (ostream& os, const edge& e) {
37  if (e != edge ()) {
38  return os << e.source() << "-->" << e.target();
39  } else {
40  return os << "UNDEF";
41  }
42 }
43 
45 {
46  return data->nodes[0].front();
47 }
48 
50 {
51  return data->nodes[1].front();
52 }
53 
54 void edge::change_source (node new_source) {
55  //
56  // First delete this edge from source's adjacency list
57  // and clear the list of sources
58  //
59 
60  list<node>::iterator the_nodes = data->nodes[0].begin();
61  list<node>::iterator the_nodes_end = data->nodes[0].end();
62 
63  while(the_nodes != the_nodes_end)
64  {
65  (*the_nodes).data->edges[1].erase (data->adj_pos[0].front());
66  data->adj_pos[0].pop_front();
67 
68  the_nodes = data->nodes[0].erase (the_nodes);
69  }
70 
71  //
72  // Just to be sure :)
73  //
74 
75  assert (data->nodes[0].empty());
76  assert (data->adj_pos[0].empty());
77 
78  //
79  // insert this edge in the list of outgoing edges of new_source
80  //
81 
82  data->adj_pos[0].push_back(new_source.data->edges[1].insert (
83  new_source.data->edges[1].end(), *this));
84 
85  //
86  // make new_source a source of this node.
87  //
88 
89  data->nodes[0].push_back (new_source);
90 }
91 
92 
93 void edge::change_target (node new_target) {
94  //
95  // First delete this edge from target's adjacency list
96  // and clear the list of targets
97  //
98 
99  list<node>::iterator the_nodes = data->nodes[1].begin();
100  list<node>::iterator the_nodes_end = data->nodes[1].end();
101 
102  while(the_nodes != the_nodes_end)
103  {
104  (*the_nodes).data->edges[0].erase (data->adj_pos[1].front());
105  data->adj_pos[1].pop_front();
106 
107  the_nodes = data->nodes[1].erase (the_nodes);
108  }
109 
110  //
111  // Just to be sure :)
112  //
113 
114  assert (data->nodes[1].empty());
115  assert (data->adj_pos[1].empty());
116 
117  //
118  // insert this edge in the list of incoming edges of new_target
119  //
120 
121  data->adj_pos[1].push_back(new_target.data->edges[0].insert (
122  new_target.data->edges[0].end(), *this));
123 
124  //
125  // make new_target a target of this node.
126  //
127 
128  data->nodes[1].push_back (new_target);
129 }
130 
131 
133 {
134  //
135  // First delete this edge from all adjacency lists
136  //
137 
138  list<node>::iterator the_nodes = data->nodes[0].begin();
139  list<node>::iterator the_nodes_end = data->nodes[0].end();
140 
141  while(the_nodes != the_nodes_end)
142  {
143  (*the_nodes).data->edges[1].erase (data->adj_pos[0].front());
144  data->adj_pos[0].pop_front();
145 
146  ++the_nodes;
147  }
148 
149  the_nodes = data->nodes[1].begin();
150  the_nodes_end = data->nodes[1].end();
151 
152  while(the_nodes != the_nodes_end)
153  {
154  (*the_nodes).data->edges[0].erase (data->adj_pos[1].front());
155  data->adj_pos[1].pop_front();
156 
157  ++the_nodes;
158  }
159 
160  //
161  // Now the lists of positions in the adjacency - lists should be empty
162  //
163 
164  assert (data->adj_pos[0].empty());
165  assert (data->adj_pos[1].empty());
166 
167  //
168  // Now insert this edge reversed
169  //
170 
171  the_nodes = data->nodes[1].begin();
172  the_nodes_end = data->nodes[1].end();
173 
174  while(the_nodes != the_nodes_end)
175  {
176  data->adj_pos[0].push_back((*the_nodes).data->edges[1].insert (
177  (*the_nodes).data->edges[1].end(), *this));
178 
179  ++the_nodes;
180  }
181 
182  the_nodes = data->nodes[0].begin();
183  the_nodes_end = data->nodes[0].end();
184 
185  while(the_nodes != the_nodes_end)
186  {
187  data->adj_pos[1].push_back((*the_nodes).data->edges[0].insert (
188  (*the_nodes).data->edges[0].end(), *this));
189 
190  ++the_nodes;
191  }
192 
193  //
194  // swap nodes[0] and nodes[1]
195  //
196 
197  list<node> tmp = data->nodes[0];
198  data->nodes[0] = data->nodes[1];
199  data->nodes[1] = tmp;
200 }
201 
202 
203 
204 list<node> edge::sources() const
205 {
206  return data->nodes[0];
207 }
208 
209 list<node> edge::targets() const
210 {
211  return data->nodes[1];
212 }
213 
214 int edge::id() const
215 {
216  return data->id;
217 }
218 
219 bool edge::is_hidden () const
220 {
221  return data->hidden;
222 }
223 
224 void edge::remove_from(int where) const
225 {
226  list<node>::iterator the_nodes = data->nodes[where].begin();
227  list<node>::iterator the_nodes_end = data->nodes[where].end();
228 
229  list<list<edge>::iterator>::iterator the_adj_pos =
230  data->adj_pos[where].begin();
231 
232  while(the_nodes != the_nodes_end)
233  {
234  the_nodes->data->edges[1-where].erase(*the_adj_pos);
235 
236  ++the_nodes;
237  ++the_adj_pos;
238  }
239 }
240 
241 const node& edge::opposite(node n) const
242 {
243  // not implemented for hypergraphs
244  assert(data);
245 
246  node& s = *(data->nodes[0].begin());
247  if (n == s)
248  return *(data->nodes[1].begin());
249  else
250  return s;
251 }
252 
254 {
255  return e1.data == e2.data;
256 }
257 
259 {
260  return e1.data != e2.data;
261 }
262 
264 {
265  return e1.data < e2.data;
266 }
267 
269 
270 //--------------------------------------------------------------------------
271 // end of file
272 //--------------------------------------------------------------------------