-
Notifications
You must be signed in to change notification settings - Fork 81
refactor(core): Use C++20 concepts to enforce requirements for logtype and variable dictionary entries, readers, and writers. #1267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9404cb4
Add concepts for the variable and logtype dictionaries and their entries
gibber9809 6ed6d74
Use dictionary concepts in EncodedVariableInterpreter.hpp
gibber9809 e9dbd71
Use dictionary concepts in GrepCore.hpp
gibber9809 0131b2d
Address rabbit comments.
gibber9809 7da8133
Fix instance of clp-s dictionary readers not following dictionary con…
gibber9809 2d60d5f
Merge branch 'main' into clp-dictionary-concepts
gibber9809 d8d81f8
Apply suggestions from code review
gibber9809 25d7a2f
Merge remote-tracking branch 'upstream/main' into clp-dictionary-conc…
gibber9809 454daba
Apply some review comments.
gibber9809 eb6e746
Simplify some templates
gibber9809 0da5e24
Remove unused parameter in concept
gibber9809 0d1e320
Rename entry_t to EntryT
gibber9809 29226f1
Rename EntryT -> Entry
gibber9809 80e27c6
Rename placeholder_ix -> placeholder_idx
gibber9809 219daed
Merge remote-tracking branch 'upstream/main' into clp-dictionary-conc…
gibber9809 f9cb84c
Split new dictionary concepts into dedicated header files.
gibber9809 abc5387
Merge remote-tracking branch 'upstream/main' into clp-dictionary-conc…
gibber9809 3201f95
Address rabbit comment
gibber9809 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,13 @@ | |
#include "ffi/ir_stream/decoding_methods.hpp" | ||
#include "ir/LogEvent.hpp" | ||
#include "ir/types.hpp" | ||
#include "LogTypeDictionaryEntryReq.hpp" | ||
#include "Query.hpp" | ||
#include "spdlog_with_specializations.hpp" | ||
#include "TraceableException.hpp" | ||
#include "type_utils.hpp" | ||
#include "VariableDictionaryReaderReq.hpp" | ||
#include "VariableDictionaryWriterReq.hpp" | ||
|
||
namespace clp { | ||
/** | ||
|
@@ -123,7 +126,9 @@ class EncodedVariableInterpreter { | |
* @param encoded_vars | ||
* @param var_ids | ||
*/ | ||
template <typename LogTypeDictionaryEntryType, typename VariableDictionaryWriterType> | ||
template < | ||
LogTypeDictionaryEntryReq LogTypeDictionaryEntryType, | ||
VariableDictionaryWriterReq VariableDictionaryWriterType> | ||
static void encode_and_add_to_dictionary( | ||
std::string_view message, | ||
LogTypeDictionaryEntryType& logtype_dict_entry, | ||
|
@@ -149,8 +154,8 @@ class EncodedVariableInterpreter { | |
*/ | ||
template < | ||
typename EncodedVariableType, | ||
typename LogTypeDictionaryEntryType, | ||
typename VariableDictionaryWriterType> | ||
LogTypeDictionaryEntryReq LogTypeDictionaryEntryType, | ||
VariableDictionaryWriterReq VariableDictionaryWriterType> | ||
static void encode_and_add_to_dictionary( | ||
ir::LogEvent<EncodedVariableType> const& log_event, | ||
LogTypeDictionaryEntryType& logtype_dict_entry, | ||
|
@@ -172,8 +177,8 @@ class EncodedVariableInterpreter { | |
* @return true if successful, false otherwise | ||
*/ | ||
template < | ||
typename LogTypeDictionaryEntryType, | ||
typename VariableDictionaryReaderType, | ||
LogTypeDictionaryEntryReq LogTypeDictionaryEntryType, | ||
VariableDictionaryReaderReq VariableDictionaryReaderType, | ||
typename EncodedVariableContainerType> | ||
static bool decode_variables_into_message( | ||
LogTypeDictionaryEntryType const& logtype_dict_entry, | ||
|
@@ -195,7 +200,7 @@ class EncodedVariableInterpreter { | |
* dictionary | ||
* @return false otherwise | ||
*/ | ||
template <typename VariableDictionaryReaderType> | ||
template <VariableDictionaryReaderReq VariableDictionaryReaderType> | ||
static bool encode_and_search_dictionary( | ||
std::string_view var_str, | ||
VariableDictionaryReaderType const& var_dict, | ||
|
@@ -207,16 +212,13 @@ class EncodedVariableInterpreter { | |
* Search for the given string-form variable in the variable dictionary, encode any matches, and | ||
* add them to the given sub-query. | ||
* @tparam VariableDictionaryReaderType | ||
* @tparam VariableDictionaryEntryType | ||
* @param var_wildcard_str | ||
* @param var_dict | ||
* @param ignore_case | ||
* @param sub_query | ||
* @return true if any match found, false otherwise | ||
*/ | ||
template < | ||
typename VariableDictionaryReaderType, | ||
typename VariableDictionaryEntryType = typename VariableDictionaryReaderType::entry_t> | ||
template <VariableDictionaryReaderReq VariableDictionaryReaderType> | ||
static bool wildcard_search_dictionary_and_get_encoded_matches( | ||
std::string_view var_wildcard_str, | ||
VariableDictionaryReaderType const& var_dict, | ||
|
@@ -237,7 +239,9 @@ class EncodedVariableInterpreter { | |
* variable) | ||
* @return The encoded variable | ||
*/ | ||
template <typename LogTypeDictionaryEntryType, typename VariableDictionaryWriterType> | ||
template < | ||
LogTypeDictionaryEntryReq LogTypeDictionaryEntryType, | ||
VariableDictionaryWriterReq VariableDictionaryWriterType> | ||
static encoded_variable_t encode_var( | ||
std::string_view var, | ||
LogTypeDictionaryEntryType& logtype_dict_entry, | ||
|
@@ -256,7 +260,9 @@ class EncodedVariableInterpreter { | |
* @param var_ids A container to add the dictionary ID to | ||
* @return The dictionary ID | ||
*/ | ||
template <typename LogTypeDictionaryEntryType, typename VariableDictionaryWriterType> | ||
template < | ||
LogTypeDictionaryEntryReq LogTypeDictionaryEntryType, | ||
VariableDictionaryWriterReq VariableDictionaryWriterType> | ||
static variable_dictionary_id_t add_dict_var( | ||
std::string_view var, | ||
LogTypeDictionaryEntryType& logtype_dict_entry, | ||
|
@@ -265,7 +271,9 @@ class EncodedVariableInterpreter { | |
); | ||
}; | ||
|
||
template <typename LogTypeDictionaryEntryType, typename VariableDictionaryWriterType> | ||
template < | ||
LogTypeDictionaryEntryReq LogTypeDictionaryEntryType, | ||
VariableDictionaryWriterReq VariableDictionaryWriterType> | ||
void EncodedVariableInterpreter::encode_and_add_to_dictionary( | ||
std::string_view message, | ||
LogTypeDictionaryEntryType& logtype_dict_entry, | ||
|
@@ -289,8 +297,8 @@ void EncodedVariableInterpreter::encode_and_add_to_dictionary( | |
|
||
template < | ||
typename EncodedVariableType, | ||
typename LogTypeDictionaryEntryType, | ||
typename VariableDictionaryWriterType> | ||
LogTypeDictionaryEntryReq LogTypeDictionaryEntryType, | ||
VariableDictionaryWriterReq VariableDictionaryWriterType> | ||
void EncodedVariableInterpreter::encode_and_add_to_dictionary( | ||
ir::LogEvent<EncodedVariableType> const& log_event, | ||
LogTypeDictionaryEntryType& logtype_dict_entry, | ||
|
@@ -362,8 +370,8 @@ void EncodedVariableInterpreter::encode_and_add_to_dictionary( | |
} | ||
|
||
template < | ||
typename LogTypeDictionaryEntryType, | ||
typename VariableDictionaryReaderType, | ||
LogTypeDictionaryEntryReq LogTypeDictionaryEntryType, | ||
VariableDictionaryReaderReq VariableDictionaryReaderType, | ||
typename EncodedVariableContainerType> | ||
bool EncodedVariableInterpreter::decode_variables_into_message( | ||
LogTypeDictionaryEntryType const& logtype_dict_entry, | ||
|
@@ -436,7 +444,7 @@ bool EncodedVariableInterpreter::decode_variables_into_message( | |
return true; | ||
} | ||
|
||
template <typename VariableDictionaryReaderType> | ||
template <VariableDictionaryReaderReq VariableDictionaryReaderType> | ||
bool EncodedVariableInterpreter::encode_and_search_dictionary( | ||
std::string_view var_str, | ||
VariableDictionaryReaderType const& var_dict, | ||
|
@@ -485,15 +493,15 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary( | |
return true; | ||
} | ||
|
||
template <typename VariableDictionaryReaderType, typename VariableDictionaryEntryType> | ||
template <VariableDictionaryReaderReq VariableDictionaryReaderType> | ||
bool EncodedVariableInterpreter::wildcard_search_dictionary_and_get_encoded_matches( | ||
std::string_view var_wildcard_str, | ||
VariableDictionaryReaderType const& var_dict, | ||
bool ignore_case, | ||
SubQuery& sub_query | ||
) { | ||
// Find matches | ||
Comment on lines
+496
to
503
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Reserve capacity for result sets to cut rehashing in hot path. Apply this diff: - // Encode matches
- std::unordered_set<encoded_variable_t> encoded_vars;
- std::unordered_set<variable_dictionary_id_t> var_dict_ids;
+ // Encode matches
+ std::unordered_set<encoded_variable_t> encoded_vars;
+ std::unordered_set<variable_dictionary_id_t> var_dict_ids;
+ encoded_vars.reserve(var_dict_entries.size());
+ var_dict_ids.reserve(var_dict_entries.size());
|
||
std::unordered_set<VariableDictionaryEntryType const*> var_dict_entries; | ||
std::unordered_set<typename VariableDictionaryReaderType::Entry const*> var_dict_entries; | ||
var_dict.get_entries_matching_wildcard_string(var_wildcard_str, ignore_case, var_dict_entries); | ||
if (var_dict_entries.empty()) { | ||
// Not in dictionary | ||
|
@@ -513,7 +521,9 @@ bool EncodedVariableInterpreter::wildcard_search_dictionary_and_get_encoded_matc | |
return true; | ||
} | ||
|
||
template <typename LogTypeDictionaryEntryType, typename VariableDictionaryWriterType> | ||
template < | ||
LogTypeDictionaryEntryReq LogTypeDictionaryEntryType, | ||
VariableDictionaryWriterReq VariableDictionaryWriterType> | ||
encoded_variable_t EncodedVariableInterpreter::encode_var( | ||
std::string_view var, | ||
LogTypeDictionaryEntryType& logtype_dict_entry, | ||
|
@@ -532,7 +542,9 @@ encoded_variable_t EncodedVariableInterpreter::encode_var( | |
return encoded_var; | ||
} | ||
|
||
template <typename LogTypeDictionaryEntryType, typename VariableDictionaryWriterType> | ||
template < | ||
LogTypeDictionaryEntryReq LogTypeDictionaryEntryType, | ||
VariableDictionaryWriterReq VariableDictionaryWriterType> | ||
variable_dictionary_id_t EncodedVariableInterpreter::add_dict_var( | ||
std::string_view var, | ||
LogTypeDictionaryEntryType& logtype_dict_entry, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.