#include "prune_reconcile.h" #include // prune_reconcile implementation — the one set-algebra computation, kept trivially // auditable: build the referenced and owned lookup sets, then walk `present` once, // keeping a path iff it is owned AND not referenced. Walking `present` (not owned) // gives the ∩-present clause for free and yields output in folder-enumeration order. namespace reasampler { std::vector pruneOrphans(const std::vector& present, const std::vector& referenced, const std::vector& owned) { // Exact-string membership — the model's canonical relative-path comparison // (Sample.relativePath / OwnedFileManifest::contains). std::string hashes/compares // byte-for-byte, so no normalization creeps in. const std::unordered_set referencedSet(referenced.begin(), referenced.end()); const std::unordered_set ownedSet(owned.begin(), owned.end()); std::vector orphans; std::unordered_set emitted; // de-dup repeated spellings in `present` for (const std::string& path : present) { // (owned ∩ present) − referenced: present is the walk; owned and !referenced // are the two membership tests; emitted guards against a duplicate `present`. if (ownedSet.count(path) == 0) continue; // not our leaving — skip if (referencedSet.count(path) != 0) continue; // some bank references it if (!emitted.insert(path).second) continue; // already emitted orphans.push_back(path); } return orphans; } } // namespace reasampler