MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / collectSectors

Function collectSectors

lib/algorithms/readerwriter.cc:233–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231 * and bad version of the same sector, the bad version is dropped). */
232
233static std::vector<std::shared_ptr<const Sector>> collectSectors(
234 std::vector<std::shared_ptr<const Sector>>& trackSectors,
235 bool collapse_conflicts = true)
236{
237 typedef std::tuple<unsigned, unsigned, unsigned> key_t;
238 std::multimap<key_t, std::shared_ptr<const Sector>> sectors;
239
240 for (const auto& sector : trackSectors)
241 {
242 key_t sectorid = {sector->logicalCylinder,
243 sector->logicalHead,
244 sector->logicalSector};
245 sectors.insert({sectorid, sector});
246 }
247
248 std::set<std::shared_ptr<const Sector>> sector_set;
249 auto it = sectors.begin();
250 while (it != sectors.end())
251 {
252 auto ub = sectors.upper_bound(it->first);
253 auto new_sector = std::accumulate(it,
254 ub,
255 it->second,
256 [&](auto left, auto& rightit) -> std::shared_ptr<const Sector>
257 {
258 auto& right = rightit.second;
259 if ((left->status == Sector::OK) &&
260 (right->status == Sector::OK) &&
261 (left->data != right->data))
262 {
263 if (!collapse_conflicts)
264 {
265 auto s = std::make_shared<Sector>(*right);
266 s->status = Sector::CONFLICT;
267 sector_set.insert(s);
268 }
269 auto s = std::make_shared<Sector>(*left);
270 s->status = Sector::CONFLICT;
271 return s;
272 }
273 if (left->status == Sector::CONFLICT)
274 return left;
275 if (right->status == Sector::CONFLICT)
276 return right;
277 if (left->status == Sector::OK)
278 return left;
279 if (right->status == Sector::OK)
280 return right;
281 return left;
282 });
283 sector_set.insert(new_sector);
284 it = ub;
285 }
286
287 return std::vector(sector_set.begin(), sector_set.end());
288}
289
290struct CombinationResult

Callers 3

combineRecordAndSectorsFunction · 0.85
readGroupFunction · 0.85
readDiskCommandFunction · 0.85

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected