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

#include <FilterSearch.hh>

Inheritance diagram for FilterSearch:
Inheritance graph
Collaboration diagram for FilterSearch:
Collaboration graph

Classes

class  Cache
 

Public Member Functions

 FilterSearch ()
 
virtual ~FilterSearch ()
 
SearchStrategycopy () const
 
CostDBTypes::EntryTable search (const CostDBEntryKey &searchKey, CostDBTypes::EntryTable components, const CostDBTypes::MatchTypeTable &match)
 
- Public Member Functions inherited from SearchStrategy
virtual ~SearchStrategy ()
 

Private Types

typedef std::vector< Cache * > CacheTable
 Table of cache entries. More...
 
typedef std::vector< Matcher * > MatcherTable
 Table of matcher types. More...
 

Private Member Functions

CostDBTypes::EntryTable findFromCache (const CostDBEntryKey &searchKey, const CostDBTypes::MatchTypeTable &match)
 
MatcherTable createMatchers (const CostDBTypes::MatchTypeTable &match)
 
 FilterSearch (const FilterSearch &)
 Copying not allowed. More...
 
FilterSearchoperator= (const FilterSearch &)
 Assignment not allowed. More...
 

Private Attributes

CacheTable entryCache_
 Results of the previous queries. More...
 
MatcherTable matcherStorage_
 Storage for all matchers. They cannot be deleted before search strategy itself is deleted. Thus, this storage exists to deallocate the memory reserved by matchers. More...
 

Detailed Description

Implementation of the queries from the cost database.

Using the FilterSearch algorithm requires only a Search() function call.

Search is based on filtering non-matching entries out according to information of one field at a time. Thus, it is very generic accepting field changes to entries without touching to the searrch algorithms.

Cache and quick filtering is used for optimisation. Cache contains all the results from the previous queries. Quick filtering removes unneccessary entries in linear time in the beginning of the search.

Definition at line 63 of file FilterSearch.hh.

Member Typedef Documentation

◆ CacheTable

typedef std::vector<Cache*> FilterSearch::CacheTable
private

Table of cache entries.

Definition at line 106 of file FilterSearch.hh.

◆ MatcherTable

typedef std::vector<Matcher*> FilterSearch::MatcherTable
private

Table of matcher types.

Definition at line 108 of file FilterSearch.hh.

Constructor & Destructor Documentation

◆ FilterSearch() [1/2]

FilterSearch::FilterSearch ( )

Default constructor.

Definition at line 47 of file FilterSearch.cc.

47  {
48 }

Referenced by copy().

◆ ~FilterSearch()

FilterSearch::~FilterSearch ( )
virtual

Destructor.

Definition at line 53 of file FilterSearch.cc.

53  {
54 
55  for (CacheTable::iterator i = entryCache_.begin();
56  i != entryCache_.end(); i++) {
57 
58  assert(*i != NULL);
59  delete *i;
60  *i = NULL;
61  }
62  for (MatcherTable::iterator i = matcherStorage_.begin();
63  i != matcherStorage_.end(); i++) {
64 
65  assert(*i != NULL);
66  delete *i;
67  *i = NULL;
68  }
69 }

References assert, entryCache_, and matcherStorage_.

◆ FilterSearch() [2/2]

FilterSearch::FilterSearch ( const FilterSearch )
private

Copying not allowed.

Member Function Documentation

◆ copy()

SearchStrategy * FilterSearch::copy ( ) const
virtual

Returns a copy of this search strategy.

Client is responsible of deallocating the memory reserved for the returned object.

Returns
Copy of this search strategy.

Implements SearchStrategy.

Definition at line 80 of file FilterSearch.cc.

80  {
81 
82  CacheTable newEntryCache;
83  for (CacheTable::const_iterator i = entryCache_.begin();
84  i != entryCache_.end(); i++) {
85 
86  newEntryCache.push_back((*i)->copy());
87  }
88  FilterSearch* newSearch = new FilterSearch();
89  newSearch->entryCache_ = newEntryCache;
90  return newSearch;
91 }

