Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::SetMatcher Class Reference

Public Types

enum class  Policy {
  ORDERED , UNORDERED , SOME , SOME_ORDERED ,
  INVALID
}
 The policy used by the SetMatcher. More...
 

Static Public Member Functions

template<class T , class MATCHER >
static bool MatchRecursive (vector< unique_ptr< MATCHER > > &matchers, vector< reference< T > > &entries, vector< reference< T > > &bindings, unordered_set< idx_t > excluded_entries, idx_t m_idx=0)
 
template<class T , class MATCHER >
static bool Match (vector< unique_ptr< MATCHER > > &matchers, vector< reference< T > > &entries, vector< reference< T > > &bindings, Policy policy)
 
template<class T , class MATCHER >
static bool Match (vector< unique_ptr< MATCHER > > &matchers, vector< unique_ptr< T > > &entries, vector< reference< T > > &bindings, Policy policy)
 

Member Enumeration Documentation

◆ Policy

The policy used by the SetMatcher.

Enumerator
ORDERED 

All entries have to be matched, and the matches have to be ordered.

UNORDERED 

All entries have to be matched, but the order of the matches does not matter.

SOME 

Only some entries have to be matched, the order of the matches does not matter.

SOME_ORDERED 

Only some entries have to be matched. The order of the matches does matter.

INVALID 

Not initialized.

69119 {
69121 ORDERED,
69123 UNORDERED,
69125 SOME,
69129 INVALID
69130 };
@ UNORDERED
All entries have to be matched, but the order of the matches does not matter.
@ SOME
Only some entries have to be matched, the order of the matches does not matter.
@ ORDERED
All entries have to be matched, and the matches have to be ordered.
@ INVALID
Not initialized.
@ SOME_ORDERED
Only some entries have to be matched. The order of the matches does matter.

Member Function Documentation

◆ MatchRecursive()

template<class T , class MATCHER >
static bool duckdb::SetMatcher::MatchRecursive ( vector< unique_ptr< MATCHER > > &  matchers,
vector< reference< T > > &  entries,
vector< reference< T > > &  bindings,
unordered_set< idx_t excluded_entries,
idx_t  m_idx = 0 
)
inlinestatic
69135 {
69136 if (m_idx == matchers.size()) {
69137 // matched all matchers!
69138 return true;
69139 }
69140 // try to find a match for the current matcher (m_idx)
69141 idx_t previous_binding_count = bindings.size();
69142 for (idx_t e_idx = 0; e_idx < entries.size(); e_idx++) {
69143 // first check if this entry has already been matched
69144 if (excluded_entries.find(e_idx) != excluded_entries.end()) {
69145 // it has been matched: skip this entry
69146 continue;
69147 }
69148 // otherwise check if the current matcher matches this entry
69149 if (matchers[m_idx]->Match(entries[e_idx], bindings)) {
69150 // m_idx matches e_idx!
69151 // check if we can find a complete match for this path
69152 // first add e_idx to the new set of excluded entries
69153 unordered_set<idx_t> new_excluded_entries;
69154 new_excluded_entries = excluded_entries;
69155 new_excluded_entries.insert(e_idx);
69156 // then match the next matcher in the set
69157 if (MatchRecursive(matchers, entries, bindings, new_excluded_entries, m_idx + 1)) {
69158 // we found a match for this path! success
69159 return true;
69160 } else {
69161 // we did not find a match! remove any bindings we added in the call to Match()
69162 bindings.erase(bindings.begin() + NumericCast<int64_t>(previous_binding_count), bindings.end());
69163 }
69164 }
69165 }
69166 return false;
69167 }

◆ Match() [1/2]

template<class T , class MATCHER >
static bool duckdb::SetMatcher::Match ( vector< unique_ptr< MATCHER > > &  matchers,
vector< reference< T > > &  entries,
vector< reference< T > > &  bindings,
Policy  policy 
)
inlinestatic
69171 {
69172 if (policy == Policy::ORDERED) {
69173 // ordered policy, count has to match
69174 if (matchers.size() != entries.size()) {
69175 return false;
69176 }
69177 // now entries have to match in order
69178 for (idx_t i = 0; i < matchers.size(); i++) {
69179 if (!matchers[i]->Match(entries[i], bindings)) {
69180 return false;
69181 }
69182 }
69183 return true;
69184 } else if (policy == Policy::SOME_ORDERED) {
69185 if (entries.size() < matchers.size()) {
69186 return false;
69187 }
69188 // now provided entries have to match in order
69189 for (idx_t i = 0; i < matchers.size(); i++) {
69190 if (!matchers[i]->Match(entries[i], bindings)) {
69191 return false;
69192 }
69193 }
69194 return true;
69195 } else {
69196 if (policy == Policy::UNORDERED && matchers.size() != entries.size()) {
69197 // unordered policy, count does not match: no match
69198 return false;
69199 } else if (policy == Policy::SOME && matchers.size() > entries.size()) {
69200 // some policy, every matcher has to match a unique entry
69201 // this is not possible if there are more matchers than entries
69202 return false;
69203 }
69204 // now perform the actual matching
69205 // every matcher has to match a UNIQUE entry
69206 // we perform this matching in a recursive way
69207 unordered_set<idx_t> excluded_entries;
69208 if (!MatchRecursive(matchers, entries, bindings, excluded_entries)) {
69209 return false;
69210 }
69211 return true;
69212 }
69213 }

◆ Match() [2/2]

template<class T , class MATCHER >
static bool duckdb::SetMatcher::Match ( vector< unique_ptr< MATCHER > > &  matchers,
vector< unique_ptr< T > > &  entries,
vector< reference< T > > &  bindings,
Policy  policy 
)
inlinestatic
69217 {
69218 // convert vector of unique_ptr to vector of normal pointers
69219 vector<reference<T>> ptr_entries;
69220 for (auto &entry : entries) {
69221 ptr_entries.push_back(*entry);
69222 }
69223 // then just call the normal match function
69224 return Match(matchers, ptr_entries, bindings, policy);
69225 }

The documentation for this class was generated from the following file: