Squashed 'third_party/libosmium/' content from commit ce865381f

git-subtree-dir: third_party/libosmium
git-subtree-split: ce865381fb752323ff1e66181f5a49b7f500ffa3
This commit is contained in:
Patrick Niklaus
2017-08-30 09:30:27 +00:00
commit 6eb4f090f9
434 changed files with 81367 additions and 0 deletions
+155
View File
@@ -0,0 +1,155 @@
#include "catch.hpp"
#include <osmium/osm/types.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/index/detail/tmpfile.hpp>
#include <osmium/util/file.hpp>
#include <osmium/index/map/dense_file_array.hpp>
#include <osmium/index/map/sparse_file_array.hpp>
#include <osmium/index/node_locations_map.hpp>
TEST_CASE("File based index") {
const int fd = osmium::detail::create_tmp_file();
REQUIRE(osmium::util::file_size(fd) == 0);
const osmium::unsigned_object_id_type id1 = 6;
const osmium::unsigned_object_id_type id2 = 3;
const osmium::Location loc1(1.2, 4.5);
const osmium::Location loc2(3.5, -7.2);
SECTION("dense index") {
using index_type = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
constexpr const size_t S = sizeof(index_type::element_type);
{
index_type index{fd};
REQUIRE(index.size() == 0);
REQUIRE_THROWS_AS(index.get( 0), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 1), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 3), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 5), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 6), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 7), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(100), const osmium::not_found&);
index.set(id1, loc1);
REQUIRE(index.size() == 7);
index.set(id2, loc2);
REQUIRE(index.size() == 7);
index.sort();
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE_THROWS_AS(index.get( 0), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 1), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 5), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 7), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(100), const osmium::not_found&);
REQUIRE(index.size() == 7);
REQUIRE(std::distance(index.cbegin(), index.cend()) == 7);
REQUIRE(osmium::util::file_size(fd) >= (6 * S));
}
{
index_type index{fd};
REQUIRE(osmium::util::file_size(fd) >= (6 * S));
REQUIRE(index.size() == 7);
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE_THROWS_AS(index.get( 0), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 1), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 5), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 7), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(100), const osmium::not_found&);
REQUIRE(index.size() == 7);
REQUIRE(std::distance(index.cbegin(), index.cend()) == 7);
auto it = index.cbegin();
REQUIRE(*it++ == osmium::Location{});
REQUIRE(*it++ == osmium::Location{});
REQUIRE(*it++ == osmium::Location{});
REQUIRE(*it++ == loc2);
REQUIRE(*it++ == osmium::Location{});
REQUIRE(*it++ == osmium::Location{});
REQUIRE(*it++ == loc1);
REQUIRE(it++ == index.cend());
}
}
SECTION("sparse index") {
using index_type = osmium::index::map::SparseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
constexpr const size_t S = sizeof(index_type::element_type);
{
index_type index{fd};
REQUIRE(index.size() == 0);
REQUIRE_THROWS_AS(index.get( 0), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 1), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 3), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 5), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 6), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 7), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(100), const osmium::not_found&);
index.set(id1, loc1);
REQUIRE(index.size() == 1);
index.set(id2, loc2);
REQUIRE(index.size() == 2);
index.sort();
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE_THROWS_AS(index.get( 0), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 1), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 5), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 7), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(100), const osmium::not_found&);
REQUIRE(index.size() == 2);
REQUIRE(std::distance(index.cbegin(), index.cend()) == 2);
REQUIRE(osmium::util::file_size(fd) >= (2 * S));
}
{
index_type index{fd};
REQUIRE(osmium::util::file_size(fd) >= (2 * S));
REQUIRE(index.size() == 2);
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE_THROWS_AS(index.get( 0), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 1), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 5), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get( 7), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(100), const osmium::not_found&);
REQUIRE(index.size() == 2);
REQUIRE(std::distance(index.cbegin(), index.cend()) == 2);
}
}
}
+166
View File
@@ -0,0 +1,166 @@
#include "catch.hpp"
#include <osmium/index/id_set.hpp>
#include <osmium/osm/types.hpp>
TEST_CASE("Basic functionality of IdSetDense") {
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
REQUIRE_FALSE(s.get(17));
REQUIRE_FALSE(s.get(28));
REQUIRE(s.empty());
REQUIRE(s.size() == 0);
s.set(17);
REQUIRE(s.get(17));
REQUIRE_FALSE(s.get(28));
REQUIRE_FALSE(s.empty());
REQUIRE(s.size() == 1);
s.set(28);
REQUIRE(s.get(17));
REQUIRE(s.get(28));
REQUIRE_FALSE(s.empty());
REQUIRE(s.size() == 2);
s.set(17);
REQUIRE(s.get(17));
REQUIRE(s.size() == 2);
REQUIRE_FALSE(s.check_and_set(17));
REQUIRE(s.get(17));
REQUIRE(s.size() == 2);
s.unset(17);
REQUIRE_FALSE(s.get(17));
REQUIRE(s.size() == 1);
REQUIRE(s.check_and_set(32));
REQUIRE(s.get(32));
REQUIRE(s.size() == 2);
s.clear();
REQUIRE(s.empty());
REQUIRE(s.size() == 0);
}
TEST_CASE("Iterating over IdSetDense") {
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
s.set(7);
s.set(35);
s.set(35);
s.set(20);
s.set(1ULL << 33);
s.set(21);
s.set((1ULL << 27) + 13);
REQUIRE(s.size() == 6);
auto it = s.begin();
REQUIRE(it != s.end());
REQUIRE(*it == 7);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 20);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 21);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 35);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == (1ULL << 27) + 13);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 1ULL << 33);
++it;
REQUIRE(it == s.end());
}
TEST_CASE("Test with larger Ids") {
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
const osmium::unsigned_object_id_type start = 25;
const osmium::unsigned_object_id_type end = 100000000;
const osmium::unsigned_object_id_type step = 123456;
for (osmium::unsigned_object_id_type i = start; i < end; i += step) {
s.set(i);
}
for (osmium::unsigned_object_id_type i = start; i < end; i += step) {
REQUIRE(s.get(i));
REQUIRE_FALSE(s.get(i + 1));
}
}
TEST_CASE("Large gap") {
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
s.set(3);
s.set(1 << 30);
REQUIRE(s.get(1 << 30));
REQUIRE_FALSE(s.get(1 << 29));
}
TEST_CASE("Basic functionality of IdSetSmall") {
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s;
REQUIRE_FALSE(s.get(17));
REQUIRE_FALSE(s.get(28));
REQUIRE(s.empty());
s.set(17);
REQUIRE(s.get(17));
REQUIRE_FALSE(s.get(28));
REQUIRE_FALSE(s.empty());
s.set(28);
REQUIRE(s.get(17));
REQUIRE(s.get(28));
REQUIRE_FALSE(s.empty());
s.clear();
REQUIRE(s.empty());
}
TEST_CASE("Iterating over IdSetSmall") {
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s;
s.set(7);
s.set(35);
s.set(35);
s.set(20);
s.set(1ULL << 33);
s.set(21);
s.set((1ULL << 27) + 13);
// needs to be called before size() and iterator will work properly
s.sort_unique();
REQUIRE(s.size() == 6);
auto it = s.begin();
REQUIRE(it != s.end());
REQUIRE(*it == 7);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 20);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 21);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 35);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == (1ULL << 27) + 13);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 1ULL << 33);
++it;
REQUIRE(it == s.end());
}
+258
View File
@@ -0,0 +1,258 @@
#include "catch.hpp"
#include <osmium/osm/types.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/index/map/dense_file_array.hpp>
#include <osmium/index/map/dense_mem_array.hpp>
#include <osmium/index/map/dense_mmap_array.hpp>
#include <osmium/index/map/dummy.hpp>
#include <osmium/index/map/flex_mem.hpp>
#include <osmium/index/map/sparse_file_array.hpp>
#include <osmium/index/map/sparse_mem_array.hpp>
#include <osmium/index/map/sparse_mem_map.hpp>
#include <osmium/index/map/sparse_mem_table.hpp>
#include <osmium/index/map/sparse_mmap_array.hpp>
#include <osmium/index/node_locations_map.hpp>
static_assert(osmium::index::empty_value<osmium::Location>() == osmium::Location{}, "Empty value for location is wrong");
template <typename TIndex>
void test_func_all(TIndex& index) {
const osmium::unsigned_object_id_type id1 = 12;
const osmium::unsigned_object_id_type id2 = 3;
const osmium::Location loc1{1.2, 4.5};
const osmium::Location loc2{3.5, -7.2};
REQUIRE_THROWS_AS(index.get(id1), const osmium::not_found&);
index.set(id1, loc1);
index.set(id2, loc2);
index.sort();
REQUIRE_THROWS_AS(index.get(0), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(1), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(5), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(100), const osmium::not_found&);
REQUIRE_THROWS_WITH(index.get(0), "id 0 not found");
REQUIRE_THROWS_WITH(index.get(1), "id 1 not found");
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(5) == osmium::Location{});
REQUIRE(index.get_noexcept(100) == osmium::Location{});
}
template <typename TIndex>
void test_func_real(TIndex& index) {
const osmium::unsigned_object_id_type id1 = 12;
const osmium::unsigned_object_id_type id2 = 3;
const osmium::Location loc1{1.2, 4.5};
const osmium::Location loc2{3.5, -7.2};
index.set(id1, loc1);
index.set(id2, loc2);
index.sort();
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE(loc1 == index.get_noexcept(id1));
REQUIRE(loc2 == index.get_noexcept(id2));
REQUIRE_THROWS_AS(index.get(0), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(1), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(5), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(100), const osmium::not_found&);
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(5) == osmium::Location{});
REQUIRE(index.get_noexcept(100) == osmium::Location{});
index.clear();
REQUIRE_THROWS_AS(index.get(id1), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(id2), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(0), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(1), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(5), const osmium::not_found&);
REQUIRE_THROWS_AS(index.get(100), const osmium::not_found&);
REQUIRE(index.get_noexcept(id1) == osmium::Location{});
REQUIRE(index.get_noexcept(id2) == osmium::Location{});
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(5) == osmium::Location{});
REQUIRE(index.get_noexcept(100) == osmium::Location{});
}
TEST_CASE("Map Id to location: Dummy") {
using index_type = osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory());
test_func_all<index_type>(index1);
REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory());
}
TEST_CASE("Map Id to location: DenseMemArray") {
using index_type = osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
index1.reserve(1000);
test_func_all<index_type>(index1);
index_type index2;
index2.reserve(1000);
test_func_real<index_type>(index2);
}
#ifdef __linux__
TEST_CASE("Map Id to location: DenseMmapArray") {
using index_type = osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
#else
# pragma message("not running 'DenseMapMmap' test case on this machine")
#endif
TEST_CASE("Map Id to location: DenseFileArray") {
using index_type = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
#ifdef OSMIUM_WITH_SPARSEHASH
TEST_CASE("Map Id to location: SparseMemTable") {
using index_type = osmium::index::map::SparseMemTable<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
#endif
TEST_CASE("Map Id to location: SparseMemMap") {
using index_type = osmium::index::map::SparseMemMap<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
TEST_CASE("Map Id to location: SparseMemArray") {
using index_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory());
test_func_all<index_type>(index1);
REQUIRE(2 == index1.size());
index_type index2;
test_func_real<index_type>(index2);
}
TEST_CASE("Map Id to location: FlexMem sparse") {
using index_type = osmium::index::map::FlexMem<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
TEST_CASE("Map Id to location: FlexMem dense") {
using index_type = osmium::index::map::FlexMem<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1{true};
test_func_all<index_type>(index1);
index_type index2{true};
test_func_real<index_type>(index2);
}
TEST_CASE("Map Id to location: FlexMem switch") {
using index_type = osmium::index::map::FlexMem<osmium::unsigned_object_id_type, osmium::Location>;
const osmium::Location loc1{1.1, 1.2};
const osmium::Location loc2{2.2, -9.4};
index_type index;
REQUIRE(index.size() == 0);
index.set(17, loc1);
index.set(99, loc2);
REQUIRE_FALSE(index.is_dense());
REQUIRE(index.size() == 2);
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(17) == loc1);
REQUIRE(index.get_noexcept(99) == loc2);
REQUIRE(index.get_noexcept(2000000000) == osmium::Location{});
index.switch_to_dense();
REQUIRE(index.is_dense());
REQUIRE(index.size() >= 2);
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(17) == loc1);
REQUIRE(index.get_noexcept(99) == loc2);
REQUIRE(index.get_noexcept(2000000000) == osmium::Location{});
}
TEST_CASE("Map Id to location: Dynamic map choice") {
using map_type = osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>;
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
const std::vector<std::string> map_type_names = map_factory.map_types();
REQUIRE(map_type_names.size() >= 6);
REQUIRE_THROWS_AS(map_factory.create_map(""), const osmium::map_factory_error&);
REQUIRE_THROWS_AS(map_factory.create_map("does not exist"), const osmium::map_factory_error&);
REQUIRE_THROWS_WITH(map_factory.create_map(""), "Need non-empty map type name");
REQUIRE_THROWS_WITH(map_factory.create_map("does not exist"), "Support for map type 'does not exist' not compiled into this binary");
for (const auto& map_type_name : map_type_names) {
std::unique_ptr<map_type> index1 = map_factory.create_map(map_type_name);
index1->reserve(1000);
test_func_all<map_type>(*index1);
std::unique_ptr<map_type> index2 = map_factory.create_map(map_type_name);
index2->reserve(1000);
test_func_real<map_type>(*index2);
}
}
@@ -0,0 +1,86 @@
#include "catch.hpp"
#include <osmium/builder/attr.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/object_pointer_collection.hpp>
#include <osmium/osm/object_comparisons.hpp>
#include <osmium/visitor.hpp>
using namespace osmium::builder::attr;
TEST_CASE("Create ObjectPointerCollection") {
osmium::memory::Buffer buffer{1024, osmium::memory::Buffer::auto_grow::yes};
osmium::builder::add_node(buffer,
_id(3),
_version(3)
);
osmium::builder::add_node(buffer,
_id(1),
_version(2)
);
osmium::builder::add_node(buffer,
_id(1),
_version(4)
);
osmium::ObjectPointerCollection collection;
REQUIRE(collection.empty());
REQUIRE(collection.size() == 0);
osmium::apply(buffer, collection);
REQUIRE_FALSE(collection.empty());
REQUIRE(collection.size() == 3);
auto it = collection.cbegin();
REQUIRE(it->id() == 3);
REQUIRE(it->version() == 3);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 2);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 4);
++it;
REQUIRE(it == collection.cend());
collection.sort(osmium::object_order_type_id_version{});
REQUIRE(collection.size() == 3);
it = collection.cbegin();
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 2);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 4);
++it;
REQUIRE(it->id() == 3);
REQUIRE(it->version() == 3);
++it;
REQUIRE(it == collection.cend());
collection.sort(osmium::object_order_type_id_reverse_version{});
it = collection.cbegin();
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 4);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 2);
++it;
REQUIRE(it->id() == 3);
REQUIRE(it->version() == 3);
++it;
REQUIRE(it == collection.cend());
collection.clear();
REQUIRE(collection.empty());
REQUIRE(collection.size() == 0);
}
+110
View File
@@ -0,0 +1,110 @@
#include "catch.hpp"
#include <type_traits>
#include <osmium/index/relations_map.hpp>
static_assert(std::is_default_constructible<osmium::index::RelationsMapIndex>::value == false, "RelationsMapIndex should not be default constructible");
static_assert(std::is_copy_constructible<osmium::index::RelationsMapIndex>::value == false, "RelationsMapIndex should not be copy constructible");
static_assert(std::is_copy_constructible<osmium::index::RelationsMapStash>::value == false, "RelationsMapStash should not be copy constructible");
static_assert(std::is_copy_assignable<osmium::index::RelationsMapIndex>::value == false, "RelationsMapIndex should not be copy assignable");
static_assert(std::is_copy_assignable<osmium::index::RelationsMapStash>::value == false, "RelationsMapStash should not be copy assignable");
TEST_CASE("RelationsMapStash lvalue") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
REQUIRE(stash.size() == 0);
stash.add(1, 2);
stash.add(2, 3);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 2);
const auto index = stash.build_member_to_parent_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 2);
int count = 0;
index.for_each(1, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 2);
++count;
});
REQUIRE(count == 1);
}
osmium::index::RelationsMapIndex func() {
osmium::index::RelationsMapStash stash;
stash.add(1, 2);
stash.add(2, 3);
return stash.build_member_to_parent_index();
}
TEST_CASE("RelationsMapStash rvalue") {
const osmium::index::RelationsMapIndex index{func()};
int count = 0;
index.for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 3);
++count;
});
REQUIRE(count == 1);
}
TEST_CASE("RelationsMapStash reverse index") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
REQUIRE(stash.size() == 0);
stash.add(1, 2);
stash.add(2, 3);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 2);
const auto index = stash.build_parent_to_member_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 2);
int count = 0;
index.for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 1);
++count;
});
index.for_each(3, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 2);
++count;
});
REQUIRE(count == 2);
}
TEST_CASE("RelationsMapStash both indexes") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
REQUIRE(stash.size() == 0);
stash.add(1, 2);
stash.add(2, 3);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 2);
const auto index = stash.build_indexes();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 2);
int count = 0;
index.member_to_parent().for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 3);
++count;
});
index.parent_to_member().for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 1);
++count;
});
REQUIRE(count == 2);
}