3cfa9239d2
Add REAPER-free/filesystem-free prune orphan-set core + additive BankBook::referencedPaths() union query, with full unit coverage.
37 lines
1.8 KiB
C++
37 lines
1.8 KiB
C++
#include "prune_reconcile.h"
|
||
|
||
#include <unordered_set>
|
||
|
||
// 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<std::string> pruneOrphans(const std::vector<std::string>& present,
|
||
const std::vector<std::string>& referenced,
|
||
const std::vector<std::string>& 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<std::string> referencedSet(referenced.begin(),
|
||
referenced.end());
|
||
const std::unordered_set<std::string> ownedSet(owned.begin(), owned.end());
|
||
|
||
std::vector<std::string> orphans;
|
||
std::unordered_set<std::string> 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
|