OpenASIP  2.0
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Interpolation Class Reference

#include <Interpolation.hh>

Inheritance diagram for Interpolation:
Inheritance graph
Collaboration diagram for Interpolation:
Collaboration graph

Classes

struct  Pair
 

Public Member Functions

 Interpolation (const EntryKeyFieldProperty *type)
 
virtual ~Interpolation ()
 
void quickFilter (const CostDBEntryKey &, CostDBTypes::EntryTable &)
 
void filter (const CostDBEntryKey &searchKey, CostDBTypes::EntryTable &components)
 
- Public Member Functions inherited from Matcher
 Matcher (const EntryKeyFieldProperty *type)
 
virtual ~Matcher ()
 

Private Member Functions

 Interpolation (const Interpolation &)
 Copying not allowed. More...
 
Interpolationoperator= (const Interpolation &)
 Assignment not allowed. More...
 

Private Attributes

CostDBTypes::EntryTable created_
 Entries created during interpolation. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Matcher
const EntryKeyFieldPropertyfieldType () const
 
bool onlyThisFieldDiffers (const EntryKeyFieldProperty *type, const CostDBEntry &entry1, const CostDBEntry &entry2) const
 

Detailed Description

Implementation for searching database entries.

If a value equal to the search key in the requested field is not found, interpolation of the smaller and greater field value is tried.

Definition at line 49 of file Interpolation.hh.

Constructor & Destructor Documentation

◆ Interpolation() [1/2]

Interpolation::Interpolation ( const EntryKeyFieldProperty type)

Constructor.

Parameters
typeType of the field.

Definition at line 46 of file Interpolation.cc.

46  :
47  Matcher(type) {
48 }

◆ ~Interpolation()

Interpolation::~Interpolation ( )
virtual

Destructor.

Deallocates memory reserved for entries created during interpolation.

Definition at line 55 of file Interpolation.cc.

55  {
56 
57  for (CostDBTypes::EntryTable::iterator i = created_.begin();
58  i != created_.end(); i++) {
59 
60  assert(*i != NULL);
61  delete *i;
62  *i = NULL;
63  }
64 }

References assert, and created_.

◆ Interpolation() [2/2]

Interpolation::Interpolation ( const Interpolation )
private

Copying not allowed.

Member Function Documentation

◆ filter()

void Interpolation::filter ( const CostDBEntryKey searchKey,
CostDBTypes::EntryTable components 
)
virtual

Searches for database entries.

If a value equal to the search key in the requested field is not found, interpolation of the smaller and greater field value is applied. Only the best matches are returned, i.e. equal match is chosen and no interpolation is done, or if two entries has only the field to which search is applied different, the closer one to the search key is chosen for interpolation.

Parameters
searchKeySearch key.
componentsEntries from which to find. Updated to contain entries that matched the search request.
Exceptions
TypeMismatchInterpolation was requested for field that cannot be interpolated.
KeyNotFoundSome CostDBEntryStats have no value caused by missing cost data.

Implements Matcher.

Definition at line 92 of file Interpolation.cc.

93  {
94  vector<Pair> entries;
95  EntryKeyField searchField = searchKey.keyFieldOfType(*fieldType());
96  for (CostDBTypes::EntryTable::iterator i = components.begin();
97  i != components.end(); i++) {
98 
99  EntryKeyField field = (*i)->keyFieldOfType(*fieldType());
100  bool newPair = true;
101  for (vector<Pair>::iterator p = entries.begin();
102  p != entries.end(); p++) {
103 
104  if ((p->smaller != 0 &&
105  !onlyThisFieldDiffers(fieldType(), *(p->smaller), *(*i))) ||
106  (p->greater != 0 &&
107  !onlyThisFieldDiffers(fieldType(), *(p->greater), *(*i)))) {
108 
109  continue;
110  }
111  if (field.isEqual(searchField)) {
112  p->smaller = *i;
113  p->greater = 0;
114  } else if (field.isSmaller(searchField)) {
115  if (p->smaller == 0 ||
116  (p->smaller != 0 &&
117  field.isGreater(
118  p->smaller->keyFieldOfType(*fieldType())))) {
119 
120  p->smaller = *i;
121  }
122  } else {
123  if (!(field.isGreater(searchField))) {
124  throw TypeMismatch(__FILE__, __LINE__,
125  "Interpolation::filter");
126  }
127  if (p->greater == 0 ||
128  (p->greater != 0 &&
129  field.isSmaller(
130  p->greater->keyFieldOfType(*fieldType())))) {
131 
132  p->greater = *i;
133  }
134  }
135  newPair = false;
136  break;
137  }
138  if (newPair) {
139  Pair pair;
140  if (field.isEqual(searchField)) {
141  pair.smaller = *i;
142  pair.greater = 0;
143  } else if (field.isSmaller(searchField)) {
144  pair.smaller = *i;
145  pair.greater = 0;
146  } else {
147  if (!(field.isGreater(searchField))) {
148  throw TypeMismatch(__FILE__, __LINE__,
149  "Interpolation::filter");
150  }
151  pair.greater = *i;
152  pair.smaller = 0;
153  }
154  entries.push_back(pair);
155  }
156  }
157  CostDBTypes::EntryTable filtered;
158  for (vector<Pair>::iterator p = entries.begin(); p != entries.end(); p++) {
159  if (p->smaller != 0 &&
160  p->smaller->keyFieldOfType(*fieldType()).isEqual(searchField)) {
161  filtered.push_back(p->smaller);
162  } else if (p->smaller != 0 && p->greater != 0) {
163  CostDBEntry* newEntry = new CostDBEntry(
164  *p->smaller, *p->greater, searchField);
165  filtered.push_back(newEntry);
166  created_.push_back(newEntry);
167  }
168  }
169  components = filtered;
170 }

References created_, Matcher::fieldType(), Interpolation::Pair::greater, EntryKeyField::isEqual(), EntryKeyField::isGreater(), EntryKeyField::isSmaller(), CostDBEntryKey::keyFieldOfType(), Matcher::onlyThisFieldDiffers(), and Interpolation::Pair::smaller.

Here is the call graph for this function:

◆ operator=()

Interpolation& Interpolation::operator= ( const Interpolation )
private

Assignment not allowed.

◆ quickFilter()

void Interpolation::quickFilter ( const CostDBEntryKey ,
CostDBTypes::EntryTable  
)
virtual

Nothing to do since no entry can be removed in linear time.

Implements Matcher.

Definition at line 70 of file Interpolation.cc.

70  {
71 }

Member Data Documentation

◆ created_

CostDBTypes::EntryTable Interpolation::created_
private

Entries created during interpolation.

Definition at line 70 of file Interpolation.hh.

Referenced by filter(), and ~Interpolation().


The documentation for this class was generated from the following files:
Matcher::Matcher
Matcher(const EntryKeyFieldProperty *type)
Definition: Matcher.cc:44
CostDBTypes::EntryTable
std::vector< CostDBEntry * > EntryTable
Table of database entries.
Definition: CostDBTypes.hh:111
EntryKeyField
Definition: EntryKeyField.hh:45
Interpolation::created_
CostDBTypes::EntryTable created_
Entries created during interpolation.
Definition: Interpolation.hh:70
EntryKeyField::isGreater
bool isGreater(const EntryKeyField &field) const
Definition: EntryKeyField.cc:103
Matcher::fieldType
const EntryKeyFieldProperty * fieldType() const
assert
#define assert(condition)
Definition: Application.hh:86
CostDBEntry
Definition: CostDBEntry.hh:52
TypeMismatch
Definition: Exception.hh:803
Matcher::onlyThisFieldDiffers
bool onlyThisFieldDiffers(const EntryKeyFieldProperty *type, const CostDBEntry &entry1, const CostDBEntry &entry2) const
Definition: Matcher.cc:64
CostDBEntryKey::keyFieldOfType
EntryKeyField keyFieldOfType(const EntryKeyFieldProperty &fieldType) const
Definition: CostDBEntryKey.cc:123
EntryKeyField::isEqual
bool isEqual(const EntryKeyField &field) const
Definition: EntryKeyField.cc:92
EntryKeyField::isSmaller
bool isSmaller(const EntryKeyField &field) const
Definition: EntryKeyField.cc:114