39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
// See guid_diff.h.
|
||
|
||
#include "core/view/guid_diff.h"
|
||
|
||
#include <algorithm>
|
||
|
||
namespace reasampler::view {
|
||
|
||
std::vector<std::string> newGuids(const std::set<std::string>& previous,
|
||
const std::set<std::string>& current) {
|
||
std::vector<std::string> added;
|
||
for (const std::string& g : current) {
|
||
if (g.empty()) continue; // never tag a GUID-read failure
|
||
if (previous.count(g) == 0) added.push_back(g);
|
||
}
|
||
return added;
|
||
}
|
||
|
||
std::vector<std::string> GuidBaseline::observe(const std::set<std::string>& current) {
|
||
if (!primed_) {
|
||
baseline_ = current;
|
||
primed_ = true;
|
||
return {};
|
||
}
|
||
std::vector<std::string> added = newGuids(baseline_, current);
|
||
// Assign `current`, not baseline_ ∪ added: a deleted GUID drops out of the
|
||
// baseline, so a later reused GUID is detected again rather than looking
|
||
// pre-existing.
|
||
baseline_ = current;
|
||
return added;
|
||
}
|
||
|
||
void GuidBaseline::reset() {
|
||
baseline_.clear();
|
||
primed_ = false;
|
||
}
|
||
|
||
} // namespace reasampler::view
|