References entryCache_, and FilterSearch().

Here is the call graph for this function:

◆ createMatchers()

FilterSearch::MatcherTable FilterSearch::createMatchers ( const CostDBTypes::MatchTypeTable match)
private

Creates sub components of this search strategy.

Parameters
matchType of match.
Returns
Sub components of this search strategy.
Exceptions
TypeMismatchRequested type is unknown.

Definition at line 179 of file FilterSearch.cc.

179  {
180  MatcherTable matcher;
181  for (CostDBTypes::MatchTypeTable::const_iterator i = match.begin();
182  i != match.end(); i++) {
183 
184  Matcher* new_matcher = NULL;
185  if ((*i)->matchingType() == CostDBTypes::MATCH_EXACT) {
186  new_matcher = new ExactMatch((*i)->fieldType());
187  } else if ((*i)->matchingType() == CostDBTypes::MATCH_SUBSET) {
188  new_matcher = new SubSet((*i)->fieldType());
189  } else if ((*i)->matchingType() == CostDBTypes::MATCH_SUPERSET) {
190  new_matcher = new SuperSet((*i)->fieldType());
191  } else if ((*i)->matchingType() == CostDBTypes::MATCH_INTERPOLATION) {
192  new_matcher = new Interpolation((*i)->fieldType());
193  } else if ((*i)->matchingType() == CostDBTypes::MATCH_ALL) {
194 
195  } else {
196  throw TypeMismatch(__FILE__, __LINE__,
197  "FilterSearch::createMatchers");
198  }
199 
200  assert(new_matcher != NULL);
201  matcherStorage_.push_back(new_matcher);
202  matcher.push_back(new_matcher);
203  }
204  return matcher;
205 }

References assert, CostDBTypes::MATCH_ALL, CostDBTypes::MATCH_EXACT, CostDBTypes::MATCH_INTERPOLATION, CostDBTypes::MATCH_SUBSET, CostDBTypes::MATCH_SUPERSET, and matcherStorage_.

Referenced by search().

◆ findFromCache()

CostDBTypes::EntryTable FilterSearch::findFromCache ( const CostDBEntryKey searchKey,
const CostDBTypes::MatchTypeTable match 
)
private

Finds entries matching search key and type of match from the cache.

Parameters
searchKeySearch key.
matchType of match.
Returns
Entries matching search key and type of match.

Definition at line 155 of file FilterSearch.cc.

157  {
158 
159  CostDBTypes::EntryTable cacheEntries;
160  for (CacheTable::iterator i = entryCache_.begin();
161  i != entryCache_.end(); i++) {
162 
163  if ((*i)->isEqual(match, &searchKey)) {
164  cacheEntries = (*i)->entries();
165  break;
166  }
167  }
168  return cacheEntries;
169 }

References entryCache_.

Referenced by search().

◆ operator=()

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

Assignment not allowed.

◆ search()

CostDBTypes::EntryTable FilterSearch::search ( const CostDBEntryKey searchKey,
CostDBTypes::EntryTable  components,
const CostDBTypes::MatchTypeTable match 
)
virtual

Searches entries that match with certain search key on a specific type of match.

Search results are valid until the strategy is deleted, after which the use of the results of the queries might lead into unexpected behaviour.

Client must not deallocate the memory reserved for the results.

Parameters
searchKeySearch key.
componentsEntries from which to find.
matchType of match. The fields are searched in the order they exist in this table.
Returns
Entries matching search key and type of match.

Implements SearchStrategy.

Definition at line 110 of file FilterSearch.cc.

