Skip to content

Commit

Permalink
#648 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aestriplex committed Jan 23, 2025
1 parent ef3a1cb commit ea41a9c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
12 changes: 6 additions & 6 deletions components/core/src/clp/DictionaryReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class DictionaryReader {
* Gets the entry exactly matching the given search string
* @param search_string
* @param ignore_case
* @return a (possibly empty) set of entries
* @return a (possibly empty) vector of entries
*/
std::unordered_set<EntryType const*>
std::vector<EntryType const*>
get_entry_matching_value(std::string const& search_string, bool ignore_case) const;
/**
* Gets the entries that match a given wildcard string
Expand Down Expand Up @@ -233,24 +233,24 @@ std::string const& DictionaryReader<DictionaryIdType, EntryType>::get_value(Dict
}

template <typename DictionaryIdType, typename EntryType>
std::unordered_set<EntryType const*>
std::vector<EntryType const*>
DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value(
std::string const& search_string,
bool ignore_case
) const {
std::unordered_set<EntryType const*> entries;
std::vector<EntryType const*> entries;
if (false == ignore_case) {
for (auto const& entry : m_entries) {
if (entry.get_value() == search_string) {
entries.insert(&entry);
entries.push_back(&entry);
return entries; /* early exit for case sensitive branch */
}
}
} else {
auto const& search_string_uppercase = boost::algorithm::to_upper_copy(search_string);
for (auto const& entry : m_entries) {
if (boost::algorithm::to_upper_copy(entry.get_value()) == search_string_uppercase) {
entries.insert(&entry);
entries.push_back(&entry);
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions components/core/src/clp/EncodedVariableInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,30 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary(
sub_query.add_non_dict_var(encoded_var);
} else {
auto entries = var_dict.get_entry_matching_value(var_str, ignore_case);
std::unordered_set<encoded_variable_t> encoded_vars;

if (entries.empty()) {
// Not in dictionary
return false;
}

LogTypeDictionaryEntry::add_dict_var(logtype);

if (entries.size() == 1) {
clp::VariableDictionaryEntry const* entry = entries[0];
auto encoded_var = encode_var_dict_id(entry->get_id());
sub_query.add_dict_var(encoded_var, entry);
return true;
}

std::unordered_set<encoded_variable_t> encoded_vars;
std::unordered_set<clp::VariableDictionaryEntry const*> entries_set(
entries.begin(),
entries.end()
);
for (auto entry : entries) {
encoded_vars.insert(encode_var_dict_id(entry->get_id()));
}
LogTypeDictionaryEntry::add_dict_var(logtype);
sub_query.add_imprecise_dict_var(encoded_vars, entries);
sub_query.add_imprecise_dict_var(encoded_vars, entries_set);
}

return true;
Expand Down
12 changes: 6 additions & 6 deletions components/core/src/clp_s/DictionaryReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class DictionaryReader {
* Gets the entry exactly matching the given search string
* @param search_string
* @param ignore_case
* @return a (possibly empty) set of entries
* @return a (possibly empty) vector of entries
*/
std::unordered_set<EntryType const*>
std::vector<EntryType const*>
get_entry_matching_value(std::string const& search_string, bool ignore_case) const;

/**
Expand Down Expand Up @@ -156,24 +156,24 @@ std::string const& DictionaryReader<DictionaryIdType, EntryType>::get_value(Dict
}

template <typename DictionaryIdType, typename EntryType>
std::unordered_set<EntryType const*>
std::vector<EntryType const*>
DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value(
std::string const& search_string,
bool ignore_case
) const {
std::unordered_set<EntryType const*> entries;
std::vector<EntryType const*> entries;
if (false == ignore_case) {
for (auto const& entry : m_entries) {
if (entry.get_value() == search_string) {
entries.insert(&entry);
entries.push_back(&entry);
return entries; /* early exit for case sensitive branch */
}
}
} else {
auto const& search_string_uppercase = boost::algorithm::to_upper_copy(search_string);
for (auto const& entry : m_entries) {
if (boost::algorithm::to_upper_copy(entry.get_value()) == search_string_uppercase) {
entries.insert(&entry);
entries.push_back(&entry);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,30 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary(
sub_query.add_non_dict_var(encoded_var);
} else {
auto entries = var_dict.get_entry_matching_value(var_str, ignore_case);
std::unordered_set<encoded_variable_t> encoded_vars;

if (entries.empty()) {
// Not in dictionary
return false;
}

LogTypeDictionaryEntry::add_non_double_var(logtype);

if (entries.size() == 1) {
VariableDictionaryEntry const* entry = entries[0];
auto encoded_var = VariableEncoder::encode_var_dict_id(entry->get_id());
sub_query.add_dict_var(encoded_var, entry);
return true;
}

std::unordered_set<encoded_variable_t> encoded_vars;
std::unordered_set<VariableDictionaryEntry const*> entries_set(
entries.begin(),
entries.end()
);
for (auto entry : entries) {
encoded_vars.insert(VariableEncoder::encode_var_dict_id(entry->get_id()));
}
LogTypeDictionaryEntry::add_non_double_var(logtype);
sub_query.add_imprecise_dict_var(encoded_vars, entries);
sub_query.add_imprecise_dict_var(encoded_vars, entries_set);
}

return true;
Expand Down
15 changes: 6 additions & 9 deletions components/core/src/glt/DictionaryReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class DictionaryReader {
* Gets the entry exactly matching the given search string
* @param search_string
* @param ignore_case
* @return a (possibly empty) set of entries
* @return nullptr if an exact match is not found, the entry otherwise
*/
std::unordered_set<EntryType const*>
EntryType const*
get_entry_matching_value(std::string const& search_string, bool ignore_case) const;
/**
* Gets the entries that match a given wildcard string
Expand Down Expand Up @@ -228,29 +228,26 @@ std::string const& DictionaryReader<DictionaryIdType, EntryType>::get_value(Dict
}

template <typename DictionaryIdType, typename EntryType>
std::unordered_set<EntryType const*>
DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value(
EntryType const* DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value(
std::string const& search_string,
bool ignore_case
) const {
std::unordered_set<EntryType const*> entries;
if (false == ignore_case) {
for (auto const& entry : m_entries) {
if (entry.get_value() == search_string) {
entries.insert(&entry);
return entries; /* early exit for case sensitive branch */
return &entry;
}
}
} else {
auto const& search_string_uppercase = boost::algorithm::to_upper_copy(search_string);
for (auto const& entry : m_entries) {
if (boost::algorithm::to_upper_copy(entry.get_value()) == search_string_uppercase) {
entries.insert(&entry);
return &entry;
}
}
}

return entries;
return nullptr;
}

template <typename DictionaryIdType, typename EntryType>
Expand Down
11 changes: 4 additions & 7 deletions components/core/src/glt/EncodedVariableInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,18 +451,15 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary(
LogTypeDictionaryEntry::add_float_var(logtype);
sub_query.add_non_dict_var(encoded_var);
} else {
auto entries = var_dict.get_entry_matching_value(var_str, ignore_case);
std::unordered_set<encoded_variable_t> encoded_vars;
if (entries.empty()) {
auto entry = var_dict.get_entry_matching_value(var_str, ignore_case);
if (nullptr == entry) {
// Not in dictionary
return false;
}
encoded_var = encode_var_dict_id(entry->get_id());

for (auto entry : entries) {
encoded_vars.insert(encode_var_dict_id(entry->get_id()));
}
LogTypeDictionaryEntry::add_dict_var(logtype);
sub_query.add_imprecise_dict_var(encoded_vars, entries);
sub_query.add_dict_var(encoded_var, entry);
}

return true;
Expand Down

0 comments on commit ea41a9c

Please sign in to comment.