Skip to content

Commit

Permalink
review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aestriplex committed Jan 28, 2025
1 parent aaac6a0 commit aecae49
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
3 changes: 2 additions & 1 deletion components/core/src/clp/DictionaryReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value(
for (auto const& entry : m_entries) {
if (entry.get_value() == search_string) {
entries.push_back(&entry);
return entries; /* early exit for case sensitive branch */
// early exit for case sensitive branch
return entries;
}
}
} else {
Expand Down
11 changes: 5 additions & 6 deletions components/core/src/clp/EncodedVariableInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ 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);

auto const entries = var_dict.get_entry_matching_value(var_str, ignore_case);
if (entries.empty()) {
// Not in dictionary
return false;
Expand All @@ -396,18 +395,18 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary(
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());
auto const* entry = entries.at(0);
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(
std::unordered_set<clp::VariableDictionaryEntry const*> const entries_set(
entries.begin(),
entries.end()
);
for (auto entry : entries) {
for (auto const entry : entries) {
encoded_vars.insert(encode_var_dict_id(entry->get_id()));
}
sub_query.add_imprecise_dict_var(encoded_vars, entries_set);
Expand Down
3 changes: 2 additions & 1 deletion components/core/src/clp_s/DictionaryReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value(
for (auto const& entry : m_entries) {
if (entry.get_value() == search_string) {
entries.push_back(&entry);
return entries; /* early exit for case sensitive branch */
// early exit for case sensitive branch
return entries;
}
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions components/core/src/clp_s/search/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,12 +932,12 @@ void Output::populate_string_queries(std::shared_ptr<Expression> const& expr) {
}
}

auto entries = m_var_dict->get_entry_matching_value(
auto const entries = m_var_dict->get_entry_matching_value(
unescaped_query_string,
m_ignore_case
);

for (auto entry : entries) {
for (auto const& entry : entries) {
matching_vars.insert(entry->get_id());
}
} else if (EncodedVariableInterpreter::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary(
LogTypeDictionaryEntry::add_double_var(logtype);
sub_query.add_non_dict_var(encoded_var);
} else {
auto entries = var_dict.get_entry_matching_value(var_str, ignore_case);

auto const entries = var_dict.get_entry_matching_value(var_str, ignore_case);
if (entries.empty()) {
// Not in dictionary
return false;
Expand All @@ -44,8 +43,8 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary(
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());
auto const* entry = entries.at(0);
encoded_var = VariableEncoder::encode_var_dict_id(entry->get_id());
sub_query.add_dict_var(encoded_var, entry);
return true;
}
Expand All @@ -55,7 +54,7 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary(
entries.begin(),
entries.end()
);
for (auto entry : entries) {
for (auto const entry : entries) {
encoded_vars.insert(VariableEncoder::encode_var_dict_id(entry->get_id()));
}
sub_query.add_imprecise_dict_var(encoded_vars, entries_set);
Expand Down
12 changes: 8 additions & 4 deletions components/core/tests/test-EncodedVariableInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,17 @@ TEST_CASE("EncodedVariableInterpreter", "[EncodedVariableInterpreter]") {
char const cVarSegmentIndexPath[] = "var.segindex";
vector<string> var_strs = {"python2.7.3", "Python2.7.3", "PyThOn2.7.3", "PYTHON2.7.3"};
clp::VariableDictionaryWriter var_dict_writer;

var_dict_writer.open(cVarDictPath, cVarSegmentIndexPath, cVariableDictionaryIdMax);

vector<encoded_variable_t> encoded_vars;
vector<clp::variable_dictionary_id_t> var_ids;
clp::LogTypeDictionaryEntry logtype_dict_entry;
for (auto var_str : var_strs) {
string const msg_template = "here is a string with a dictionary var: ";

for (auto const& var_str : var_strs) {
EncodedVariableInterpreter::encode_and_add_to_dictionary(
var_str,
msg_template + var_str,
logtype_dict_entry,
var_dict_writer,
encoded_vars,
Expand All @@ -400,9 +404,9 @@ TEST_CASE("EncodedVariableInterpreter", "[EncodedVariableInterpreter]") {
var_dict_reader.open(cVarDictPath, cVarSegmentIndexPath);
var_dict_reader.read_new_entries();

REQUIRE(var_dict_reader.get_entry_matching_value(var_strs[0], true).size()
REQUIRE(var_dict_reader.get_entry_matching_value(var_strs.at(0), true).size()
== var_strs.size());
REQUIRE(var_dict_reader.get_entry_matching_value(var_strs[0], false).size() == 1);
REQUIRE(var_dict_reader.get_entry_matching_value(var_strs.at(0), false).size() == 1);

var_dict_reader.close();

Expand Down

0 comments on commit aecae49

Please sign in to comment.