113  {
114 
115  if (components.size() == 0) {
116  return components;
117  }
118 
119  // check the cache
120  CostDBTypes::EntryTable cache_entries = findFromCache(searchKey, match);
121  if (!cache_entries.empty()) {
122  return cache_entries;
123  }
124 
125  MatcherTable matcher = createMatchers(match);
126 
127  // filter quickly poor ones out
128  for (MatcherTable::const_iterator i = matcher.begin();
129  i != matcher.end(); i++) {
130 
131  (*i)->quickFilter(searchKey, components);
132  }
133 
134  // choose correct entries from acceptable ones
135  for (MatcherTable::const_iterator i = matcher.begin();
136  i != matcher.end(); i++) {
137 
138  (*i)->filter(searchKey, components);
139  }
140 
141  // insert found entries into cache
142  entryCache_.push_back(new Cache(match, searchKey.copy(), components));
143 
144  return components;
145 }

References CostDBEntryKey::copy(), createMatchers(), entryCache_, and findFromCache().

Here is the call graph for this function:

Member Data Documentation

◆ entryCache_

CacheTable FilterSearch::entryCache_
private

Results of the previous queries.

Definition at line 116 of file FilterSearch.hh.

Referenced by copy(), findFromCache(), search(), and ~FilterSearch().

◆ matcherStorage_

MatcherTable FilterSearch::matcherStorage_
private

Storage for all matchers. They cannot be deleted before search strategy itself is deleted. Thus, this storage exists to deallocate the memory reserved by matchers.

Definition at line 120 of file FilterSearch.hh.

Referenced by createMatchers(), and ~FilterSearch().


The documentation for this class was generated from the following files:
CostDBTypes::MATCH_SUPERSET
@ MATCH_SUPERSET
Definition: CostDBTypes.hh:58
ExactMatch
Definition: ExactMatch.hh:46
FilterSearch::findFromCache
CostDBTypes::EntryTable findFromCache(const CostDBEntryKey &searchKey, const CostDBTypes::MatchTypeTable &match)
Definition: FilterSearch.cc:155
SubSet
Definition: SubSet.hh:46
FilterSearch::FilterSearch
FilterSearch()
Definition: FilterSearch.cc:47
Interpolation
Definition: Interpolation.hh:49
CostDBTypes::EntryTable
std::vector< CostDBEntry * > EntryTable
Table of database entries.
Definition: CostDBTypes.hh:111
FilterSearch::MatcherTable
std::vector< Matcher * > MatcherTable
Table of matcher types.
Definition: FilterSearch.hh:108
CostDBTypes::MATCH_EXACT
@ MATCH_EXACT
Definition: CostDBTypes.hh:56
SuperSet
Definition: SuperSet.hh:46
assert
#define assert(condition)
Definition: Application.hh:86
CostDBTypes::MATCH_INTERPOLATION
@ MATCH_INTERPOLATION
Definition: CostDBTypes.hh:59
FilterSearch
Definition: FilterSearch.hh:63
TypeMismatch
Definition: Exception.hh:803
FilterSearch::entryCache_
CacheTable entryCache_
Results of the previous queries.
Definition: FilterSearch.hh:116
CostDBTypes::MATCH_ALL
@ MATCH_ALL
Definition: CostDBTypes.hh:55
FilterSearch::CacheTable
std::vector< Cache * > CacheTable
Table of cache entries.
Definition: FilterSearch.hh:106
CostDBTypes::MATCH_SUBSET
@ MATCH_SUBSET
Definition: CostDBTypes.hh:57
FilterSearch::matcherStorage_
MatcherTable matcherStorage_
Storage for all matchers. They cannot be deleted before search strategy itself is deleted....
Definition: FilterSearch.hh:120
CostDBEntryKey::copy
CostDBEntryKey * copy() const
Definition: CostDBEntryKey.cc:69
Matcher
Definition: Matcher.hh:50
FilterSearch::createMatchers
MatcherTable createMatchers(const CostDBTypes::MatchTypeTable &match)
Definition: FilterSearch.cc:179