mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 04:53:36 +00:00
Format all C++ and Java code via clang-format
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "base/checked_cast.hpp"
|
||||
|
||||
#include <future>
|
||||
#include <execution>
|
||||
#include <future>
|
||||
|
||||
namespace generator::cache
|
||||
{
|
||||
@@ -62,9 +62,7 @@ protected:
|
||||
class RawFilePointStorageMmapReader : public PointStorageReaderInterface
|
||||
{
|
||||
public:
|
||||
explicit RawFilePointStorageMmapReader(string const & name)
|
||||
: m_mmapReader(name, MmapReader::Advice::Random)
|
||||
{}
|
||||
explicit RawFilePointStorageMmapReader(string const & name) : m_mmapReader(name, MmapReader::Advice::Random) {}
|
||||
|
||||
// PointStorageReaderInterface overrides:
|
||||
bool GetPoint(uint64_t id, double & lat, double & lon) const override
|
||||
@@ -85,9 +83,7 @@ private:
|
||||
class RawFilePointStorageWriter : public PointStorageWriterBase
|
||||
{
|
||||
public:
|
||||
explicit RawFilePointStorageWriter(string const & name)
|
||||
: m_fileWriter(name)
|
||||
{}
|
||||
explicit RawFilePointStorageWriter(string const & name) : m_fileWriter(name) {}
|
||||
|
||||
// PointStorageWriterInterface overrides:
|
||||
void AddPoint(uint64_t id, double lat, double lon) override
|
||||
@@ -108,8 +104,7 @@ private:
|
||||
class RawMemPointStorageReader : public PointStorageReaderInterface
|
||||
{
|
||||
public:
|
||||
explicit RawMemPointStorageReader(string const & name)
|
||||
: m_fileReader(name)
|
||||
explicit RawMemPointStorageReader(string const & name) : m_fileReader(name)
|
||||
{
|
||||
uint64_t const fileSize = m_fileReader.Size();
|
||||
CHECK_EQUAL(fileSize % sizeof(LatLon), 0, ("Node's coordinates file is broken"));
|
||||
@@ -141,16 +136,9 @@ class RawMemPointStorageWriter : public PointStorageWriterBase
|
||||
static constexpr size_t kBufferSize = 1000000000;
|
||||
|
||||
public:
|
||||
explicit RawMemPointStorageWriter(string const & name)
|
||||
: m_fileWriter(name)
|
||||
{
|
||||
m_buffer.reserve(kBufferSize);
|
||||
}
|
||||
explicit RawMemPointStorageWriter(string const & name) : m_fileWriter(name) { m_buffer.reserve(kBufferSize); }
|
||||
|
||||
~RawMemPointStorageWriter() noexcept(false) override
|
||||
{
|
||||
Flush();
|
||||
}
|
||||
~RawMemPointStorageWriter() noexcept(false) override { Flush(); }
|
||||
|
||||
// PointStorageWriterInterface overrides:
|
||||
void AddPoint(uint64_t id, double lat, double lon) override
|
||||
@@ -173,11 +161,8 @@ private:
|
||||
// Sort, according to the seek pos in file.
|
||||
|
||||
/// @todo Try parallel sort when clang will be able.
|
||||
//std::sort(std::execution::par, buffer.begin(), buffer.end(), [](LatLonPos const & l, LatLonPos const & r)
|
||||
std::sort(buffer.begin(), buffer.end(), [](LatLonPos const & l, LatLonPos const & r)
|
||||
{
|
||||
return l.m_pos < r.m_pos;
|
||||
});
|
||||
// std::sort(std::execution::par, buffer.begin(), buffer.end(), [](LatLonPos const & l, LatLonPos const & r)
|
||||
std::sort(buffer.begin(), buffer.end(), [](LatLonPos const & l, LatLonPos const & r) { return l.m_pos < r.m_pos; });
|
||||
|
||||
size_t constexpr structSize = sizeof(LatLon);
|
||||
for (auto const & llp : buffer)
|
||||
@@ -219,10 +204,7 @@ private:
|
||||
uint64_t m_pos = 0;
|
||||
|
||||
public:
|
||||
explicit CachedPosWriter(std::string const & fPath) : m_writer(fPath)
|
||||
{
|
||||
CHECK_EQUAL(m_pos, m_writer.Pos(), ());
|
||||
}
|
||||
explicit CachedPosWriter(std::string const & fPath) : m_writer(fPath) { CHECK_EQUAL(m_pos, m_writer.Pos(), ()); }
|
||||
|
||||
void Write(uint64_t pos, void const * p, size_t size)
|
||||
{
|
||||
@@ -245,8 +227,7 @@ private:
|
||||
class MapFilePointStorageReader : public PointStorageReaderInterface
|
||||
{
|
||||
public:
|
||||
explicit MapFilePointStorageReader(string const & name)
|
||||
: m_fileReader(name + kShortExtension)
|
||||
explicit MapFilePointStorageReader(string const & name) : m_fileReader(name + kShortExtension)
|
||||
{
|
||||
LOG(LINFO, ("Nodes reading is started"));
|
||||
|
||||
@@ -273,10 +254,7 @@ public:
|
||||
return false;
|
||||
bool ret = FromLatLon(i->second, lat, lon);
|
||||
if (!ret)
|
||||
{
|
||||
LOG(LERROR, ("Inconsistent MapFilePointStorageReader. Node with id =", id,
|
||||
"must exist but was not found"));
|
||||
}
|
||||
LOG(LERROR, ("Inconsistent MapFilePointStorageReader. Node with id =", id, "must exist but was not found"));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -288,10 +266,7 @@ private:
|
||||
class MapFilePointStorageWriter : public PointStorageWriterBase
|
||||
{
|
||||
public:
|
||||
explicit MapFilePointStorageWriter(string const & name)
|
||||
: m_fileWriter(name + kShortExtension)
|
||||
{
|
||||
}
|
||||
explicit MapFilePointStorageWriter(string const & name) : m_fileWriter(name + kShortExtension) {}
|
||||
|
||||
// PointStorageWriterInterface overrides:
|
||||
void AddPoint(uint64_t id, double lat, double lon) override
|
||||
@@ -351,10 +326,7 @@ bool IndexFileReader::GetValueByKey(Key key, Value & value) const
|
||||
}
|
||||
|
||||
// IndexFileWriter ---------------------------------------------------------------------------------
|
||||
IndexFileWriter::IndexFileWriter(string const & name) :
|
||||
m_fileWriter(name)
|
||||
{
|
||||
}
|
||||
IndexFileWriter::IndexFileWriter(string const & name) : m_fileWriter(name) {}
|
||||
|
||||
void IndexFileWriter::WriteAll()
|
||||
{
|
||||
@@ -390,15 +362,18 @@ OSMElementCacheReader::OSMElementCacheReader(IntermediateDataObjectsCache::Alloc
|
||||
|
||||
// OSMElementCacheWriter ---------------------------------------------------------------------------
|
||||
OSMElementCacheWriter::OSMElementCacheWriter(string const & name)
|
||||
: m_fileWriter(name), m_offsets(name + OFFSET_EXT), m_name(name)
|
||||
: m_fileWriter(name)
|
||||
, m_offsets(name + OFFSET_EXT)
|
||||
, m_name(name)
|
||||
{}
|
||||
|
||||
void OSMElementCacheWriter::SaveOffsets()
|
||||
{
|
||||
m_offsets.WriteAll();
|
||||
}
|
||||
|
||||
void OSMElementCacheWriter::SaveOffsets() { m_offsets.WriteAll(); }
|
||||
|
||||
// IntermediateDataObjectsCache --------------------------------------------------------------------
|
||||
IntermediateDataObjectsCache::AllocatedObjects &
|
||||
IntermediateDataObjectsCache::GetOrCreatePointStorageReader(
|
||||
IntermediateDataObjectsCache::AllocatedObjects & IntermediateDataObjectsCache::GetOrCreatePointStorageReader(
|
||||
feature::GenerateInfo::NodeStorageType type, string const & name)
|
||||
{
|
||||
auto const strType = std::to_string(static_cast<int>(type));
|
||||
@@ -418,14 +393,13 @@ void IntermediateDataObjectsCache::Clear()
|
||||
std::unordered_map<string, AllocatedObjects>().swap(m_objects);
|
||||
}
|
||||
|
||||
IntermediateDataObjectsCache::AllocatedObjects::AllocatedObjects(
|
||||
feature::GenerateInfo::NodeStorageType type, string const & name)
|
||||
IntermediateDataObjectsCache::AllocatedObjects::AllocatedObjects(feature::GenerateInfo::NodeStorageType type,
|
||||
string const & name)
|
||||
{
|
||||
m_storageReader = CreatePointStorageReader(type, name);
|
||||
}
|
||||
|
||||
IndexFileReader const & IntermediateDataObjectsCache::AllocatedObjects::GetOrCreateIndexReader(
|
||||
std::string const & name)
|
||||
IndexFileReader const & IntermediateDataObjectsCache::AllocatedObjects::GetOrCreateIndexReader(std::string const & name)
|
||||
{
|
||||
static std::mutex m;
|
||||
std::lock_guard lock(m);
|
||||
@@ -434,20 +408,18 @@ IndexFileReader const & IntermediateDataObjectsCache::AllocatedObjects::GetOrCre
|
||||
}
|
||||
|
||||
// IntermediateDataReader --------------------------------------------------------------------------
|
||||
IntermediateDataReader::IntermediateDataReader(
|
||||
IntermediateDataObjectsCache::AllocatedObjects & objs, feature::GenerateInfo const & info)
|
||||
IntermediateDataReader::IntermediateDataReader(IntermediateDataObjectsCache::AllocatedObjects & objs,
|
||||
feature::GenerateInfo const & info)
|
||||
: m_nodes(objs.GetPointStorageReader())
|
||||
, m_ways(objs, info.GetCacheFileName(WAYS_FILE), info.m_preloadCache)
|
||||
, m_relations(objs, info.GetCacheFileName(RELATIONS_FILE), info.m_preloadCache)
|
||||
, m_nodeToRelations(objs.GetOrCreateIndexReader(info.GetCacheFileName(NODES_FILE, ID2REL_EXT)))
|
||||
, m_wayToRelations(objs.GetOrCreateIndexReader(info.GetCacheFileName(WAYS_FILE, ID2REL_EXT)))
|
||||
, m_relationToRelations(
|
||||
objs.GetOrCreateIndexReader(info.GetCacheFileName(RELATIONS_FILE, ID2REL_EXT)))
|
||||
, m_relationToRelations(objs.GetOrCreateIndexReader(info.GetCacheFileName(RELATIONS_FILE, ID2REL_EXT)))
|
||||
{}
|
||||
|
||||
// IntermediateDataWriter --------------------------------------------------------------------------
|
||||
IntermediateDataWriter::IntermediateDataWriter(PointStorageWriterInterface & nodes,
|
||||
feature::GenerateInfo const & info)
|
||||
IntermediateDataWriter::IntermediateDataWriter(PointStorageWriterInterface & nodes, feature::GenerateInfo const & info)
|
||||
: m_nodes(nodes)
|
||||
, m_ways(info.GetCacheFileName(WAYS_FILE))
|
||||
, m_relations(info.GetCacheFileName(RELATIONS_FILE))
|
||||
@@ -458,8 +430,8 @@ IntermediateDataWriter::IntermediateDataWriter(PointStorageWriterInterface & nod
|
||||
|
||||
void IntermediateDataWriter::AddRelation(Key id, RelationElement const & e)
|
||||
{
|
||||
static std::set<std::string_view> const types = {"multipolygon", "route", "boundary",
|
||||
"associatedStreet", "building", "restriction"};
|
||||
static std::set<std::string_view> const types = {"multipolygon", "route", "boundary",
|
||||
"associatedStreet", "building", "restriction"};
|
||||
auto const relationType = e.GetType();
|
||||
if (!types.count(relationType))
|
||||
return;
|
||||
@@ -481,43 +453,36 @@ void IntermediateDataWriter::SaveIndex()
|
||||
}
|
||||
|
||||
// Functions
|
||||
std::unique_ptr<PointStorageReaderInterface>
|
||||
CreatePointStorageReader(feature::GenerateInfo::NodeStorageType type, string const & name)
|
||||
std::unique_ptr<PointStorageReaderInterface> CreatePointStorageReader(feature::GenerateInfo::NodeStorageType type,
|
||||
string const & name)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case feature::GenerateInfo::NodeStorageType::File:
|
||||
return std::make_unique<RawFilePointStorageMmapReader>(name);
|
||||
case feature::GenerateInfo::NodeStorageType::Index:
|
||||
return std::make_unique<MapFilePointStorageReader>(name);
|
||||
case feature::GenerateInfo::NodeStorageType::Memory:
|
||||
return std::make_unique<RawMemPointStorageReader>(name);
|
||||
case feature::GenerateInfo::NodeStorageType::File: return std::make_unique<RawFilePointStorageMmapReader>(name);
|
||||
case feature::GenerateInfo::NodeStorageType::Index: return std::make_unique<MapFilePointStorageReader>(name);
|
||||
case feature::GenerateInfo::NodeStorageType::Memory: return std::make_unique<RawMemPointStorageReader>(name);
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
std::unique_ptr<PointStorageWriterInterface>
|
||||
CreatePointStorageWriter(feature::GenerateInfo::NodeStorageType type, string const & name)
|
||||
std::unique_ptr<PointStorageWriterInterface> CreatePointStorageWriter(feature::GenerateInfo::NodeStorageType type,
|
||||
string const & name)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case feature::GenerateInfo::NodeStorageType::File:
|
||||
return std::make_unique<RawFilePointStorageWriter>(name);
|
||||
case feature::GenerateInfo::NodeStorageType::Index:
|
||||
return std::make_unique<MapFilePointStorageWriter>(name);
|
||||
case feature::GenerateInfo::NodeStorageType::Memory:
|
||||
return std::make_unique<RawMemPointStorageWriter>(name);
|
||||
case feature::GenerateInfo::NodeStorageType::File: return std::make_unique<RawFilePointStorageWriter>(name);
|
||||
case feature::GenerateInfo::NodeStorageType::Index: return std::make_unique<MapFilePointStorageWriter>(name);
|
||||
case feature::GenerateInfo::NodeStorageType::Memory: return std::make_unique<RawMemPointStorageWriter>(name);
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
IntermediateData::IntermediateData(IntermediateDataObjectsCache & objectsCache,
|
||||
feature::GenerateInfo const & info)
|
||||
IntermediateData::IntermediateData(IntermediateDataObjectsCache & objectsCache, feature::GenerateInfo const & info)
|
||||
: m_objectsCache(objectsCache)
|
||||
, m_info(info)
|
||||
{
|
||||
auto & allocatedObjects = m_objectsCache.GetOrCreatePointStorageReader(
|
||||
info.m_nodeStorageType, info.GetCacheFileName(NODES_FILE));
|
||||
auto & allocatedObjects =
|
||||
m_objectsCache.GetOrCreatePointStorageReader(info.m_nodeStorageType, info.GetCacheFileName(NODES_FILE));
|
||||
m_reader = std::make_shared<IntermediateDataReader>(allocatedObjects, info);
|
||||
}
|
||||
|
||||
@@ -530,4 +495,4 @@ std::shared_ptr<IntermediateData> IntermediateData::Clone() const
|
||||
{
|
||||
return std::make_shared<IntermediateData>(m_objectsCache, m_info);
|
||||
}
|
||||
} // namespace generator
|
||||
} // namespace generator::cache
|
||||
|
||||
Reference in New Issue
Block a user