diff --git a/include/contractor/contractor_graph.hpp b/include/contractor/contractor_graph.hpp index 8fd4a86f2..e50f29f97 100644 --- a/include/contractor/contractor_graph.hpp +++ b/include/contractor/contractor_graph.hpp @@ -24,7 +24,7 @@ struct ContractorEdgeData bool forward, bool backward) : weight(weight), duration(duration), id(id), - originalEdges(std::min((unsigned)1 << 28, original_edges)), shortcut(shortcut), + originalEdges(std::min((1u << 28) - 1u, original_edges)), shortcut(shortcut), forward(forward), backward(backward), is_original_via_node_ID(false) { } diff --git a/include/contractor/graph_contractor.hpp b/include/contractor/graph_contractor.hpp index 3c904177b..f2a2b12e0 100644 --- a/include/contractor/graph_contractor.hpp +++ b/include/contractor/graph_contractor.hpp @@ -175,11 +175,11 @@ class GraphContractor auto &dijkstra = data->dijkstra; std::size_t inserted_edges_size = data->inserted_edges.size(); std::vector &inserted_edges = data->inserted_edges; - const constexpr bool SHORTCUT_ARC = true; - const constexpr bool FORWARD_DIRECTION_ENABLED = true; - const constexpr bool FORWARD_DIRECTION_DISABLED = false; - const constexpr bool REVERSE_DIRECTION_ENABLED = true; - const constexpr bool REVERSE_DIRECTION_DISABLED = false; + constexpr bool SHORTCUT_ARC = true; + constexpr bool FORWARD_DIRECTION_ENABLED = true; + constexpr bool FORWARD_DIRECTION_DISABLED = false; + constexpr bool REVERSE_DIRECTION_ENABLED = true; + constexpr bool REVERSE_DIRECTION_DISABLED = false; for (auto in_edge : contractor_graph->GetAdjacentEdgeRange(node)) { @@ -213,7 +213,9 @@ class GraphContractor } const NodeID target = contractor_graph->GetTarget(out_edge); if (node == target) + { continue; + } const EdgeWeight path_weight = in_data.weight + out_data.weight; if (target == source) diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index f78c742a7..9005cd9f0 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -859,18 +859,15 @@ class ContiguousInternalMemoryDataFacade : public BaseDataFacade const unsigned end = m_geometry_indices.at(id + 1); std::vector result_datasources; - result_datasources.resize(end - begin); // If there was no datasource info, return an array of 0's. if (m_datasource_list.empty()) { - for (unsigned i = 0; i < end - begin; ++i) - { - result_datasources.push_back(0); - } + result_datasources.resize(end - begin, 0); } else { + result_datasources.resize(end - begin); std::copy(m_datasource_list.begin() + begin, m_datasource_list.begin() + end, result_datasources.begin()); @@ -902,13 +899,11 @@ class ContiguousInternalMemoryDataFacade : public BaseDataFacade // If there was no datasource info, return an array of 0's. if (m_datasource_list.empty()) { - for (unsigned i = 0; i < end - begin; ++i) - { - result_datasources.push_back(0); - } + result_datasources.resize(end - begin, 0); } else { + result_datasources.resize(end - begin); std::copy(m_datasource_list.rbegin() + (m_datasource_list.size() - end), m_datasource_list.rbegin() + (m_datasource_list.size() - begin), result_datasources.begin()); diff --git a/include/storage/io.hpp b/include/storage/io.hpp index 464083a08..591941933 100644 --- a/include/storage/io.hpp +++ b/include/storage/io.hpp @@ -91,7 +91,7 @@ class FileReader const auto &result = input_stream.read(reinterpret_cast(dest), count * sizeof(T)); const std::size_t bytes_read = input_stream.gcount(); - if (bytes_read != count && !result) + if (bytes_read != count * sizeof(T) && !result) { if (result.eof()) { diff --git a/include/util/deallocating_vector.hpp b/include/util/deallocating_vector.hpp index c8883b2c6..3a4519e2e 100644 --- a/include/util/deallocating_vector.hpp +++ b/include/util/deallocating_vector.hpp @@ -356,8 +356,8 @@ class DeallocatingVector ElementT &back() const { - const std::size_t _bucket = current_size / ELEMENTS_PER_BLOCK; - const std::size_t _index = current_size % ELEMENTS_PER_BLOCK; + const std::size_t _bucket = (current_size - 1) / ELEMENTS_PER_BLOCK; + const std::size_t _index = (current_size - 1) % ELEMENTS_PER_BLOCK; return (bucket_list[_bucket][_index]); } diff --git a/include/util/dynamic_graph.hpp b/include/util/dynamic_graph.hpp index e47990b4d..8312292ca 100644 --- a/include/util/dynamic_graph.hpp +++ b/include/util/dynamic_graph.hpp @@ -161,9 +161,13 @@ template class DynamicGraph EdgeIterator InsertEdge(const NodeIterator from, const NodeIterator to, const EdgeDataT &data) { Node &node = node_array[from]; - EdgeIterator newFirstEdge = node.edges + node.first_edge; - if (newFirstEdge >= edge_list.size() || !isDummy(newFirstEdge)) + EdgeIterator one_beyond_last_of_node = node.edges + node.first_edge; + // if we can't write at the end of this nodes edges + // that is: the end is the end of the edge_list, + // or the beginning of the next nodes edges + if (one_beyond_last_of_node == edge_list.size() || !isDummy(one_beyond_last_of_node)) { + // can we write before this nodes edges? if (node.first_edge != 0 && isDummy(node.first_edge - 1)) { node.first_edge--; @@ -171,20 +175,24 @@ template class DynamicGraph } else { + // we have to move this nodes edges to the end of the edge_list EdgeIterator newFirstEdge = (EdgeIterator)edge_list.size(); unsigned newSize = node.edges * 1.1 + 2; EdgeIterator requiredCapacity = newSize + edge_list.size(); EdgeIterator oldCapacity = edge_list.capacity(); + // make sure there is enough space at the end if (requiredCapacity >= oldCapacity) { edge_list.reserve(requiredCapacity * 1.1); } edge_list.resize(edge_list.size() + newSize); + // move the edges over and invalidate the old ones for (const auto i : irange(0u, node.edges)) { edge_list[newFirstEdge + i] = edge_list[node.first_edge + i]; makeDummy(node.first_edge + i); } + // invalidate until the end of edge_list for (const auto i : irange(node.edges + 1, newSize)) { makeDummy(newFirstEdge + i); @@ -192,6 +200,8 @@ template class DynamicGraph node.first_edge = newFirstEdge; } } + // get the position for the edge that is to be inserted + // and write it Edge &edge = edge_list[node.first_edge + node.edges]; edge.target = to; edge.data = data; diff --git a/src/contractor/graph_contractor.cpp b/src/contractor/graph_contractor.cpp index 2ac36c81e..0a3833ccf 100644 --- a/src/contractor/graph_contractor.cpp +++ b/src/contractor/graph_contractor.cpp @@ -237,7 +237,7 @@ void GraphContractor::Run(double core_factor) unsigned current_level = 0; bool flushed_contractor = false; - while (number_of_nodes > 2 && + while (remaining_nodes.size() > 1 && number_of_contracted_nodes < static_cast(number_of_nodes * core_factor)) { if (!flushed_contractor && (number_of_contracted_nodes > @@ -341,16 +341,19 @@ void GraphContractor::Run(double core_factor) for (const ContractorEdge &edge : data->inserted_edges) { const EdgeID current_edge_ID = contractor_graph->FindEdge(edge.source, edge.target); - if (current_edge_ID < contractor_graph->EndEdges(edge.source)) + if (current_edge_ID != SPECIAL_EDGEID) { ContractorGraph::EdgeData ¤t_data = contractor_graph->GetEdgeData(current_edge_ID); if (current_data.shortcut && edge.data.forward == current_data.forward && - edge.data.backward == current_data.backward && - edge.data.weight < current_data.weight) + edge.data.backward == current_data.backward) { // found a duplicate edge with smaller weight, update it. - current_data = edge.data; + if (edge.data.weight < current_data.weight) + { + current_data = edge.data; + } + // don't insert duplicates continue; } } @@ -387,7 +390,7 @@ void GraphContractor::Run(double core_factor) if (remaining_nodes.size() > 2) { - if (orig_node_id_from_new_node_id_map.size() > 0) + if (flushed_contractor) { tbb::parallel_for(tbb::blocked_range(0, remaining_nodes.size(), InitGrainSize), [this, &remaining_nodes](const tbb::blocked_range &range) { diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index 0f3b06ef1..4eeed9f9e 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -174,10 +174,11 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) // setup restriction parser const RestrictionParser restriction_parser(scripting_environment); - while (const osmium::memory::Buffer buffer = reader.read()) + // create a vector of iterators into the buffer + for (std::vector osm_elements; + const osmium::memory::Buffer buffer = reader.read(); + osm_elements.clear()) { - // create a vector of iterators into the buffer - std::vector osm_elements; for (auto iter = std::begin(buffer), end = std::end(buffer); iter != end; ++iter) { osm_elements.push_back(iter); diff --git a/src/storage/storage_config.cpp b/src/storage/storage_config.cpp index dfb1fe25a..714d4fb5a 100644 --- a/src/storage/storage_config.cpp +++ b/src/storage/storage_config.cpp @@ -36,7 +36,7 @@ bool StorageConfig::IsValid() const timestamp_path, turn_weight_penalties_path, turn_duration_penalties_path, - datasource_indexes_path, + datasource_names_path, datasource_indexes_path, names_data_path, properties_path,