Skip to content

Commit

Permalink
Sort overrides list for faster searching later on.
Browse files Browse the repository at this point in the history
  • Loading branch information
danpat committed Nov 17, 2017
1 parent 4a90e40 commit 72220ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
24 changes: 18 additions & 6 deletions include/engine/datafacade/contiguous_internalmem_datafacade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,12 +903,24 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
GetOverridesThatStartAt(const NodeID edge_based_node_id) const override final
{
std::vector<extractor::ManeuverOverride> results;
std::copy_if(m_maneuver_overrides.begin(),
m_maneuver_overrides.end(),
std::back_inserter(results),
[edge_based_node_id](auto & override) {
return override.from_node == edge_based_node_id;
});
// m_maneuver_overrides is a vector sorted by from_node, and there can be
// several entries for a given from_node
auto found = std::find_first(
m_maneuver_overrides.begin(), m_maneuver_overrides.end(), edge_based_node_id);

if (found != m_maneuver_overrides.end())
{
results.push_back(*found);
++found;

// Look at subsequent entries to see if they're the same
// from_node
while (found != m_maneuver_overrides.end() && found->from_node == edge_based_node_id)
{
results.push_back(*first);
++found;
}
}

This comment has been minimized.

Copy link
@daniel-j-h

daniel-j-h Nov 20, 2017

Member

You probably want equal_range?

return results;
}
};
Expand Down
7 changes: 6 additions & 1 deletion src/extractor/edge_based_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,13 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
}
}
{
util::Log() << "Writing " << renumbered_maneuver_overrides.size()
util::Log() << "Sorting and writing " << renumbered_maneuver_overrides.size()
<< " maneuver overrides...";

// Sort by `from_node`, so that later lookups can be done with a binary search.
std::sort(renumbered_maneuver_overrides.begin(),
renumbered_maneuver_overrides.end(),
[](const auto &a, const auto &b) { return a.from_node < b.from_node; });
// write conditional turn penalties into the restrictions file
storage::io::FileWriter writer(maneuver_overrides_filename,
storage::io::FileWriter::GenerateFingerprint);
Expand Down

0 comments on commit 72220ed

Please sign in to comment.