B5: sample-remove verb — index-only drop, this-bank scope, confirm-on-last-reference

This commit is contained in:
2026-07-26 15:07:41 -04:00
parent 22f07d0654
commit 6c1efa0f25
5 changed files with 373 additions and 18 deletions
+33
View File
@@ -281,6 +281,39 @@ TransferResult BankBook::copySample(const std::string& sampleId,
return applyDestAdd(to->index, copy, TransferResult::Copied);
}
// ---------------------------------------------------------------------------
// Sample removal (index-only) + the last-reference query
// ---------------------------------------------------------------------------
RemoveResult BankBook::removeSample(const std::string& sampleId,
const std::string& fromBankId,
RemoveScope scope) {
if (scope == RemoveScope::AllBanks) {
// Latent seam: purge the id from every bank that holds it. fromBankId is
// ignored (the id is dropped book-wide). Removed iff at least one drop landed.
bool any = false;
for (auto& b : banks_)
if (b.index.remove(sampleId)) any = true;
return any ? RemoveResult::Removed : RemoveResult::RejectedSampleAbsent;
}
// ThisBank (default, the only surfaced verb): drop from the one named source bank.
Bank* from = bank(fromBankId);
if (from == nullptr) return RemoveResult::RejectedUnknownBank;
return from->index.remove(sampleId) ? RemoveResult::Removed
: RemoveResult::RejectedSampleAbsent;
}
bool BankBook::hashReferencedElsewhere(const std::string& hash,
const std::string& exceptBankId) const {
if (hash.empty()) return false; // empty hashes never dedup (mirror findByHash)
for (const auto& b : banks_) {
if (b.id == exceptBankId) continue; // the removed-from bank is excluded
if (b.index.findByHash(hash) != nullptr) return true;
}
return false;
}
// ===========================================================================
// JSON — writer
// ===========================================================================