Skip to content

Commit cff8ff4

Browse files
committed
Order deleted objects after visible ones in reverse id order
osmium::object_order_type_id_reverse_version is used to order OSM objects for merging or applying diffs. If the diffs are from extracts, it can happen that there are multiple objects with the same type, id, version, and timestamp but different deleted flag. In that case the merged diff should contain the visible object, not the deleted one, because the deleted one isn't really deleted, just outside the area of the extract. To achieve this, osmium::object_order_type_id_reverse_version must order visible objects before deleted ones if all else stays the same. See osmcode/osmium-tool#282
1 parent a57fe6c commit cff8ff4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

include/osmium/osm/object_comparisons.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ namespace osmium {
160160

161161
bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
162162
return const_tie(lhs.type(), lhs.id() > 0, lhs.positive_id(), rhs.version(),
163-
((lhs.timestamp().valid() && rhs.timestamp().valid()) ? rhs.timestamp() : osmium::Timestamp())) <
163+
((lhs.timestamp().valid() && rhs.timestamp().valid()) ? rhs.timestamp() : osmium::Timestamp()),
164+
rhs.visible()) <
164165
const_tie(rhs.type(), rhs.id() > 0, rhs.positive_id(), lhs.version(),
165-
((lhs.timestamp().valid() && rhs.timestamp().valid()) ? lhs.timestamp() : osmium::Timestamp()));
166+
((lhs.timestamp().valid() && rhs.timestamp().valid()) ? lhs.timestamp() : osmium::Timestamp()),
167+
lhs.visible());
166168
}
167169

168170
/// @pre lhs and rhs must not be nullptr

test/t/osm/test_object_comparisons.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ TEST_CASE("Node comparisons") {
195195
REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend(), osmium::object_order_type_id_reverse_version{}));
196196
}
197197

198+
SECTION("reverse version ordering should order objects with deleted flag last") {
199+
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"), _deleted(false))));
200+
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"), _deleted(true))));
201+
202+
REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend(), osmium::object_order_type_id_reverse_version{}));
203+
}
198204
}
199205

200206
TEST_CASE("Object comparisons: types are ordered nodes, then ways, then relations") {

0 commit comments

Comments
 (0)