feat(prune): R1 prune-reconcile pure core — (owned ∩ present) − referenced

Add REAPER-free/filesystem-free prune orphan-set core + additive
BankBook::referencedPaths() union query, with full unit coverage.
This commit is contained in:
2026-07-26 18:02:42 -04:00
parent b6464f78c8
commit 3cfa9239d2
6 changed files with 426 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
#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