diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index e0ec8be..8e2ea99 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -11,6 +11,8 @@ set( collector_interface.hpp collector_tag.cpp collector_tag.hpp + covering_index_generator.cpp + covering_index_generator.hpp data_version.cpp data_version.hpp dumper.cpp @@ -58,8 +60,6 @@ set( key_value_concurrent_writer.hpp key_value_storage.cpp key_value_storage.hpp - locality_index_generator.cpp - locality_index_generator.hpp osm2meta.cpp osm2meta.hpp osm2type.cpp diff --git a/generator/locality_index_generator.cpp b/generator/covering_index_generator.cpp similarity index 88% rename from generator/locality_index_generator.cpp rename to generator/covering_index_generator.cpp index 3a7306d..a7fdbdd 100644 --- a/generator/locality_index_generator.cpp +++ b/generator/covering_index_generator.cpp @@ -1,4 +1,4 @@ -#include "generator/locality_index_generator.hpp" +#include "generator/covering_index_generator.hpp" #include "generator/data_version.hpp" #include "generator/geo_objects/geo_objects_filter.hpp" @@ -6,9 +6,9 @@ #include "generator/streets/streets_filter.hpp" #include "generator/utils.hpp" +#include "indexer/covered_object.hpp" +#include "indexer/covering_index_builder.hpp" #include "indexer/data_header.hpp" -#include "indexer/locality_index_builder.hpp" -#include "indexer/locality_object.hpp" #include "indexer/scales.hpp" #include "coding/file_container.hpp" @@ -40,16 +40,16 @@ using namespace std; namespace generator { -class LocalityObjectBuilder +class CoveredObjectBuilder { public: - LocalityObjectBuilder() + CoveredObjectBuilder() { m_header.SetGeometryCodingParams(serial::GeometryCodingParams()); m_header.SetScales({scales::GetUpperScale()}); } - boost::optional operator()(FeatureBuilder & fb) + boost::optional operator()(FeatureBuilder & fb) { auto && geometryHolder = MakeGeometryHolder(fb); if (!geometryHolder) @@ -57,20 +57,20 @@ public: auto & data = geometryHolder->GetBuffer(); auto const encodedId = fb.GetMostGenericOsmId().GetEncodedId(); - m_localityObject.SetId(encodedId); + m_coveredObject.SetId(encodedId); switch (fb.GetGeomType()) { case GeomType::Point: { buffer_vector points{fb.GetKeyPoint()}; - m_localityObject.SetPoints(std::move(points)); + m_coveredObject.SetPoints(std::move(points)); break; } case GeomType::Line: { buffer_vector points{data.m_innerPts.begin(), data.m_innerPts.end()}; - m_localityObject.SetPoints(std::move(points)); + m_coveredObject.SetPoints(std::move(points)); break; } case GeomType::Area: @@ -82,14 +82,14 @@ public: buffer_vector triangles; serial::StripToTriangles(m_pointsBuffer.size(), m_pointsBuffer, triangles); - m_localityObject.SetTriangles(std::move(triangles)); + m_coveredObject.SetTriangles(std::move(triangles)); break; } default: UNREACHABLE(); }; - return {m_localityObject}; + return {m_coveredObject}; } private: @@ -149,21 +149,21 @@ private: } DataHeader m_header; - indexer::LocalityObject m_localityObject; + indexer::CoveredObject m_coveredObject; buffer_vector m_pointsBuffer; }; template -bool GenerateLocalityIndex( +bool GenerateCoveringIndex( std::string const & outPath, std::string const & featuresFile, FeatureFilter && featureFilter, IndexBuilder && indexBuilder, unsigned int threadsCount, uint64_t chunkFeaturesCount) { - std::list coveringsParts{}; + std::list coveringsParts{}; auto makeProcessor = [&] { coveringsParts.emplace_back(); auto & covering = coveringsParts.back(); - LocalityObjectBuilder localityObjectBuilder; + CoveredObjectBuilder localityObjectBuilder; auto processor = [featureFilter, &indexBuilder, &covering, localityObjectBuilder] (FeatureBuilder & fb, uint64_t /* currPos */) mutable { @@ -183,17 +183,17 @@ bool GenerateLocalityIndex( LOG(LINFO, ("Finish features geometry covering")); LOG(LINFO, ("Merge geometry coverings...")); - covering::LocalitiesCovering localitiesCovering; + covering::ObjectsCovering objectsCovering; while (!coveringsParts.empty()) { auto const & part = coveringsParts.back(); - localitiesCovering.insert(localitiesCovering.end(), part.begin(), part.end()); + objectsCovering.insert(objectsCovering.end(), part.begin(), part.end()); coveringsParts.pop_back(); } LOG(LINFO, ("Finish merging of geometry coverings")); LOG(LINFO, ("Build locality index...")); - if (!indexBuilder.BuildCoveringIndex(std::move(localitiesCovering), outPath)) + if (!indexBuilder.BuildCoveringIndex(std::move(objectsCovering), outPath)) return false; LOG(LINFO, ("Finish locality index building ", outPath)); @@ -237,8 +237,8 @@ bool GenerateRegionsIndex(std::string const & outPath, std::string const & featu unsigned int threadsCount) { auto const featuresFilter = [](FeatureBuilder & fb) { return fb.IsArea(); }; - indexer::RegionsLocalityIndexBuilder indexBuilder; - return GenerateLocalityIndex(outPath, featuresFile, featuresFilter, indexBuilder, + indexer::RegionsIndexBuilder indexBuilder; + return GenerateCoveringIndex(outPath, featuresFile, featuresFilter, indexBuilder, threadsCount, 1 /* chunkFeaturesCount */); } @@ -270,11 +270,11 @@ bool GenerateGeoObjectsIndex( return false; }; - indexer::GeoObjectsLocalityIndexBuilder indexBuilder; + indexer::GeoObjectsIndexBuilder indexBuilder; if (!streetsFeaturesFile) { - return GenerateLocalityIndex(outPath, geoObjectsFeaturesFile, featuresFilter, indexBuilder, + return GenerateCoveringIndex(outPath, geoObjectsFeaturesFile, featuresFilter, indexBuilder, threadsCount, 10 /* chunkFeaturesCount */); } @@ -286,7 +286,7 @@ bool GenerateGeoObjectsIndex( base::AppendFileToFile(geoObjectsFeaturesFile, featuresFile); base::AppendFileToFile(*streetsFeaturesFile, featuresFile); - return GenerateLocalityIndex(outPath, featuresFile, featuresFilter, indexBuilder, + return GenerateCoveringIndex(outPath, featuresFile, featuresFilter, indexBuilder, threadsCount, 100 /* chunkFeaturesCount */); } diff --git a/generator/locality_index_generator.hpp b/generator/covering_index_generator.hpp similarity index 100% rename from generator/locality_index_generator.hpp rename to generator/covering_index_generator.hpp diff --git a/generator/feature_builder.cpp b/generator/feature_builder.cpp index ee366d8..0efc1f5 100644 --- a/generator/feature_builder.cpp +++ b/generator/feature_builder.cpp @@ -632,8 +632,8 @@ bool FeatureBuilder::PreSerializeAndRemoveUselessNamesForMwm(SupportingData cons return PreSerializeAndRemoveUselessNamesForIntermediate(); } -void FeatureBuilder::SerializeLocalityObject(serial::GeometryCodingParams const & params, - SupportingData & data) const +void FeatureBuilder::SerializeCoveredObject(serial::GeometryCodingParams const & params, + SupportingData & data) const { data.m_buffer.clear(); diff --git a/generator/feature_builder.hpp b/generator/feature_builder.hpp index 5babfc2..090a2c1 100644 --- a/generator/feature_builder.hpp +++ b/generator/feature_builder.hpp @@ -193,8 +193,8 @@ public: void DeserializeAccuratelyFromIntermediate(Buffer & data); bool PreSerializeAndRemoveUselessNamesForMwm(SupportingData const & data); - void SerializeLocalityObject(serial::GeometryCodingParams const & params, - SupportingData & data) const; + void SerializeCoveredObject(serial::GeometryCodingParams const & params, + SupportingData & data) const; void SerializeForMwm(SupportingData & data, serial::GeometryCodingParams const & params) const; // Get common parameters of feature. diff --git a/generator/generator_tests/feature_builder_test.cpp b/generator/generator_tests/feature_builder_test.cpp index 5cdd584..b75f754 100644 --- a/generator/generator_tests/feature_builder_test.cpp +++ b/generator/generator_tests/feature_builder_test.cpp @@ -6,10 +6,10 @@ #include "generator/generator_tests_support/test_with_classificator.hpp" #include "generator/geometry_holder.hpp" -#include "indexer/data_header.cpp" #include "indexer/classificator_loader.hpp" +#include "indexer/covered_object.hpp" +#include "indexer/data_header.cpp" #include "indexer/feature_visibility.hpp" -#include "indexer/locality_object.hpp" #include "base/geo_object_id.hpp" @@ -230,7 +230,7 @@ UNIT_CLASS_TEST(TestWithClassificator, FeatureParams_Parsing) } } -UNIT_CLASS_TEST(TestWithClassificator, FeatureBuilder_SerializeLocalityObjectForBuildingPoint) +UNIT_CLASS_TEST(TestWithClassificator, FeatureBuilder_SerializeCoveredObjectForBuildingPoint) { FeatureBuilder fb; FeatureParams params; @@ -259,19 +259,19 @@ UNIT_CLASS_TEST(TestWithClassificator, FeatureBuilder_SerializeLocalityObjectFor auto & buffer = holder.GetBuffer(); TEST(fb.PreSerializeAndRemoveUselessNamesForMwm(buffer), ()); - fb.SerializeLocalityObject(serial::GeometryCodingParams(), buffer); + fb.SerializeCoveredObject(serial::GeometryCodingParams(), buffer); - using indexer::LocalityObject; - LocalityObject object; + using indexer::CoveredObject; + CoveredObject object; object.Deserialize(buffer.m_buffer.data()); - TEST_EQUAL(LocalityObject::FromStoredId(object.GetStoredId()), base::MakeOsmNode(1), ()); + TEST_EQUAL(CoveredObject::FromStoredId(object.GetStoredId()), base::MakeOsmNode(1), ()); object.ForEachPoint([] (auto && point) { TEST(base::AlmostEqualAbs(point, m2::PointD(10.1, 15.8), 1e-7), ()); }); } -UNIT_CLASS_TEST(TestWithClassificator, FeatureBuilder_SerializeLocalityObjectForLine) +UNIT_CLASS_TEST(TestWithClassificator, FeatureBuilder_SerializeCoveredObjectForLine) { FeatureBuilder fb; FeatureParams params; @@ -303,13 +303,13 @@ UNIT_CLASS_TEST(TestWithClassificator, FeatureBuilder_SerializeLocalityObjectFor auto & buffer = holder.GetBuffer(); auto preserialize = fb.PreSerializeAndRemoveUselessNamesForMwm(buffer); CHECK(preserialize, ()); - fb.SerializeLocalityObject(serial::GeometryCodingParams(), buffer); + fb.SerializeCoveredObject(serial::GeometryCodingParams(), buffer); - using indexer::LocalityObject; - LocalityObject object; + using indexer::CoveredObject; + CoveredObject object; object.Deserialize(buffer.m_buffer.data()); - TEST_EQUAL(LocalityObject::FromStoredId(object.GetStoredId()), base::MakeOsmNode(1), ()); + TEST_EQUAL(CoveredObject::FromStoredId(object.GetStoredId()), base::MakeOsmNode(1), ()); auto localityObjectsPoints = std::vector{}; object.ForEachPoint([&] (auto && point) { localityObjectsPoints.push_back(point); diff --git a/generator/generator_tests/streets_index_tests.cpp b/generator/generator_tests/streets_index_tests.cpp index 35125c6..a77cc2d 100644 --- a/generator/generator_tests/streets_index_tests.cpp +++ b/generator/generator_tests/streets_index_tests.cpp @@ -1,11 +1,11 @@ #include "testing/testing.hpp" #include "generator/generator_tests/common.hpp" +#include "generator/covering_index_generator.hpp" #include "generator/data_version.hpp" #include "generator/geo_objects/geo_objects.hpp" -#include "generator/locality_index_generator.hpp" -#include "indexer/locality_index.hpp" +#include "indexer/covering_index.hpp" #include "base/assert.hpp" diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index 13dc428..2ecead8 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -1,7 +1,7 @@ +#include "generator/covering_index_generator.hpp" #include "generator/data_version.hpp" #include "generator/generate_info.hpp" #include "generator/geo_objects/geo_objects_generator.hpp" -#include "generator/locality_index_generator.hpp" #include "generator/osm_source.hpp" #include "generator/processor_factory.hpp" #include "generator/raw_generator.hpp" @@ -13,8 +13,8 @@ #include "generator/translator_factory.hpp" #include "indexer/classificator_loader.hpp" +#include "indexer/covering_index_builder.hpp" #include "indexer/features_vector.hpp" -#include "indexer/locality_index_builder.hpp" #include "indexer/map_style_reader.hpp" #include "platform/platform.hpp" diff --git a/generator/geo_objects/geo_objects.cpp b/generator/geo_objects/geo_objects.cpp index c93fe19..a8b7f2f 100644 --- a/generator/geo_objects/geo_objects.cpp +++ b/generator/geo_objects/geo_objects.cpp @@ -1,9 +1,9 @@ +#include "generator/covering_index_generator.hpp" #include "generator/data_version.hpp" #include "generator/feature_builder.hpp" #include "generator/feature_generator.hpp" #include "generator/key_value_concurrent_writer.hpp" #include "generator/key_value_storage.hpp" -#include "generator/locality_index_generator.hpp" #include "generator/geo_objects/geo_objects.hpp" #include "generator/geo_objects/geo_objects_filter.hpp" @@ -12,7 +12,7 @@ #include "generator/regions/region_base.hpp" #include "indexer/classificator.hpp" -#include "indexer/locality_index.hpp" +#include "indexer/covering_index.hpp" #include "coding/mmap_reader.hpp" @@ -408,7 +408,7 @@ void AddPoisEnrichedWithHouseAddresses(GeoObjectMaintainer & geoObjectMaintainer NullBuildingsInfo const & buildingsInfo, std::string const & geoObjectKeyValuePath, std::string const & pathInGeoObjectsTmpMwm, - std::ostream & streamPoiIdsToAddToLocalityIndex, + std::ostream & streamPoiIdsToAddToCoveringIndex, bool /*verbose*/, unsigned int threadsCount) { std::atomic_size_t counter{0}; @@ -436,7 +436,7 @@ void AddPoisEnrichedWithHouseAddresses(GeoObjectMaintainer & geoObjectMaintainer std::lock_guard lock(streamMutex); kvWriter.Write(id, JsonValue{std::move(jsonValue)}); - streamPoiIdsToAddToLocalityIndex << id << "\n"; + streamPoiIdsToAddToCoveringIndex << id << "\n"; }; ForEachParallelFromDatRawFormat(threadsCount, pathInGeoObjectsTmpMwm, concurrentTransformer); diff --git a/generator/geo_objects/geo_objects.hpp b/generator/geo_objects/geo_objects.hpp index 2023e1b..36e8855 100644 --- a/generator/geo_objects/geo_objects.hpp +++ b/generator/geo_objects/geo_objects.hpp @@ -52,7 +52,7 @@ void AddPoisEnrichedWithHouseAddresses(GeoObjectMaintainer & geoObjectMaintainer NullBuildingsInfo const & buildingsInfo, std::string const & geoObjectKeyValuePath, std::string const & pathInGeoObjectsTmpMwm, - std::ostream & streamPoiIdsToAddToLocalityIndex, + std::ostream & streamPoiIdsToAddToCoveringIndex, bool verbose, unsigned int threadsCount); diff --git a/generator/geo_objects/geo_objects_generator.cpp b/generator/geo_objects/geo_objects_generator.cpp index 52fa5f4..445b511 100644 --- a/generator/geo_objects/geo_objects_generator.cpp +++ b/generator/geo_objects/geo_objects_generator.cpp @@ -30,7 +30,7 @@ GeoObjectsGenerator::GeoObjectsGenerator( std::string pathOutIdsWithoutAddress, std::string pathOutGeoObjectsKv, bool verbose, unsigned int threadsCount) : m_pathInGeoObjectsTmpMwm(std::move(pathInGeoObjectsTmpMwm)) - , m_pathOutPoiIdsToAddToLocalityIndex(std::move(pathOutIdsWithoutAddress)) + , m_pathOutPoiIdsToAddToCoveringIndex(std::move(pathOutIdsWithoutAddress)) , m_pathOutGeoObjectsKv(std::move(pathOutGeoObjectsKv)) , m_verbose(verbose) , m_threadsCount(threadsCount) @@ -69,11 +69,11 @@ bool GeoObjectsGenerator::GenerateGeoObjectsPrivate() NullBuildingsInfo const & buildingInfo = EnrichPointsWithOuterBuildingGeometry( m_geoObjectMaintainer, m_pathInGeoObjectsTmpMwm, m_threadsCount); - std::ofstream streamPoiIdsToAddToLocalityIndex(m_pathOutPoiIdsToAddToLocalityIndex); + std::ofstream streamPoiIdsToAddToCoveringIndex(m_pathOutPoiIdsToAddToCoveringIndex); AddPoisEnrichedWithHouseAddresses( m_geoObjectMaintainer, buildingInfo, m_pathOutGeoObjectsKv, m_pathInGeoObjectsTmpMwm, - streamPoiIdsToAddToLocalityIndex, m_verbose, m_threadsCount); + streamPoiIdsToAddToCoveringIndex, m_verbose, m_threadsCount); FilterAddresslessThanGaveTheirGeometryToInnerPoints(m_pathInGeoObjectsTmpMwm, buildingInfo, m_threadsCount); @@ -82,7 +82,7 @@ bool GeoObjectsGenerator::GenerateGeoObjectsPrivate() LOG(LINFO, ("Geo objects without addresses were built.")); LOG(LINFO, ("Geo objects key-value storage saved to", m_pathOutGeoObjectsKv)); - LOG(LINFO, ("Ids of POIs without addresses saved to", m_pathOutPoiIdsToAddToLocalityIndex)); + LOG(LINFO, ("Ids of POIs without addresses saved to", m_pathOutPoiIdsToAddToCoveringIndex)); return true; } diff --git a/generator/geo_objects/geo_objects_generator.hpp b/generator/geo_objects/geo_objects_generator.hpp index cfc095e..455b393 100644 --- a/generator/geo_objects/geo_objects_generator.hpp +++ b/generator/geo_objects/geo_objects_generator.hpp @@ -39,7 +39,7 @@ private: bool GenerateGeoObjectsPrivate(); std::string m_pathInGeoObjectsTmpMwm; - std::string m_pathOutPoiIdsToAddToLocalityIndex; + std::string m_pathOutPoiIdsToAddToCoveringIndex; std::string m_pathOutGeoObjectsKv; bool m_verbose = false; diff --git a/generator/geo_objects/geo_objects_maintainer.hpp b/generator/geo_objects/geo_objects_maintainer.hpp index 7b05d11..4d192de 100644 --- a/generator/geo_objects/geo_objects_maintainer.hpp +++ b/generator/geo_objects/geo_objects_maintainer.hpp @@ -6,7 +6,7 @@ #include "generator/feature_builder.hpp" -#include "indexer/locality_index.hpp" +#include "indexer/covering_index.hpp" #include "coding/reader.hpp" diff --git a/generator/regions/region_info_getter.hpp b/generator/regions/region_info_getter.hpp index 8420e3e..30c30de 100644 --- a/generator/regions/region_info_getter.hpp +++ b/generator/regions/region_info_getter.hpp @@ -3,7 +3,7 @@ #include "generator/key_value_storage.hpp" #include "indexer/borders.hpp" -#include "indexer/locality_index.hpp" +#include "indexer/covering_index.hpp" #include "coding/reader.hpp" diff --git a/indexer/CMakeLists.txt b/indexer/CMakeLists.txt index d064bf6..9cee6c2 100644 --- a/indexer/CMakeLists.txt +++ b/indexer/CMakeLists.txt @@ -24,6 +24,11 @@ set( classificator.hpp classificator_loader.cpp classificator_loader.hpp + covered_object.cpp + covered_object.hpp + covering_index.cpp + covering_index.hpp + covering_index_builder.hpp data_factory.cpp data_factory.hpp data_header.cpp @@ -84,11 +89,6 @@ set( index_builder.hpp interval_index.hpp interval_index_builder.hpp - locality_index.cpp - locality_index.hpp - locality_index_builder.hpp - locality_object.cpp - locality_object.hpp map_object.cpp map_object.hpp map_style.cpp diff --git a/indexer/locality_object.cpp b/indexer/covered_object.cpp similarity index 91% rename from indexer/locality_object.cpp rename to indexer/covered_object.cpp index 47ea078..f55be99 100644 --- a/indexer/locality_object.cpp +++ b/indexer/covered_object.cpp @@ -1,4 +1,4 @@ -#include "indexer/locality_object.hpp" +#include "indexer/covered_object.hpp" #include "indexer/feature_decl.hpp" @@ -7,7 +7,7 @@ namespace indexer { -void LocalityObject::Deserialize(char const * data) +void CoveredObject::Deserialize(char const * data) { ArrayByteSource src(data); serial::GeometryCodingParams cp = {}; diff --git a/indexer/locality_object.hpp b/indexer/covered_object.hpp similarity index 90% rename from indexer/locality_object.hpp rename to indexer/covered_object.hpp index 29529cc..5a3e900 100644 --- a/indexer/locality_object.hpp +++ b/indexer/covered_object.hpp @@ -14,19 +14,19 @@ namespace indexer { -// Class for intermediate objects used to build LocalityIndex. -class LocalityObject +// Class for intermediate objects used to build CoveringIndex. +class CoveredObject { public: - LocalityObject() = default; + CoveredObject() = default; - // Decodes id stored in LocalityIndex. See GetStoredId(). + // Decodes id stored in CoveringIndex. See GetStoredId(). static base::GeoObjectId FromStoredId(uint64_t storedId) { return base::GeoObjectId(storedId >> 2 | storedId << 62); } - // We need LocalityIndex object id to be at most numeric_limits::max(). + // We need CoveringIndex object id to be at most numeric_limits::max(). // We use incremental encoding for ids and need to keep ids of close object close if it is possible. // To ensure it we move two leading bits which encodes object type to the end of id. uint64_t GetStoredId() const { return m_id << 2 | m_id >> 62; } diff --git a/indexer/locality_index.cpp b/indexer/covering_index.cpp similarity index 94% rename from indexer/locality_index.cpp rename to indexer/covering_index.cpp index f72315b..bcbe824 100644 --- a/indexer/locality_index.cpp +++ b/indexer/covering_index.cpp @@ -1,4 +1,4 @@ -#include "indexer/locality_index.hpp" +#include "indexer/covering_index.hpp" #include "coding/file_container.hpp" #include "coding/mmap_reader.hpp" diff --git a/indexer/locality_index.hpp b/indexer/covering_index.hpp similarity index 93% rename from indexer/locality_index.hpp rename to indexer/covering_index.hpp index d644fc4..812df9e 100644 --- a/indexer/locality_index.hpp +++ b/indexer/covering_index.hpp @@ -1,9 +1,9 @@ #pragma once #include "indexer/cell_id.hpp" +#include "indexer/covered_object.hpp" #include "indexer/feature_covering.hpp" #include "indexer/interval_index.hpp" -#include "indexer/locality_object.hpp" #include "indexer/scales.hpp" #include "coding/file_container.hpp" @@ -28,14 +28,14 @@ namespace indexer // Used for geocoder server, stores only POIs and buildings which have address information. // Based on IntervalIndex. template -class LocalityIndex +class CoveringIndex { public: using ProcessObject = std::function; using ProcessCloseObject = std::function; - LocalityIndex() = default; - explicit LocalityIndex(Reader const & reader) + CoveringIndex() = default; + explicit CoveringIndex(Reader const & reader) { m_intervalIndex = std::make_unique>(reader); } @@ -54,7 +54,7 @@ public: { m_intervalIndex->ForEach( [&processObject](uint64_t /* key */, uint64_t storedId) { - processObject(LocalityObject::FromStoredId(storedId)); + processObject(CoveredObject::FromStoredId(storedId)); }, i.first, i.second); } @@ -113,7 +113,7 @@ public: }; auto insertObject = [&] (int64_t cellNumber, uint64_t storedId) { - auto const objectId = LocalityObject::FromStoredId(storedId).GetEncodedId(); + auto const objectId = CoveredObject::FromStoredId(storedId).GetEncodedId(); auto & objectWeight = objectWeights[objectId]; objectWeight = std::max(objectWeight, cellRelativeWeight(cellNumber)); }; @@ -142,10 +142,10 @@ private: }; template -using GeoObjectsIndex = LocalityIndex; +using GeoObjectsIndex = CoveringIndex; template -using RegionsIndex = LocalityIndex; +using RegionsIndex = CoveringIndex; template struct GeoObjectsIndexBox diff --git a/indexer/locality_index_builder.hpp b/indexer/covering_index_builder.hpp similarity index 74% rename from indexer/locality_index_builder.hpp rename to indexer/covering_index_builder.hpp index 8654ca2..fdedfa0 100644 --- a/indexer/locality_index_builder.hpp +++ b/indexer/covering_index_builder.hpp @@ -1,9 +1,9 @@ #pragma once #include "indexer/cell_id.hpp" #include "indexer/cell_value_pair.hpp" +#include "indexer/covered_object.hpp" #include "indexer/feature_covering.hpp" #include "indexer/interval_index_builder.hpp" -#include "indexer/locality_object.hpp" #include "indexer/scales.hpp" #include "coding/file_container.hpp" @@ -25,27 +25,27 @@ namespace covering { -using LocalitiesCovering = std::deque>; +using ObjectsCovering = std::deque>; } // namespace covering namespace indexer { template -class LocalityIndexBuilder +class CoveringIndexBuilder { public: - void Cover(LocalityObject const & localityObject, covering::LocalitiesCovering & covering) const + void Cover(CoveredObject const & coveredObject, covering::ObjectsCovering & covering) const { static auto const cellDepth = covering::GetCodingDepth(scales::GetUpperScale()); - auto const id = localityObject.GetStoredId(); - auto && cells = m_builderSpec.Cover(localityObject, cellDepth); + auto const id = coveredObject.GetStoredId(); + auto && cells = m_builderSpec.Cover(coveredObject, cellDepth); for (auto const & cell : cells) covering.emplace_back(cell, id); } - bool BuildCoveringIndex(covering::LocalitiesCovering && covering, + bool BuildCoveringIndex(covering::ObjectsCovering && covering, std::string const & localityIndexPath) const { std::vector buffer; @@ -69,7 +69,7 @@ public: } template - void BuildCoveringIndex(covering::LocalitiesCovering && covering, Writer && writer, + void BuildCoveringIndex(covering::ObjectsCovering && covering, Writer && writer, int depthLevel) const { // 32 threads block_indirect_sort is fastest for |block_size| (internal parameter) and @@ -90,7 +90,7 @@ struct RegionsIndexBuilderSpec static constexpr int kDepthLevels = kRegionsDepthLevels; static constexpr auto const & kIndexFileTag = REGIONS_INDEX_FILE_TAG; - std::vector Cover(indexer::LocalityObject const & o, int cellDepth) const + std::vector Cover(indexer::CoveredObject const & o, int cellDepth) const { return covering::CoverRegion(o, cellDepth); } @@ -101,12 +101,12 @@ struct GeoObjectsIndexBuilderSpec static constexpr int kDepthLevels = kGeoObjectsDepthLevels; static constexpr auto const & kIndexFileTag = GEO_OBJECTS_INDEX_FILE_TAG; - std::vector Cover(indexer::LocalityObject const & o, int cellDepth) const + std::vector Cover(indexer::CoveredObject const & o, int cellDepth) const { return covering::CoverGeoObject(o, cellDepth); } }; -using RegionsLocalityIndexBuilder = LocalityIndexBuilder; -using GeoObjectsLocalityIndexBuilder = LocalityIndexBuilder; +using RegionsIndexBuilder = CoveringIndexBuilder; +using GeoObjectsIndexBuilder = CoveringIndexBuilder; } // namespace indexer diff --git a/indexer/feature_covering.cpp b/indexer/feature_covering.cpp index 8a0fe0a..20a42ab 100644 --- a/indexer/feature_covering.cpp +++ b/indexer/feature_covering.cpp @@ -1,7 +1,7 @@ #include "indexer/feature_covering.hpp" +#include "indexer/covered_object.hpp" #include "indexer/feature.hpp" -#include "indexer/locality_object.hpp" #include "geometry/covering_utils.hpp" @@ -150,7 +150,7 @@ vector CoverIntersection(FeatureIntersector const & fIsec } template -vector CoverLocality(indexer::LocalityObject const & o, int cellDepth) +vector Cover(indexer::CoveredObject const & o, int cellDepth) { FeatureIntersector fIsect; o.ForEachPoint(fIsect); @@ -168,14 +168,14 @@ vector CoverFeature(FeatureType & f, int cellDepth, uint64_t cellPenalt return CoverIntersection(fIsect, cellDepth, cellPenaltyArea); } -vector CoverGeoObject(indexer::LocalityObject const & o, int cellDepth) +vector CoverGeoObject(indexer::CoveredObject const & o, int cellDepth) { - return CoverLocality(o, cellDepth); + return Cover(o, cellDepth); } -vector CoverRegion(indexer::LocalityObject const & o, int cellDepth) +vector CoverRegion(indexer::CoveredObject const & o, int cellDepth) { - return CoverLocality(o, cellDepth); + return Cover(o, cellDepth); } void SortAndMergeIntervals(Intervals v, Intervals & res) diff --git a/indexer/feature_covering.hpp b/indexer/feature_covering.hpp index 001dd60..db340e3 100644 --- a/indexer/feature_covering.hpp +++ b/indexer/feature_covering.hpp @@ -21,7 +21,7 @@ class FeatureType; namespace indexer { -class LocalityObject; +class CoveredObject; } // namespace indexer namespace covering @@ -32,8 +32,8 @@ typedef std::vector Intervals; // Cover feature with RectIds and return their integer representations. std::vector CoverFeature(FeatureType & feature, int cellDepth, uint64_t cellPenaltyArea); -std::vector CoverRegion(indexer::LocalityObject const & o, int cellDepth); -std::vector CoverGeoObject(indexer::LocalityObject const & o, int cellDepth); +std::vector CoverRegion(indexer::CoveredObject const & o, int cellDepth); +std::vector CoverGeoObject(indexer::CoveredObject const & o, int cellDepth); // Given a vector of intervals [a, b), sort them and merge overlapping intervals. Intervals SortAndMergeIntervals(Intervals const & intervals); diff --git a/indexer/indexer_tests/locality_index_test.cpp b/indexer/indexer_tests/locality_index_test.cpp index 0dfecb7..eabd45f 100644 --- a/indexer/indexer_tests/locality_index_test.cpp +++ b/indexer/indexer_tests/locality_index_test.cpp @@ -1,9 +1,9 @@ #include "testing/testing.hpp" #include "indexer/cell_id.hpp" -#include "indexer/locality_index.hpp" -#include "indexer/locality_index_builder.hpp" -#include "indexer/locality_object.hpp" +#include "indexer/covering_index.hpp" +#include "indexer/covering_index_builder.hpp" +#include "indexer/covered_object.hpp" #include "coding/file_container.hpp" #include "coding/reader.hpp" @@ -26,9 +26,9 @@ namespace template void BuildGeoObjectsIndex(ObjectsVector const & objects, Writer && writer) { - indexer::GeoObjectsLocalityIndexBuilder indexBuilder; + indexer::GeoObjectsIndexBuilder indexBuilder; - covering::LocalitiesCovering objectsCovering; + covering::ObjectsCovering objectsCovering; for (auto const & object : objects) indexBuilder.Cover(object, objectsCovering); @@ -39,8 +39,8 @@ void BuildGeoObjectsIndex(ObjectsVector const & objects, Writer && writer) using Ids = set; using RankedIds = vector; -template -Ids GetIds(LocalityIndex const & index, m2::RectD const & rect) +template +Ids GetIds(CoveringIndex const & index, m2::RectD const & rect) { Ids ids; index.ForEachInRect([&ids](base::GeoObjectId const & id) { ids.insert(id.GetEncodedId()); }, @@ -48,8 +48,8 @@ Ids GetIds(LocalityIndex const & index, m2::RectD const & rect) return ids; }; -template -RankedIds GetRankedIds(LocalityIndex const & index, m2::PointD const & center, +template +RankedIds GetRankedIds(CoveringIndex const & index, m2::PointD const & center, m2::PointD const & border, uint32_t topSize) { RankedIds ids; @@ -59,9 +59,9 @@ RankedIds GetRankedIds(LocalityIndex const & index, m2::PointD const & center, return ids; }; -UNIT_TEST(BuildLocalityIndexTest) +UNIT_TEST(BuildCoveringIndexTest) { - vector objects; + vector objects; objects.resize(4); objects[0].SetForTesting(1, m2::PointD{0, 0}); objects[1].SetForTesting(2, m2::PointD{1, 0}); @@ -80,9 +80,9 @@ UNIT_TEST(BuildLocalityIndexTest) TEST_EQUAL(GetIds(index, m2::RectD{-0.5, -0.5, 1.5, 1.5}), (Ids{1, 2, 3, 4}), ()); } -UNIT_TEST(LocalityIndexRankTest) +UNIT_TEST(CoveringIndexRankTest) { - vector objects; + vector objects; objects.resize(4); objects[0].SetForTesting(1, m2::PointD{1, 0}); objects[1].SetForTesting(2, m2::PointD{2, 0}); @@ -112,9 +112,9 @@ UNIT_TEST(LocalityIndexRankTest) (vector{3}), ()); } -UNIT_TEST(LocalityIndexTopSizeTest) +UNIT_TEST(CoveringIndexTopSizeTest) { - vector objects; + vector objects; objects.resize(8); // Same cell. objects[0].SetForTesting(1, m2::PointD{1.0, 0.0}); @@ -175,12 +175,12 @@ UNIT_TEST(LocalityIndexTopSizeTest) 8, ()); } -UNIT_TEST(LocalityIndexWeightRankTest) +UNIT_TEST(CoveringIndexWeightRankTest) { m2::PointD queryPoint{0, 0}; m2::PointD queryBorder{0, 2}; - vector objects; + vector objects; objects.resize(7); // Enclose query point. objects[0].SetForTesting(1, m2::PointD{0, 0});