[generator, indexer] Refact: rename LocalityIndex -> CoveringIndex
This commit is contained in:
parent
b924f170d0
commit
04ec6f69bc
23 changed files with 116 additions and 116 deletions
|
@ -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
|
||||
|
|
|
@ -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<indexer::LocalityObject const &> operator()(FeatureBuilder & fb)
|
||||
boost::optional<indexer::CoveredObject const &> 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<m2::PointD, 32> points{fb.GetKeyPoint()};
|
||||
m_localityObject.SetPoints(std::move(points));
|
||||
m_coveredObject.SetPoints(std::move(points));
|
||||
break;
|
||||
}
|
||||
case GeomType::Line:
|
||||
{
|
||||
buffer_vector<m2::PointD, 32> 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<m2::PointD, 32> 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<m2::PointD, 32> m_pointsBuffer;
|
||||
};
|
||||
|
||||
template <typename FeatureFilter, typename IndexBuilder>
|
||||
bool GenerateLocalityIndex(
|
||||
bool GenerateCoveringIndex(
|
||||
std::string const & outPath, std::string const & featuresFile, FeatureFilter && featureFilter,
|
||||
IndexBuilder && indexBuilder, unsigned int threadsCount, uint64_t chunkFeaturesCount)
|
||||
{
|
||||
std::list<covering::LocalitiesCovering> coveringsParts{};
|
||||
std::list<covering::ObjectsCovering> 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 */);
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<m2::PointD>{};
|
||||
object.ForEachPoint([&] (auto && point) {
|
||||
localityObjectsPoints.push_back(point);
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<std::mutex> lock(streamMutex);
|
||||
kvWriter.Write(id, JsonValue{std::move(jsonValue)});
|
||||
streamPoiIdsToAddToLocalityIndex << id << "\n";
|
||||
streamPoiIdsToAddToCoveringIndex << id << "\n";
|
||||
};
|
||||
|
||||
ForEachParallelFromDatRawFormat(threadsCount, pathInGeoObjectsTmpMwm, concurrentTransformer);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "generator/feature_builder.hpp"
|
||||
|
||||
#include "indexer/locality_index.hpp"
|
||||
#include "indexer/covering_index.hpp"
|
||||
|
||||
#include "coding/reader.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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = {};
|
|
@ -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<int64_t>::max().
|
||||
// We need CoveringIndex object id to be at most numeric_limits<int64_t>::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; }
|
|
@ -1,4 +1,4 @@
|
|||
#include "indexer/locality_index.hpp"
|
||||
#include "indexer/covering_index.hpp"
|
||||
|
||||
#include "coding/file_container.hpp"
|
||||
#include "coding/mmap_reader.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 <typename Reader, int DEPTH_LEVELS>
|
||||
class LocalityIndex
|
||||
class CoveringIndex
|
||||
{
|
||||
public:
|
||||
using ProcessObject = std::function<void(base::GeoObjectId const &)>;
|
||||
using ProcessCloseObject = std::function<void(base::GeoObjectId const & objectId, double closenessWeight)>;
|
||||
|
||||
LocalityIndex() = default;
|
||||
explicit LocalityIndex(Reader const & reader)
|
||||
CoveringIndex() = default;
|
||||
explicit CoveringIndex(Reader const & reader)
|
||||
{
|
||||
m_intervalIndex = std::make_unique<IntervalIndex<Reader, uint64_t>>(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 <typename Reader>
|
||||
using GeoObjectsIndex = LocalityIndex<Reader, kGeoObjectsDepthLevels>;
|
||||
using GeoObjectsIndex = CoveringIndex<Reader, kGeoObjectsDepthLevels>;
|
||||
|
||||
template <typename Reader>
|
||||
using RegionsIndex = LocalityIndex<Reader, kRegionsDepthLevels>;
|
||||
using RegionsIndex = CoveringIndex<Reader, kRegionsDepthLevels>;
|
||||
|
||||
template <typename Reader>
|
||||
struct GeoObjectsIndexBox
|
|
@ -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<CellValuePair<uint64_t>>;
|
||||
using ObjectsCovering = std::deque<CellValuePair<uint64_t>>;
|
||||
} // namespace covering
|
||||
|
||||
namespace indexer
|
||||
{
|
||||
template <typename BuilderSpec>
|
||||
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<BuilderSpec::kDepthLevels>(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<char> buffer;
|
||||
|
@ -69,7 +69,7 @@ public:
|
|||
}
|
||||
|
||||
template <typename Writer>
|
||||
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<int64_t> Cover(indexer::LocalityObject const & o, int cellDepth) const
|
||||
std::vector<int64_t> 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<int64_t> Cover(indexer::LocalityObject const & o, int cellDepth) const
|
||||
std::vector<int64_t> Cover(indexer::CoveredObject const & o, int cellDepth) const
|
||||
{
|
||||
return covering::CoverGeoObject(o, cellDepth);
|
||||
}
|
||||
};
|
||||
|
||||
using RegionsLocalityIndexBuilder = LocalityIndexBuilder<RegionsIndexBuilderSpec>;
|
||||
using GeoObjectsLocalityIndexBuilder = LocalityIndexBuilder<GeoObjectsIndexBuilderSpec>;
|
||||
using RegionsIndexBuilder = CoveringIndexBuilder<RegionsIndexBuilderSpec>;
|
||||
using GeoObjectsIndexBuilder = CoveringIndexBuilder<GeoObjectsIndexBuilderSpec>;
|
||||
} // namespace indexer
|
|
@ -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<int64_t> CoverIntersection(FeatureIntersector<DEPTH_LEVELS> const & fIsec
|
|||
}
|
||||
|
||||
template <int DEPTH_LEVELS>
|
||||
vector<int64_t> CoverLocality(indexer::LocalityObject const & o, int cellDepth)
|
||||
vector<int64_t> Cover(indexer::CoveredObject const & o, int cellDepth)
|
||||
{
|
||||
FeatureIntersector<DEPTH_LEVELS> fIsect;
|
||||
o.ForEachPoint(fIsect);
|
||||
|
@ -168,14 +168,14 @@ vector<int64_t> CoverFeature(FeatureType & f, int cellDepth, uint64_t cellPenalt
|
|||
return CoverIntersection(fIsect, cellDepth, cellPenaltyArea);
|
||||
}
|
||||
|
||||
vector<int64_t> CoverGeoObject(indexer::LocalityObject const & o, int cellDepth)
|
||||
vector<int64_t> CoverGeoObject(indexer::CoveredObject const & o, int cellDepth)
|
||||
{
|
||||
return CoverLocality<kGeoObjectsDepthLevels>(o, cellDepth);
|
||||
return Cover<kGeoObjectsDepthLevels>(o, cellDepth);
|
||||
}
|
||||
|
||||
vector<int64_t> CoverRegion(indexer::LocalityObject const & o, int cellDepth)
|
||||
vector<int64_t> CoverRegion(indexer::CoveredObject const & o, int cellDepth)
|
||||
{
|
||||
return CoverLocality<kRegionsDepthLevels>(o, cellDepth);
|
||||
return Cover<kRegionsDepthLevels>(o, cellDepth);
|
||||
}
|
||||
|
||||
void SortAndMergeIntervals(Intervals v, Intervals & res)
|
||||
|
|
|
@ -21,7 +21,7 @@ class FeatureType;
|
|||
|
||||
namespace indexer
|
||||
{
|
||||
class LocalityObject;
|
||||
class CoveredObject;
|
||||
} // namespace indexer
|
||||
|
||||
namespace covering
|
||||
|
@ -32,8 +32,8 @@ typedef std::vector<Interval> Intervals;
|
|||
// Cover feature with RectIds and return their integer representations.
|
||||
std::vector<int64_t> CoverFeature(FeatureType & feature, int cellDepth, uint64_t cellPenaltyArea);
|
||||
|
||||
std::vector<int64_t> CoverRegion(indexer::LocalityObject const & o, int cellDepth);
|
||||
std::vector<int64_t> CoverGeoObject(indexer::LocalityObject const & o, int cellDepth);
|
||||
std::vector<int64_t> CoverRegion(indexer::CoveredObject const & o, int cellDepth);
|
||||
std::vector<int64_t> 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);
|
||||
|
|
|
@ -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 <class ObjectsVector, class Writer>
|
||||
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<uint64_t>;
|
||||
using RankedIds = vector<uint64_t>;
|
||||
|
||||
template <typename LocalityIndex>
|
||||
Ids GetIds(LocalityIndex const & index, m2::RectD const & rect)
|
||||
template <typename CoveringIndex>
|
||||
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 <typename LocalityIndex>
|
||||
RankedIds GetRankedIds(LocalityIndex const & index, m2::PointD const & center,
|
||||
template <typename CoveringIndex>
|
||||
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<LocalityObject> objects;
|
||||
vector<CoveredObject> 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<LocalityObject> objects;
|
||||
vector<CoveredObject> 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<uint64_t>{3}), ());
|
||||
}
|
||||
|
||||
UNIT_TEST(LocalityIndexTopSizeTest)
|
||||
UNIT_TEST(CoveringIndexTopSizeTest)
|
||||
{
|
||||
vector<LocalityObject> objects;
|
||||
vector<CoveredObject> 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<LocalityObject> objects;
|
||||
vector<CoveredObject> objects;
|
||||
objects.resize(7);
|
||||
// Enclose query point.
|
||||
objects[0].SetForTesting(1, m2::PointD{0, 0});
|
||||
|
|
Loading…
Add table
Reference in a new issue