Use mmap instead of read - it's a lot faster here.
Also clean up construction of STRONG_TYPEDEF so that it can be
packed properly in structs (this explains all the () -> {}) changes
here.
This commit is contained in:
@@ -480,19 +480,17 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
// updates to the edge-expanded-edge based directly on its ID.
|
||||
if (generate_edge_lookup)
|
||||
{
|
||||
unsigned fixed_penalty = distance - edge_data1.distance;
|
||||
edge_penalty_file.write(reinterpret_cast<const char *>(&fixed_penalty),
|
||||
sizeof(fixed_penalty));
|
||||
const auto node_based_edges =
|
||||
m_compressed_edge_container.GetBucketReference(edge_from_u);
|
||||
NodeID previous = node_u;
|
||||
|
||||
const unsigned node_count = node_based_edges.size() + 1;
|
||||
edge_segment_file.write(reinterpret_cast<const char *>(&node_count),
|
||||
sizeof(node_count));
|
||||
const QueryNode &first_node = m_node_info_list[previous];
|
||||
edge_segment_file.write(reinterpret_cast<const char *>(&first_node.node_id),
|
||||
sizeof(first_node.node_id));
|
||||
|
||||
lookup::SegmentHeaderBlock header = {node_count, first_node.node_id};
|
||||
|
||||
edge_segment_file.write(reinterpret_cast<const char *>(&header),
|
||||
sizeof(header));
|
||||
|
||||
for (auto target_node : node_based_edges)
|
||||
{
|
||||
@@ -501,12 +499,11 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
const double segment_length =
|
||||
util::coordinate_calculation::greatCircleDistance(from, to);
|
||||
|
||||
edge_segment_file.write(reinterpret_cast<const char *>(&to.node_id),
|
||||
sizeof(to.node_id));
|
||||
edge_segment_file.write(reinterpret_cast<const char *>(&segment_length),
|
||||
sizeof(segment_length));
|
||||
edge_segment_file.write(reinterpret_cast<const char *>(&target_node.weight),
|
||||
sizeof(target_node.weight));
|
||||
lookup::SegmentBlock nodeblock = {
|
||||
to.node_id, segment_length, target_node.weight};
|
||||
|
||||
edge_segment_file.write(reinterpret_cast<const char *>(&nodeblock),
|
||||
sizeof(nodeblock));
|
||||
previous = target_node.node_id;
|
||||
}
|
||||
|
||||
@@ -533,12 +530,11 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
m_node_info_list[m_compressed_edge_container.GetFirstEdgeTargetID(
|
||||
turn.eid)];
|
||||
|
||||
edge_penalty_file.write(reinterpret_cast<const char *>(&from_node.node_id),
|
||||
sizeof(from_node.node_id));
|
||||
edge_penalty_file.write(reinterpret_cast<const char *>(&via_node.node_id),
|
||||
sizeof(via_node.node_id));
|
||||
edge_penalty_file.write(reinterpret_cast<const char *>(&to_node.node_id),
|
||||
sizeof(to_node.node_id));
|
||||
const unsigned fixed_penalty = distance - edge_data1.distance;
|
||||
lookup::PenaltyBlock penaltyblock = {
|
||||
fixed_penalty, from_node.node_id, via_node.node_id, to_node.node_id};
|
||||
edge_penalty_file.write(reinterpret_cast<const char *>(&penaltyblock),
|
||||
sizeof(penaltyblock));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,9 +344,9 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
|
||||
BOOST_ASSERT(edge_iterator->result.osm_target_id == node_iterator->node_id);
|
||||
BOOST_ASSERT(edge_iterator->weight_data.speed >= 0);
|
||||
BOOST_ASSERT(edge_iterator->source_coordinate.lat !=
|
||||
util::FixedLatitude(std::numeric_limits<int>::min()));
|
||||
util::FixedLatitude{std::numeric_limits<std::int32_t>::min()});
|
||||
BOOST_ASSERT(edge_iterator->source_coordinate.lon !=
|
||||
util::FixedLongitude(std::numeric_limits<int>::min()));
|
||||
util::FixedLongitude{std::numeric_limits<std::int32_t>::min()});
|
||||
|
||||
const double distance = util::coordinate_calculation::greatCircleDistance(
|
||||
edge_iterator->source_coordinate,
|
||||
@@ -652,14 +652,14 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
restrictions_iterator != restrictions_list_end)
|
||||
{
|
||||
if (way_start_and_end_iterator->way_id <
|
||||
OSMWayID(restrictions_iterator->restriction.from.way))
|
||||
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.from.way)})
|
||||
{
|
||||
++way_start_and_end_iterator;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (way_start_and_end_iterator->way_id >
|
||||
OSMWayID(restrictions_iterator->restriction.from.way))
|
||||
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.from.way)})
|
||||
{
|
||||
util::SimpleLogger().Write(LogLevel::logWARNING)
|
||||
<< "Restriction references invalid way: "
|
||||
@@ -670,9 +670,9 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
}
|
||||
|
||||
BOOST_ASSERT(way_start_and_end_iterator->way_id ==
|
||||
OSMWayID(restrictions_iterator->restriction.from.way));
|
||||
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.from.way)});
|
||||
// we do not remap the via id yet, since we will need it for the to node as well
|
||||
const OSMNodeID via_node_id = OSMNodeID(restrictions_iterator->restriction.via.node);
|
||||
const OSMNodeID via_node_id = OSMNodeID{restrictions_iterator->restriction.via.node};
|
||||
|
||||
// check if via is actually valid, if not invalidate
|
||||
auto via_id_iter = external_to_internal_node_id_map.find(via_node_id);
|
||||
@@ -686,11 +686,11 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
continue;
|
||||
}
|
||||
|
||||
if (OSMNodeID(way_start_and_end_iterator->first_segment_source_id) == via_node_id)
|
||||
if (way_start_and_end_iterator->first_segment_source_id == via_node_id)
|
||||
{
|
||||
// assign new from node id
|
||||
auto id_iter = external_to_internal_node_id_map.find(
|
||||
OSMNodeID(way_start_and_end_iterator->first_segment_target_id));
|
||||
way_start_and_end_iterator->first_segment_target_id);
|
||||
if (id_iter == external_to_internal_node_id_map.end())
|
||||
{
|
||||
util::SimpleLogger().Write(LogLevel::logWARNING)
|
||||
@@ -703,11 +703,11 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
}
|
||||
restrictions_iterator->restriction.from.node = id_iter->second;
|
||||
}
|
||||
else if (OSMNodeID(way_start_and_end_iterator->last_segment_target_id) == via_node_id)
|
||||
else if (way_start_and_end_iterator->last_segment_target_id == via_node_id)
|
||||
{
|
||||
// assign new from node id
|
||||
auto id_iter = external_to_internal_node_id_map.find(
|
||||
OSMNodeID(way_start_and_end_iterator->last_segment_source_id));
|
||||
way_start_and_end_iterator->last_segment_source_id);
|
||||
if (id_iter == external_to_internal_node_id_map.end())
|
||||
{
|
||||
util::SimpleLogger().Write(LogLevel::logWARNING)
|
||||
@@ -746,7 +746,7 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
restrictions_iterator != restrictions_list_end_)
|
||||
{
|
||||
if (way_start_and_end_iterator->way_id <
|
||||
OSMWayID(restrictions_iterator->restriction.to.way))
|
||||
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.to.way)})
|
||||
{
|
||||
++way_start_and_end_iterator;
|
||||
continue;
|
||||
@@ -758,7 +758,7 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
continue;
|
||||
}
|
||||
if (way_start_and_end_iterator->way_id >
|
||||
OSMWayID(restrictions_iterator->restriction.to.way))
|
||||
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.to.way)})
|
||||
{
|
||||
util::SimpleLogger().Write(LogLevel::logDEBUG)
|
||||
<< "Restriction references invalid way: "
|
||||
@@ -768,18 +768,18 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
continue;
|
||||
}
|
||||
BOOST_ASSERT(way_start_and_end_iterator->way_id ==
|
||||
OSMWayID(restrictions_iterator->restriction.to.way));
|
||||
const OSMNodeID via_node_id = OSMNodeID(restrictions_iterator->restriction.via.node);
|
||||
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.to.way)});
|
||||
const OSMNodeID via_node_id = OSMNodeID{restrictions_iterator->restriction.via.node};
|
||||
|
||||
// assign new via node id
|
||||
auto via_id_iter = external_to_internal_node_id_map.find(via_node_id);
|
||||
BOOST_ASSERT(via_id_iter != external_to_internal_node_id_map.end());
|
||||
restrictions_iterator->restriction.via.node = via_id_iter->second;
|
||||
|
||||
if (OSMNodeID(way_start_and_end_iterator->first_segment_source_id) == via_node_id)
|
||||
if (way_start_and_end_iterator->first_segment_source_id == via_node_id)
|
||||
{
|
||||
auto to_id_iter = external_to_internal_node_id_map.find(
|
||||
OSMNodeID(way_start_and_end_iterator->first_segment_target_id));
|
||||
way_start_and_end_iterator->first_segment_target_id);
|
||||
if (to_id_iter == external_to_internal_node_id_map.end())
|
||||
{
|
||||
util::SimpleLogger().Write(LogLevel::logWARNING)
|
||||
@@ -792,10 +792,10 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
}
|
||||
restrictions_iterator->restriction.to.node = to_id_iter->second;
|
||||
}
|
||||
else if (OSMNodeID(way_start_and_end_iterator->last_segment_target_id) == via_node_id)
|
||||
else if (way_start_and_end_iterator->last_segment_target_id == via_node_id)
|
||||
{
|
||||
auto to_id_iter = external_to_internal_node_id_map.find(
|
||||
OSMNodeID(way_start_and_end_iterator->last_segment_source_id));
|
||||
way_start_and_end_iterator->last_segment_source_id);
|
||||
if (to_id_iter == external_to_internal_node_id_map.end())
|
||||
{
|
||||
util::SimpleLogger().Write(LogLevel::logWARNING)
|
||||
|
||||
@@ -48,9 +48,9 @@ void ExtractorCallbacks::ProcessNode(const osmium::Node &input_node,
|
||||
const ExtractionNode &result_node)
|
||||
{
|
||||
external_memory.all_nodes_list.push_back(
|
||||
{util::toFixed(util::FloatLongitude(input_node.location().lon())),
|
||||
util::toFixed(util::FloatLatitude(input_node.location().lat())),
|
||||
OSMNodeID(input_node.id()),
|
||||
{util::toFixed(util::FloatLongitude{input_node.location().lon()}),
|
||||
util::toFixed(util::FloatLatitude{input_node.location().lat()}),
|
||||
OSMNodeID{static_cast<std::uint64_t>(input_node.id())},
|
||||
result_node.barrier,
|
||||
result_node.traffic_lights});
|
||||
}
|
||||
@@ -304,7 +304,7 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
std::transform(input_way.nodes().begin(),
|
||||
input_way.nodes().end(),
|
||||
std::back_inserter(external_memory.used_node_id_list),
|
||||
[](const osmium::NodeRef &ref) { return OSMNodeID(ref.ref()); });
|
||||
[](const osmium::NodeRef &ref) { return OSMNodeID{static_cast<std::uint64_t>(ref.ref())}; });
|
||||
|
||||
const bool is_opposite_way = TRAVEL_MODE_INACCESSIBLE == parsed_way.forward_travel_mode;
|
||||
|
||||
@@ -318,8 +318,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
input_way.nodes().crend(),
|
||||
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) {
|
||||
external_memory.all_edges_list.push_back(
|
||||
InternalExtractorEdge(OSMNodeID(first_node.ref()),
|
||||
OSMNodeID(last_node.ref()),
|
||||
InternalExtractorEdge(OSMNodeID{static_cast<std::uint64_t>(first_node.ref())},
|
||||
OSMNodeID{static_cast<std::uint64_t>(last_node.ref())},
|
||||
name_id,
|
||||
backward_weight_data,
|
||||
true,
|
||||
@@ -334,11 +334,11 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
});
|
||||
|
||||
external_memory.way_start_end_id_list.push_back(
|
||||
{OSMWayID(input_way.id()),
|
||||
OSMNodeID(input_way.nodes().back().ref()),
|
||||
OSMNodeID(input_way.nodes()[input_way.nodes().size() - 2].ref()),
|
||||
OSMNodeID(input_way.nodes()[1].ref()),
|
||||
OSMNodeID(input_way.nodes()[0].ref())});
|
||||
{OSMWayID{static_cast<std::uint32_t>(input_way.id())},
|
||||
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes().back().ref())},
|
||||
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[input_way.nodes().size() - 2].ref())},
|
||||
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[1].ref())},
|
||||
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[0].ref())}});
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -349,8 +349,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
input_way.nodes().cend(),
|
||||
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) {
|
||||
external_memory.all_edges_list.push_back(
|
||||
InternalExtractorEdge(OSMNodeID(first_node.ref()),
|
||||
OSMNodeID(last_node.ref()),
|
||||
InternalExtractorEdge(OSMNodeID{static_cast<std::uint64_t>(first_node.ref())},
|
||||
OSMNodeID{static_cast<std::uint64_t>(last_node.ref())},
|
||||
name_id,
|
||||
forward_weight_data,
|
||||
true,
|
||||
@@ -371,8 +371,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
input_way.nodes().cend(),
|
||||
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) {
|
||||
external_memory.all_edges_list.push_back(
|
||||
InternalExtractorEdge(OSMNodeID(first_node.ref()),
|
||||
OSMNodeID(last_node.ref()),
|
||||
InternalExtractorEdge(OSMNodeID{static_cast<std::uint64_t>(first_node.ref())},
|
||||
OSMNodeID{static_cast<std::uint64_t>(last_node.ref())},
|
||||
name_id,
|
||||
backward_weight_data,
|
||||
false,
|
||||
@@ -388,11 +388,11 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
}
|
||||
|
||||
external_memory.way_start_end_id_list.push_back(
|
||||
{OSMWayID(input_way.id()),
|
||||
OSMNodeID(input_way.nodes().back().ref()),
|
||||
OSMNodeID(input_way.nodes()[input_way.nodes().size() - 2].ref()),
|
||||
OSMNodeID(input_way.nodes()[1].ref()),
|
||||
OSMNodeID(input_way.nodes()[0].ref())});
|
||||
{OSMWayID{static_cast<std::uint32_t>(input_way.id())},
|
||||
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes().back().ref())},
|
||||
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[input_way.nodes().size() - 2].ref())},
|
||||
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[1].ref())},
|
||||
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[0].ref())}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,10 +84,10 @@ int SourceContainer::LoadRasterSource(const std::string &path_string,
|
||||
std::size_t nrows,
|
||||
std::size_t ncols)
|
||||
{
|
||||
const auto _xmin = static_cast<int>(util::toFixed(util::FloatLongitude(xmin)));
|
||||
const auto _xmax = static_cast<int>(util::toFixed(util::FloatLongitude(xmax)));
|
||||
const auto _ymin = static_cast<int>(util::toFixed(util::FloatLatitude(ymin)));
|
||||
const auto _ymax = static_cast<int>(util::toFixed(util::FloatLatitude(ymax)));
|
||||
const auto _xmin = static_cast<std::int32_t>(util::toFixed(util::FloatLongitude{xmin}));
|
||||
const auto _xmax = static_cast<std::int32_t>(util::toFixed(util::FloatLongitude{xmax}));
|
||||
const auto _ymin = static_cast<std::int32_t>(util::toFixed(util::FloatLatitude{ymin}));
|
||||
const auto _ymax = static_cast<std::int32_t>(util::toFixed(util::FloatLatitude{ymax}));
|
||||
|
||||
const auto itr = LoadedSourcePaths.find(path_string);
|
||||
if (itr != LoadedSourcePaths.end())
|
||||
@@ -135,8 +135,8 @@ RasterDatum SourceContainer::GetRasterDataFromSource(unsigned int source_id, dou
|
||||
BOOST_ASSERT(lon > -180);
|
||||
|
||||
const auto &found = LoadedSources[source_id];
|
||||
return found.GetRasterData(static_cast<int>(util::toFixed(util::FloatLongitude(lon))),
|
||||
static_cast<int>(util::toFixed(util::FloatLatitude(lat))));
|
||||
return found.GetRasterData(static_cast<std::int32_t>(util::toFixed(util::FloatLongitude{lon})),
|
||||
static_cast<std::int32_t>(util::toFixed(util::FloatLatitude{lat})));
|
||||
}
|
||||
|
||||
// External function for looking up interpolated data from a specified source
|
||||
@@ -154,8 +154,8 @@ SourceContainer::GetRasterInterpolateFromSource(unsigned int source_id, double l
|
||||
BOOST_ASSERT(lon > -180);
|
||||
|
||||
const auto &found = LoadedSources[source_id];
|
||||
return found.GetRasterInterpolate(static_cast<int>(util::toFixed(util::FloatLongitude(lon))),
|
||||
static_cast<int>(util::toFixed(util::FloatLatitude(lat))));
|
||||
return found.GetRasterInterpolate(static_cast<std::int32_t>(util::toFixed(util::FloatLongitude{lon})),
|
||||
static_cast<std::int32_t>(util::toFixed(util::FloatLatitude{lat})));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user