aboutsummaryrefslogtreecommitdiff
path: root/paludis/resolver/job_requirements.cc
diff options
context:
space:
mode:
Diffstat (limited to 'paludis/resolver/job_requirements.cc')
-rw-r--r--paludis/resolver/job_requirements.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/paludis/resolver/job_requirements.cc b/paludis/resolver/job_requirements.cc
index 7fda1d098..7098f4db1 100644
--- a/paludis/resolver/job_requirements.cc
+++ b/paludis/resolver/job_requirements.cc
@@ -23,9 +23,11 @@
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/sequence-impl.hh>
#include <paludis/util/make_named_values.hh>
+#include <paludis/util/enum_iterator.hh>
#include <paludis/serialise-impl.hh>
#include <istream>
#include <ostream>
+#include <set>
using namespace paludis;
using namespace paludis::resolver;
@@ -51,6 +53,48 @@ JobRequirement::serialise(Serialiser & s) const
;
}
+namespace
+{
+ struct JobRequirementComparator
+ {
+ bool operator() (const JobRequirement & a, const JobRequirement & b)
+ {
+ if (a.job_number() < b.job_number())
+ return true;
+ if (a.job_number() > b.job_number())
+ return false;
+
+ for (EnumIterator<JobRequirementIf> t, t_end(last_jri) ; t != t_end ; ++t)
+ {
+ if (a.required_if()[*t] < b.required_if()[*t])
+ return true;
+ if (a.required_if()[*t] > b.required_if()[*t])
+ return false;
+ }
+
+ return false;
+ }
+ };
+}
+
+const std::shared_ptr<JobRequirements>
+paludis::resolver::minimise_requirements(const std::shared_ptr<const JobRequirements> & reqs)
+{
+ const std::shared_ptr<JobRequirements> result(std::make_shared<JobRequirements>());
+ std::set<JobRequirement, JobRequirementComparator> duplicates;
+
+ for (auto r(reqs->begin()), r_end(reqs->end()) ;
+ r != r_end ; ++r)
+ {
+ if (! duplicates.insert(*r).second)
+ continue;
+
+ result->push_back(*r);
+ }
+
+ return result;
+}
+
template class Sequence<JobRequirement>;
template class WrappedForwardIterator<Sequence<JobRequirement>::ConstIteratorTag, const JobRequirement>;