| 37 | } |
| 38 | |
| 39 | void WriteCitiesIdsSectionToFile(std::string const & dataPath, |
| 40 | ankerl::unordered_dense::map<uint32_t, base::GeoObjectId> const & mapping) |
| 41 | { |
| 42 | indexer::FeatureIdToGeoObjectIdBimapMem map; |
| 43 | auto const localities = generator::GetLocalities(dataPath); |
| 44 | localities.ForEach([&](uint64_t fid64) |
| 45 | { |
| 46 | auto const fid = base::checked_cast<uint32_t>(fid64); |
| 47 | auto const it = mapping.find(fid); |
| 48 | if (it == mapping.end()) |
| 49 | return; |
| 50 | |
| 51 | auto const osmId = it->second; |
| 52 | if (!map.Add(fid, osmId)) |
| 53 | { |
| 54 | uint32_t oldFid; |
| 55 | base::GeoObjectId oldOsmId; |
| 56 | auto const hasOldOsmId = map.GetValue(fid, oldOsmId); |
| 57 | auto const hasOldFid = map.GetKey(osmId, oldFid); |
| 58 | |
| 59 | LOG(LWARNING, ("Could not add the pair (", fid, ",", osmId, |
| 60 | ") to the cities ids section; old fid:", (hasOldFid ? DebugPrint(oldFid) : "none"), |
| 61 | "old osmId:", (hasOldOsmId ? DebugPrint(oldOsmId) : "none"))); |
| 62 | } |
| 63 | }); |
| 64 | |
| 65 | FilesContainerW container(dataPath, FileWriter::OP_WRITE_EXISTING); |
| 66 | // Note that we only store cities ids but nothing stops us from |
| 67 | // generalizing the section if we need, so a more generic tag is used. |
| 68 | auto sink = container.GetWriter(FEATURE_TO_OSM_FILE_TAG); |
| 69 | auto const pos0 = sink->Pos(); |
| 70 | indexer::FeatureIdToGeoObjectIdSerDes::Serialize(*sink, map); |
| 71 | auto const pos1 = sink->Pos(); |
| 72 | |
| 73 | LOG(LINFO, ("Serialized cities ids. Number of entries:", map.Size(), "Size in bytes:", pos1 - pos0)); |
| 74 | } |
| 75 | } // namespace |
| 76 | |
| 77 | namespace generator |