More of Tuning Framework
[satune.git] / src / Tuner / searchtuner.cc
1 #include "searchtuner.h"
2
3 TunableSetting::TunableSetting(VarType _type, TunableParam _param) :
4         hasVar(true),
5         type(_type),
6         param(_param) {
7 }
8
9 TunableSetting::TunableSetting(TunableParam _param) :
10         hasVar(false),
11         type(0),
12         param(_param) {
13 }
14
15 void TunableSetting::setDecision(int _low, int _high, int _default, int _selection) {
16         lowValue = _low;
17         highValue = _high;
18         defaultValue = _default;
19         selectedValue = _selection;
20 }
21
22 unsigned int tunableSettingHash(TunableSetting *setting) {
23         return setting->hasVar ^ setting->type ^ setting->param;
24 }
25
26 bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2) {
27         return setting1->hasVar == setting2->hasVar &&
28                 setting1->type == setting2->type &&
29                 setting1->param == setting2->param;
30 }
31
32 SearchTuner::SearchTuner() {
33 }
34
35 SearchTuner::~SearchTuner() {
36         HSIteratorTunableSetting *iterator=settings.iterator();
37         while(iterator->hasNext()) {
38                 TunableSetting *setting=iterator->next();
39                 delete setting;
40         }
41         delete iterator;
42 }
43
44 int SearchTuner::getTunable(TunableParam param, TunableDesc *descriptor) {
45         TunableSetting setting(param);
46         TunableSetting * result = usedSettings.get(&setting);
47         if (result == NULL) {
48                 result = settings.get(&setting);
49                 if ( result == NULL) {
50                         result=new TunableSetting(param);
51                         result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, descriptor->defaultValue);
52                         settings.add(result);
53                 }
54                 usedSettings.add(result);
55         }
56         return result->selectedValue;
57 }
58
59 int SearchTuner::getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor) {
60         TunableSetting setting(vartype, param);
61         TunableSetting * result = usedSettings.get(&setting);
62         if (result == NULL) {
63                 result = settings.get(&setting);
64                 if ( result == NULL) {
65                         result=new TunableSetting(vartype, param);
66                         result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, descriptor->defaultValue);
67                         settings.add(result);
68                 }
69                 usedSettings.add(result);
70         }
71         return result->selectedValue;
72 }