diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2023-10-28 15:24:53 +0200 | 
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-10-28 22:31:17 +0200 | 
| commit | 9ae77b5a3accd7bd4fd3c529a1567279fda95004 (patch) | |
| tree | 50bd879ae4ca0e0a2120004798158e8fa6c83797 | |
| parent | 0b6891ec4a53817b825c557f374cce62bbd79128 (diff) | |
Storage: generalize predecessor helpers
| -rw-r--r-- | include/erebos/storage.h | 20 | 
1 files changed, 13 insertions, 7 deletions
| 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<T>> Stored<T>::previous() const  }  template<typename T> -bool Stored<T>::precedes(const Stored<T> & 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<typename T> -void filterAncestors(std::vector<Stored<T>> & xs) +bool Stored<T>::precedes(const Stored<T> & other) const +{ +	return erebos::precedes(*this, other); +} + +template<typename T> +void filterAncestors(std::vector<T> & xs)  {  	if (xs.size() < 2)  		return; @@ -598,19 +604,19 @@ void filterAncestors(std::vector<Stored<T>> & xs)  	std::sort(xs.begin(), xs.end());  	xs.erase(std::unique(xs.begin(), xs.end()), xs.end()); -	std::vector<Stored<T>> old; +	std::vector<T> 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;  				} |