2 * Copyright (C) 2014 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <utils/KeyedVector.h>
18 #include <utils/SortedVector.h>
19 #include <utils/Vector.h>
23 #include "RuleGenerator.h"
24 #include "SplitSelector.h"
28 using namespace android;
30 SplitSelector::SplitSelector() {
33 SplitSelector::SplitSelector(const Vector<SplitDescription>& splits)
34 : mGroups(groupByMutualExclusivity(splits)) {
37 static void selectBestFromGroup(const SortedVector<SplitDescription>& splits,
38 const SplitDescription& target, Vector<SplitDescription>& splitsOut) {
39 SplitDescription bestSplit;
41 const size_t splitCount = splits.size();
42 for (size_t j = 0; j < splitCount; j++) {
43 const SplitDescription& thisSplit = splits[j];
44 if (!thisSplit.match(target)) {
48 if (!isSet || thisSplit.isBetterThan(bestSplit, target)) {
50 bestSplit = thisSplit;
55 splitsOut.add(bestSplit);
59 Vector<SplitDescription> SplitSelector::getBestSplits(const SplitDescription& target) const {
60 Vector<SplitDescription> bestSplits;
61 const size_t groupCount = mGroups.size();
62 for (size_t i = 0; i < groupCount; i++) {
63 selectBestFromGroup(mGroups[i], target, bestSplits);
68 KeyedVector<SplitDescription, sp<Rule> > SplitSelector::getRules() const {
69 KeyedVector<SplitDescription, sp<Rule> > rules;
71 const size_t groupCount = mGroups.size();
72 for (size_t i = 0; i < groupCount; i++) {
73 const SortedVector<SplitDescription>& splits = mGroups[i];
74 const size_t splitCount = splits.size();
75 for (size_t j = 0; j < splitCount; j++) {
76 sp<Rule> rule = Rule::simplify(RuleGenerator::generate(splits, j));
78 rules.add(splits[j], rule);