[generator] Optimize features generatrion: share intermediate data for all translators

This commit is contained in:
Anatoly Serdtcev 2019-11-05 14:46:26 +03:00 committed by Sergey Yershov
parent 08474d499f
commit 79ee32b690
13 changed files with 37 additions and 34 deletions

View file

@ -10,10 +10,10 @@ using namespace feature;
namespace generator
{
FeatureMakerBase::FeatureMakerBase(std::shared_ptr<cache::IntermediateData> const & cache)
FeatureMakerBase::FeatureMakerBase(std::shared_ptr<cache::IntermediateData const> const & cache)
: m_cache(cache) {}
void FeatureMakerBase::SetCache(std::shared_ptr<cache::IntermediateData> const & cache)
void FeatureMakerBase::SetCache(std::shared_ptr<cache::IntermediateData const> const & cache)
{
m_cache = cache;
}

View file

@ -19,12 +19,12 @@ class IntermediateData;
class FeatureMakerBase
{
public:
explicit FeatureMakerBase(std::shared_ptr<cache::IntermediateData> const & cache = {});
explicit FeatureMakerBase(std::shared_ptr<cache::IntermediateData const> const & cache = {});
virtual ~FeatureMakerBase() = default;
virtual std::shared_ptr<FeatureMakerBase> Clone() const = 0;
void SetCache(std::shared_ptr<cache::IntermediateData> const & cache);
void SetCache(std::shared_ptr<cache::IntermediateData const> const & cache);
// Reference on element is non const because ftype::GetNameAndType will be call.
virtual bool Add(OsmElement & element);
@ -40,7 +40,7 @@ protected:
virtual void ParseParams(FeatureParams & params, OsmElement & element) const = 0;
std::shared_ptr<cache::IntermediateData> m_cache;
std::shared_ptr<cache::IntermediateData const> m_cache;
std::queue<feature::FeatureBuilder> m_queue;
};

View file

@ -547,9 +547,9 @@ shared_ptr<IntermediateDataReader> const & IntermediateData::GetCache() const
return m_reader;
}
shared_ptr<IntermediateData> IntermediateData::Clone() const
shared_ptr<IntermediateData const> IntermediateData::Clone() const
{
return make_shared<IntermediateData>(m_info);
return shared_from_this();
}
} // namespace cache
} // namespace generator

View file

