|
9 | 9 |
|
10 | 10 | HGEdge::HGEdge(HighwaySegment *s) |
11 | 11 | { // initial construction is based on a HighwaySegment |
12 | | - written = new char[Args::numthreads]; |
13 | | - // deleted by HGEdge::detach |
14 | | - // we only need to initialize the first element, for master graphs. |
15 | | - // the rest will get zeroed out for each subgraph set. |
16 | | - written[0] = 0; |
17 | 12 | vertex1 = s->waypoint1->hashpoint()->vertex; |
18 | 13 | vertex2 = s->waypoint2->hashpoint()->vertex; |
19 | 14 | format = simple | collapsed | traveled; |
20 | 15 | segment_name = s->segment_name(); |
21 | | - vertex1->incident_s_edges.push_back(this); |
22 | | - vertex2->incident_s_edges.push_back(this); |
23 | | - vertex1->incident_c_edges.push_back(this); |
24 | | - vertex2->incident_c_edges.push_back(this); |
25 | | - vertex1->incident_t_edges.push_back(this); |
26 | | - vertex2->incident_t_edges.push_back(this); |
| 16 | + vertex1->incident_edges.push_back(this); |
| 17 | + vertex2->incident_edges.push_back(this); |
| 18 | + vertex1->edge_count++; |
| 19 | + vertex2->edge_count++; |
27 | 20 | // canonical segment, used to reference region and list of travelers |
28 | 21 | // assumption: each edge/segment lives within a unique region |
29 | 22 | // and a 'multi-edge' would not be able to span regions as there |
30 | 23 | // would be a required visible waypoint at the border |
31 | 24 | segment = s; |
32 | 25 | } |
33 | 26 |
|
34 | | -HGEdge::HGEdge(HGVertex *vertex, unsigned char fmt_mask) |
| 27 | +HGEdge::HGEdge(HGVertex *vertex, int& deletions, unsigned char fmt_mask, HGEdge *e1, HGEdge *e2) |
35 | 28 | { // build by collapsing two existing edges around a common hidden vertex |
36 | | - written = new char[Args::numthreads]; |
37 | | - // deleted by HGEdge::detach |
38 | | - written[0] = 0; |
39 | 29 | format = fmt_mask; |
40 | | - // we know there are exactly 2 incident edges, as we |
41 | | - // checked for that, and we will replace these two |
42 | | - // with the single edge we are constructing here... |
43 | | - HGEdge *edge1 = 0; |
44 | | - HGEdge *edge2 = 0; |
45 | | - if (fmt_mask & collapsed) |
46 | | - { // ...in the compressed graph, and/or... |
47 | | - edge1 = vertex->incident_c_edges.front(); |
48 | | - edge2 = vertex->incident_c_edges.back(); |
49 | | - } |
50 | | - if (fmt_mask & traveled) |
51 | | - { // ...in the traveled graph, as appropriate |
52 | | - edge1 = vertex->incident_t_edges.front(); |
53 | | - edge2 = vertex->incident_t_edges.back(); |
54 | | - } |
| 30 | + HGEdge *edge1 = e1; |
| 31 | + HGEdge *edge2 = e2; |
55 | 32 | // segment names should match as routes should not start or end |
56 | 33 | // nor should concurrencies begin or end at a hidden point |
57 | 34 | if (edge1->segment_name != edge2->segment_name) |
@@ -103,46 +80,29 @@ HGEdge::HGEdge(HGVertex *vertex, unsigned char fmt_mask) |
103 | 80 | intermediate_point_string() << " to " << *(vertex2->unique_name) << std::endl; |
104 | 81 | //std::cout << "DEBUG: new " << str() << std::endl; |
105 | 82 |
|
| 83 | + // clear format bits of old edges |
| 84 | + // anything with a format of 0 won't be moved to the graph, and |
| 85 | + // will be destroyed when the temp_edges container exits scope |
| 86 | + edge1->format &= ~fmt_mask; |
| 87 | + edge2->format &= ~fmt_mask; |
106 | 88 | // replace edge references at our endpoints with ourself |
107 | | - edge1->detach(fmt_mask); |
108 | | - edge2->detach(fmt_mask); |
109 | | - if (fmt_mask & collapsed) |
110 | | - { vertex1->incident_c_edges.push_back(this); |
111 | | - vertex2->incident_c_edges.push_back(this); |
112 | | - } |
113 | | - if (fmt_mask & traveled) |
114 | | - { vertex1->incident_t_edges.push_back(this); |
115 | | - vertex2->incident_t_edges.push_back(this); |
116 | | - } |
| 89 | + if (!edge1->format) {edge1->detach(); deletions++;} |
| 90 | + if (!edge2->format) {edge2->detach(); deletions++;} |
| 91 | + vertex1->incident_edges.push_back(this); |
| 92 | + vertex2->incident_edges.push_back(this); |
117 | 93 | } |
118 | 94 |
|
119 | | -void HGEdge::detach() {return detach(format);} |
120 | | -void HGEdge::detach(unsigned char fmt_mask) |
| 95 | +void HGEdge::detach() |
121 | 96 | { // detach edge from vertices in graph(s) specified in fmt_mask |
122 | | - #define DETACH(v) \ |
123 | | - for (std::list<HGEdge*>::iterator e = v.begin(); e != v.end(); e++) \ |
| 97 | + auto detach = [&](std::vector<HGEdge*>& v) \ |
| 98 | + { for (std::vector<HGEdge*>::iterator e = v.begin(); e != v.end(); e++) \ |
124 | 99 | if (*e == this) \ |
125 | 100 | { v.erase(e); \ |
126 | 101 | break; \ |
127 | 102 | } |
128 | | - if (fmt_mask & simple) |
129 | | - { DETACH(vertex1->incident_s_edges) |
130 | | - DETACH(vertex2->incident_s_edges) |
131 | | - } |
132 | | - if (fmt_mask & collapsed) |
133 | | - { DETACH(vertex1->incident_c_edges) |
134 | | - DETACH(vertex2->incident_c_edges) |
135 | | - } |
136 | | - if (fmt_mask & traveled) |
137 | | - { DETACH(vertex1->incident_t_edges) |
138 | | - DETACH(vertex2->incident_t_edges) |
139 | | - } |
140 | | - #undef DETACH |
141 | | - format &= ~fmt_mask; |
142 | | - if (!format) |
143 | | - { delete[] written; |
144 | | - delete this; |
145 | | - } |
| 103 | + }; |
| 104 | + detach(vertex1->incident_edges); |
| 105 | + detach(vertex2->incident_edges); |
146 | 106 | } |
147 | 107 |
|
148 | 108 | // write line to tmg collapsed edge file |
|
0 commit comments