MCPcopy Create free account
hub / github.com/comaps/comaps / Serialize

Method Serialize

libs/routing/cross_border_graph.hpp:103–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101// static
102template <class Sink>
103void CrossBorderGraphSerializer::Serialize(CrossBorderGraph const & graph, Sink & sink,
104 std::shared_ptr<NumMwmIds> numMwmIds)
105{
106 Header header(graph);
107 header.Serialize(sink);
108
109 std::set<uint32_t> mwmNameHashes;
110
111 for (auto it = graph.m_mwms.begin(); it != graph.m_mwms.end(); ++it)
112 {
113 auto const & mwmId = it->first;
114 std::string const & mwmName = numMwmIds->GetFile(mwmId).GetName();
115 auto const hash = Hash(mwmName);
116
117 // Triggering of this check during the maps build means that the mwm set has been changed and
118 // current hash function Hash(mwmName) no longer suits it and should be replaced.
119 CHECK(mwmNameHashes.emplace(hash).second, (mwmId, mwmName, hash));
120 }
121
122 CHECK_LESS(mwmNameHashes.size(), std::numeric_limits<NumMwmId>::max(), ());
123
124 for (auto hash : mwmNameHashes)
125 WriteToSink(sink, hash);
126
127 auto writeSegEnding = [&](CrossBorderSegmentEnding const & ending)
128 {
129 auto const & coord = ending.m_point.GetLatLon();
130 WriteToSink(sink, DoubleToUint32(coord.m_lat, ms::LatLon::kMinLat, ms::LatLon::kMaxLat, kBitsForDouble));
131 WriteToSink(sink, DoubleToUint32(coord.m_lon, ms::LatLon::kMinLon, ms::LatLon::kMaxLon, kBitsForDouble));
132
133 auto const & mwmNameHash = Hash(numMwmIds->GetFile(ending.m_numMwmId).GetName());
134 auto it = mwmNameHashes.find(mwmNameHash);
135 CHECK(it != mwmNameHashes.end(), (ending.m_numMwmId, mwmNameHash));
136
137 NumMwmId const id = std::distance(mwmNameHashes.begin(), it);
138 WriteToSink(sink, id);
139 };
140
141 for (auto const & [segId, seg] : graph.m_segments)
142 {
143 WriteVarUint(sink, segId);
144
145 WriteVarUint(sink, static_cast<uint64_t>(std::lround(seg.m_weight * kDouble2Int)));
146
147 writeSegEnding(seg.m_start);
148 writeSegEnding(seg.m_end);
149 }
150}
151
152// static
153template <class Source>

Callers

nothing calls this directly

Calls 13

WriteToSinkFunction · 0.85
DoubleToUint32Function · 0.85
distanceFunction · 0.85
WriteVarUintFunction · 0.85
GetFileMethod · 0.80
HashClass · 0.70
beginMethod · 0.45
endMethod · 0.45
GetNameMethod · 0.45
emplaceMethod · 0.45
sizeMethod · 0.45
GetLatLonMethod · 0.45

Tested by

no test coverage detected