Skip to content

Commit a2cdc06

Browse files
TheMarexkarenzshea
authored andcommitted
Remove superflous sentinel in DynamicGraph, fixes #4738
1 parent 6e06daf commit a2cdc06

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

include/contractor/contracted_edge_container.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct ContractedEdgeContainer
108108
edges.insert(edges.end(), new_edges.begin(), new_end);
109109
auto edges_size = edges.size();
110110
auto new_edges_size = std::distance(new_edges.begin(), new_end);
111-
BOOST_ASSERT(edges_size >= new_edges_size);
111+
BOOST_ASSERT(static_cast<int>(edges_size) >= new_edges_size);
112112
flags.resize(edges_size);
113113
std::fill(flags.begin() + edges_size - new_edges_size, flags.end(), flag);
114114

include/util/dynamic_graph.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ template <typename EdgeDataT> class DynamicGraph
115115

116116
number_of_nodes = nodes;
117117
number_of_edges = static_cast<EdgeIterator>(graph.size());
118-
node_array.resize(number_of_nodes + 1);
118+
node_array.resize(number_of_nodes);
119119
EdgeIterator edge = 0;
120120
EdgeIterator position = 0;
121121
for (const auto node : irange(0u, number_of_nodes))
@@ -129,7 +129,6 @@ template <typename EdgeDataT> class DynamicGraph
129129
node_array[node].edges = edge - last_edge;
130130
position += node_array[node].edges;
131131
}
132-
node_array.back().first_edge = position;
133132
edge_list.reserve(static_cast<std::size_t>(edge_list.size() * 1.1));
134133
edge_list.resize(position);
135134
edge = 0;
@@ -144,6 +143,8 @@ template <typename EdgeDataT> class DynamicGraph
144143
++edge;
145144
}
146145
}
146+
147+
BOOST_ASSERT(node_array.size() == number_of_nodes);
147148
}
148149

149150
// Copy&move for the same data
@@ -191,6 +192,8 @@ template <typename EdgeDataT> class DynamicGraph
191192
// Removes all edges to and from nodes for which filter(node_id) returns false
192193
template <typename Pred> auto Filter(Pred filter) const &
193194
{
195+
BOOST_ASSERT(node_array.size() == number_of_nodes);
196+
194197
DynamicGraph other;
195198

196199
other.number_of_nodes = number_of_nodes;
@@ -202,6 +205,8 @@ template <typename EdgeDataT> class DynamicGraph
202205
std::transform(
203206
node_array.begin(), node_array.end(), other.node_array.begin(), [&](const Node &node) {
204207
const EdgeIterator first_edge = other.edge_list.size();
208+
209+
BOOST_ASSERT(node_id < number_of_nodes);
205210
if (filter(node_id++))
206211
{
207212
std::copy_if(edge_list.begin() + node.first_edge,
@@ -416,7 +421,7 @@ template <typename EdgeDataT> class DynamicGraph
416421
void Renumber(const std::vector<NodeID> &old_to_new_node)
417422
{
418423
// permutate everything but the sentinel
419-
util::inplacePermutation(node_array.begin(), std::prev(node_array.end()), old_to_new_node);
424+
util::inplacePermutation(node_array.begin(), node_array.end(), old_to_new_node);
420425

421426
// Build up edge permutation
422427
auto new_edge_index = 0;

src/contractor/graph_contractor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ void RenumberData(std::vector<RemainingNodeData> &remaining_nodes,
384384
// we need to make a copy here because we are going to modify it
385385
auto to_orig = new_to_old_node_id;
386386

387-
auto new_node_id = 0;
387+
auto new_node_id = 0u;
388388

389389
// All remaining nodes get the low IDs
390390
for (auto &remaining : remaining_nodes)

0 commit comments

Comments
 (0)