Skip to content

Commit

Permalink
Review fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatiana-yan authored and mpimenov committed Oct 2, 2020
1 parent dd24ed3 commit e52d0ef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
28 changes: 14 additions & 14 deletions generator/boundary_postcodes_enricher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ namespace generator
BoundaryPostcodesEnricher::BoundaryPostcodesEnricher(std::string const & boundaryPostcodesFilename)
{
// May be absent for tests because TestMwmBuilder cannot collect data from osm elements.
if (Platform::IsFileExistsByFullPath(boundaryPostcodesFilename))
if (!Platform::IsFileExistsByFullPath(boundaryPostcodesFilename))
return;

FileReader reader(boundaryPostcodesFilename);
ReaderSource<FileReader> src(reader);

while (src.Size() > 0)
{
FileReader reader(boundaryPostcodesFilename);
ReaderSource<FileReader> src(reader);

while (src.Size() > 0)
{
std::string postcode;
utils::ReadString(src, postcode);
std::vector<m2::PointD> geometry;
rw::ReadVectorOfPOD(src, geometry);
m_boundaryPostcodes.emplace_back(std::move(postcode), std::move(geometry));
m_boundariesTree.Add(m_boundaryPostcodes.size() - 1,
m_boundaryPostcodes.back().second.GetRect());
}
std::string postcode;
utils::ReadString(src, postcode);
std::vector<m2::PointD> geometry;
rw::ReadVectorOfPOD(src, geometry);
m_boundaryPostcodes.emplace_back(std::move(postcode), std::move(geometry));
m_boundariesTree.Add(m_boundaryPostcodes.size() - 1,
m_boundaryPostcodes.back().second.GetRect());
}
};

Expand Down
24 changes: 13 additions & 11 deletions indexer/metadata_serdes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void MetadataDeserializer::Header::Read(Reader & reader)

bool MetadataDeserializer::Get(uint32_t id, feature::MetadataBase & meta)
{
vector<pair<uint8_t, uint32_t>> metaIds;
MetaIds metaIds;
if (!m_map->GetThreadsafe(id, metaIds))
return false;

Expand Down Expand Up @@ -60,9 +60,9 @@ unique_ptr<MetadataDeserializer> MetadataDeserializer::Load(Reader & reader)
if (!deserializer->m_mapSubreader)
return {};

// Decodes block encoded by writeBlockCallback from PostcodesBuilder::Freeze.
// Decodes block encoded by writeBlockCallback from MetadataBuilder::Freeze.
auto const readBlockCallback = [&](NonOwningReaderSource & source, uint32_t blockSize,
vector<vector<pair<uint8_t, uint32_t>>> & values) {
vector<MetaIds> & values) {
// We may have some unused values it the tail of the last block but it's ok because
// default block size is 64.
values.resize(blockSize);
Expand Down Expand Up @@ -92,7 +92,7 @@ unique_ptr<MetadataDeserializer> MetadataDeserializer::Load(Reader & reader)
// MetadataBuilder -----------------------------------------------------------------------------
void MetadataBuilder::Put(uint32_t featureId, feature::MetadataBase const & meta)
{
vector<pair<uint8_t, uint32_t>> metaIds;
MetadataDeserializer::MetaIds metaIds;
for (auto const & type : meta.GetPresentTypes())
{
uint32_t id = 0;
Expand Down Expand Up @@ -148,16 +148,18 @@ void MetadataBuilder::Freeze(Writer & writer) const
auto const writeBlockCallback = [](auto & w, auto begin, auto end) {
for (auto it = begin; it != end; ++it)
{
// |*it| is vector<pair<uint8_t, uint32_t>>
CHECK_GREATER(it->size(), 0, ());
WriteVarUint(w, it->size());
for (auto const & kv : *it)
MetadataDeserializer::MetaIds const & metaIds = *it;
CHECK_GREATER(metaIds.size(), 0, ());
WriteVarUint(w, metaIds.size());
for (auto const & kv : metaIds)
WriteToSink(w, kv.first);

WriteVarUint(w, (*it)[0].second);
WriteVarUint(w, metaIds[0].second);
for (size_t i = 1; i < it->size(); ++i)
WriteVarInt(
w, static_cast<int32_t>((*it)[i].second) - static_cast<int32_t>((*it)[i - 1].second));
{
WriteVarInt(w, static_cast<int32_t>(metaIds[i].second) -
static_cast<int32_t>(metaIds[i - 1].second));
}
}
};
m_builder.Freeze(writer, writeBlockCallback);
Expand Down
8 changes: 6 additions & 2 deletions indexer/metadata_serdes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class MetadataDeserializer
uint32_t m_metadataMapSize = 0;
};

// Vector of metadata ids. Each element first is meta type, second is metadata value id inside
// string storage.
using MetaIds = std::vector<std::pair<uint8_t, uint32_t>>;

static std::unique_ptr<MetadataDeserializer> Load(Reader & reader);

// Tries to get metadata of the feature with id |featureId|. Returns false if table
Expand All @@ -63,7 +67,7 @@ class MetadataDeserializer
WARN_UNUSED_RESULT bool Get(uint32_t featureId, feature::MetadataBase & meta);

private:
using Map = MapUint32ToValue<std::vector<std::pair<uint8_t, uint32_t>>>;
using Map = MapUint32ToValue<MetaIds>;

std::unique_ptr<Reader> m_stringsSubreader;
coding::BlockedTextStorageReader m_strings;
Expand All @@ -82,6 +86,6 @@ class MetadataBuilder
private:
std::unordered_map<std::string, uint32_t> m_stringToId;
std::unordered_map<uint32_t, std::string> m_idToString;
MapUint32ToValueBuilder<std::vector<std::pair<uint8_t, uint32_t>>> m_builder;
MapUint32ToValueBuilder<MetadataDeserializer::MetaIds> m_builder;
};
} // namespace indexer
2 changes: 1 addition & 1 deletion platform/mwm_version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum class Format
v10, // April 2020 (dat section renamed to features, compressed metadata index, addr section with
// header, sdx section with header, dat section renamed to features, features section with
// header).
v11, // September 2020 (complessed string storage for metadata).
v11, // September 2020 (compressed string storage for metadata).
lastFormat = v11
};

Expand Down

0 comments on commit e52d0ef

Please sign in to comment.