From 9ae77b5a3accd7bd4fd3c529a1567279fda95004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 28 Oct 2023 15:24:53 +0200 Subject: Storage: generalize predecessor helpers --- include/erebos/storage.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/erebos/storage.h b/include/erebos/storage.h index 8a701e9..3feb22b 100644 --- a/include/erebos/storage.h +++ b/include/erebos/storage.h @@ -580,17 +580,23 @@ std::vector> Stored::previous() const } template -bool Stored::precedes(const Stored & other) const +bool precedes(const T & ancestor, const T & descendant) { - for (const auto & x : other.previous()) { - if (*this == x || precedes(x)) + for (const auto & x : descendant.previous()) { + if (ancestor == x || precedes(ancestor, x)) return true; } return false; } template -void filterAncestors(std::vector> & xs) +bool Stored::precedes(const Stored & other) const +{ + return erebos::precedes(*this, other); +} + +template +void filterAncestors(std::vector & xs) { if (xs.size() < 2) return; @@ -598,19 +604,19 @@ void filterAncestors(std::vector> & xs) std::sort(xs.begin(), xs.end()); xs.erase(std::unique(xs.begin(), xs.end()), xs.end()); - std::vector> old; + std::vector old; old.swap(xs); for (auto i = old.begin(); i != old.end(); i++) { bool add = true; for (const auto & x : xs) - if (i->precedes(x)) { + if (precedes(*i, x)) { add = false; break; } if (add) for (auto j = i + 1; j != old.end(); j++) - if (i->precedes(*j)) { + if (precedes(*i, *j)) { add = false; break; } -- cgit v1.2.3