@ -138,7 +138,7 @@ public:
bool forceReload = false);
template <class Value>
bool Read(Key id, Value & value)
bool Read(Key id, Value & value) const
{
uint64_t pos = 0;
if (!m_offsetsReader.GetValueByKey(id, pos))
@ -254,24 +254,24 @@ public:
// TODO |GetNode()|, |lat|, |lon| are used as y, x in real.
bool GetNode(Key id, double & lat, double & lon) const { return m_nodes.GetPoint(id, lat, lon); }
bool GetWay(Key id, WayElement & e) { return m_ways.Read(id, e); }
bool GetWay(Key id, WayElement & e) const { return m_ways.Read(id, e); }
template <typename ToDo>
void ForEachRelationByWay(Key id, ToDo && toDo)
void ForEachRelationByWay(Key id, ToDo && toDo) const
{
RelationProcessor<ToDo> processor(m_relations, std::forward<ToDo>(toDo));
m_wayToRelations.ForEachByKey(id, processor);
}
template <typename ToDo>
void ForEachRelationByWayCached(Key id, ToDo && toDo)
void ForEachRelationByWayCached(Key id, ToDo && toDo) const
{
CachedRelationProcessor<ToDo> processor(m_relations, std::forward<ToDo>(toDo));
m_wayToRelations.ForEachByKey(id, processor);
}
template <typename ToDo>
void ForEachRelationByNodeCached(Key id, ToDo && toDo)
void ForEachRelationByNodeCached(Key id, ToDo && toDo) const
{
CachedRelationProcessor<ToDo> processor(m_relations, std::forward<ToDo>(toDo));
m_nodeToRelations.ForEachByKey(id, processor);
@ -284,7 +284,8 @@ private:
class ElementProcessorBase
{
public:
ElementProcessorBase(CacheReader & reader, ToDo & toDo) : m_reader(reader), m_toDo(toDo) {}
ElementProcessorBase(CacheReader const & reader, ToDo & toDo) : m_reader(reader), m_toDo(toDo)
{ }
base::ControlFlow operator()(uint64_t id)
{
@ -293,7 +294,7 @@ private:
}
protected:
CacheReader & m_reader;
CacheReader const & m_reader;
ToDo & m_toDo;
};
@ -302,7 +303,7 @@ private:
{
using Base = ElementProcessorBase<RelationElement, ToDo>;
RelationProcessor(CacheReader & reader, ToDo & toDo) : Base(reader, toDo) {}
RelationProcessor(CacheReader const & reader, ToDo & toDo) : Base(reader, toDo) {}
};
template <typename ToDo>
@ -310,13 +311,13 @@ private:
{
using Base = RelationProcessor<ToDo>;
CachedRelationProcessor(CacheReader & reader, ToDo & toDo) : Base(reader, toDo) {}
CachedRelationProcessor(CacheReader const & reader, ToDo & toDo) : Base(reader, toDo) {}
base::ControlFlow operator()(uint64_t id) { return this->m_toDo(id, this->m_reader); }
};
PointStorageReaderInterface const & m_nodes;
cache::OSMElementCacheReader m_ways;
cache::OSMElementCacheReader m_relations;
cache::OSMElementCacheReader const m_ways;
cache::OSMElementCacheReader const m_relations;
cache::IndexFileReader const & m_nodeToRelations;
cache::IndexFileReader const & m_wayToRelations;
};
@ -368,12 +369,12 @@ CreatePointStorageReader(feature::GenerateInfo::NodeStorageType type, std::strin
std::unique_ptr<PointStorageWriterInterface>
CreatePointStorageWriter(feature::GenerateInfo::NodeStorageType type, std::string const & name);
class IntermediateData
class IntermediateData : public std::enable_shared_from_this<IntermediateData>
{
public:
explicit IntermediateData(feature::GenerateInfo const & info, bool forceReload = false);
std::shared_ptr<IntermediateDataReader> const & GetCache() const;
std::shared_ptr<IntermediateData> Clone() const;
std::shared_ptr<IntermediateData const> Clone() const;
private:
feature::GenerateInfo const & m_info;

View file

@ -57,7 +57,7 @@ private:
feature::GenerateInfo & m_genInfo;
size_t m_chunkSize;
std::shared_ptr<cache::IntermediateData> m_cache;
std::shared_ptr<cache::IntermediateData const> m_cache;
std::shared_ptr<FeatureProcessorQueue> m_queue;
std::shared_ptr<TranslatorCollection> m_translators;
std::priority_queue<FinalProcessorPtr, std::vector<FinalProcessorPtr>, FinalProcessorPtrCmp> m_finalProcessors;

View file

@ -11,7 +11,7 @@ using namespace feature;
namespace generator
{
Translator::Translator(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData> const & cache,
std::shared_ptr<cache::IntermediateData const> const & cache,
std::shared_ptr<FeatureMakerBase> const & maker,
std::shared_ptr<FilterInterface> const & filter,
std::shared_ptr<CollectorInterface> const & collector)
@ -26,7 +26,7 @@ Translator::Translator(std::shared_ptr<FeatureProcessorInterface> const & proces
}
Translator::Translator(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData> const & cache,
std::shared_ptr<cache::IntermediateData const> const & cache,
std::shared_ptr<FeatureMakerBase> const & maker)
: Translator(processor, cache, maker, std::make_shared<FilterCollection>(), std::make_shared<CollectorCollection>())
{

View file

@ -27,12 +27,12 @@ class Translator : public TranslatorInterface
{
public:
explicit Translator(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData> const & cache,
std::shared_ptr<cache::IntermediateData const> const & cache,
std::shared_ptr<FeatureMakerBase> const & maker,
std::shared_ptr<FilterInterface> const & filter,
std::shared_ptr<CollectorInterface> const & collector);
explicit Translator(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData> const & cache,
std::shared_ptr<cache::IntermediateData const> const & cache,
std::shared_ptr<FeatureMakerBase> const & maker);
void SetCollector(std::shared_ptr<CollectorInterface> const & collector);
@ -66,6 +66,6 @@ protected:
RelationTagsEnricher m_tagsEnricher;
std::shared_ptr<FeatureMakerBase> m_featureMaker;
std::shared_ptr<FeatureProcessorInterface> m_processor;
std::shared_ptr<cache::IntermediateData> m_cache;
std::shared_ptr<cache::IntermediateData const> m_cache;
};
} // namespace generator

View file

@ -11,8 +11,9 @@
namespace generator
{
TranslatorGeoObjects::TranslatorGeoObjects(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData> const & cache)
TranslatorGeoObjects::TranslatorGeoObjects(
std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData const> const & cache)
: Translator(processor, cache, std::make_shared<FeatureMakerSimple>(cache))
{

View file

@ -18,7 +18,7 @@ class TranslatorGeoObjects : public Translator
{
public:
explicit TranslatorGeoObjects(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData> const & cache);
std::shared_ptr<cache::IntermediateData const> const & cache);
// TranslatorInterface overrides:
std::shared_ptr<TranslatorInterface> Clone() const override;

View file

@ -52,7 +52,7 @@ public:
} // namespace
TranslatorRegion::TranslatorRegion(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData> const & cache,
std::shared_ptr<cache::IntermediateData const> const & cache,
std::string const & regionsInfoPath)
: Translator(processor, cache, std::make_shared<FeatureMakerSimple>(cache))

View file

@ -22,7 +22,7 @@ class TranslatorRegion : public Translator
{
public:
explicit TranslatorRegion(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData> const & cache,
std::shared_ptr<cache::IntermediateData const> const & cache,
std::string const & regionsInfoPath);
// TranslatorInterface overrides:

View file

@ -7,8 +7,9 @@
namespace generator
{
TranslatorStreets::TranslatorStreets(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData> const & cache)
TranslatorStreets::TranslatorStreets(
std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData const> const & cache)
: Translator(processor, cache, std::make_shared<FeatureMakerSimple>(cache))
{

View file

@ -18,7 +18,7 @@ class TranslatorStreets : public Translator
{
public:
explicit TranslatorStreets(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData> const & cache);
std::shared_ptr<cache::IntermediateData const> const & cache);
// TranslatorInterface overrides:
std::shared_ptr<TranslatorInterface> Clone() const override;