Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions include/osmium/osm/object_comparisons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ namespace osmium {
* (negative IDs first, then positive IDs, both in the order of their
* absolute values), but later versions of an object are ordered before
* earlier versions of the same object. This is useful when the last
* version of an object needs to be used.
* version of an object needs to be used. Object visibility is not taken
* into account, so objects with different visibilities keep their order.
*/
struct object_order_type_id_reverse_version {

bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
const bool tsvalid = lhs.timestamp().valid() && rhs.timestamp().valid();
return const_tie(lhs.type(), lhs.id() > 0, lhs.positive_id(), rhs.version(),
((lhs.timestamp().valid() && rhs.timestamp().valid()) ? rhs.timestamp() : osmium::Timestamp()),
rhs.visible()) <
(tsvalid ? rhs.timestamp() : osmium::Timestamp())) <
const_tie(rhs.type(), rhs.id() > 0, rhs.positive_id(), lhs.version(),
((lhs.timestamp().valid() && rhs.timestamp().valid()) ? lhs.timestamp() : osmium::Timestamp()),
lhs.visible());
(tsvalid ? lhs.timestamp() : osmium::Timestamp()));
}

/// @pre lhs and rhs must not be nullptr
Expand Down
9 changes: 8 additions & 1 deletion test/t/osm/test_object_comparisons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,18 @@ TEST_CASE("Node comparisons") {
REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend(), osmium::object_order_type_id_reverse_version{}));
}

SECTION("reverse version ordering should order objects with deleted flag last") {
SECTION("reverse version ordering should keep order for deleted objects") {
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"), _deleted(false))));
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"), _deleted(true))));

REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend(), osmium::object_order_type_id_reverse_version{}));

nodes.clear();

nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"), _deleted(true))));
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"), _deleted(false))));

REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend(), osmium::object_order_type_id_reverse_version{}));
}
}

Expand Down