From b9820f73605d148ba046d2922165bfa6dfae7385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tr=C3=A1vn=C3=AD=C4=8Dek?= <jan.travnicek@fit.cvut.cz> Date: Tue, 1 Mar 2022 09:00:43 +0100 Subject: [PATCH] aux: replace not needed specialized comparisons with a generic one --- alib2aux/src/compare/IsSame.cpp | 19 +++++++++++++++++++ alib2aux/src/compare/PrimitiveCompare.cpp | 12 ------------ alib2aux/src/compare/PrimitiveCompare.h | 16 ---------------- alib2aux/src/compare/SetCompare.cpp | 11 ----------- alib2aux/src/compare/SetCompare.h | 16 ---------------- alib2aux/src/compare/StringCompare.h | 2 +- alib2aux/src/compare/TrieCompare.cpp | 8 -------- alib2aux/src/compare/TrieCompare.h | 17 ----------------- alib2aux/src/compare/VectorCompare.cpp | 8 -------- alib2aux/src/compare/VectorCompare.h | 16 ---------------- ...ologyMPAlreadyMatchedPatternPrefixTest.aql | 2 +- tests/aql/InfiniteLanguage.aql | 2 +- tests/cppaql/approximateMatching.cpp | 4 ++-- tests/cppaql/arbologyTest.cpp | 4 ++-- tests/cppaql/borderArrayTest.cpp | 2 +- tests/cppaql/dummyTest.cpp | 2 +- tests/cppaql/exactMatching.cpp | 4 ++-- tests/cppaql/normalizeTest.cpp | 4 ++-- tests/cppaql/treeNotationTest.cpp | 4 ++-- tests/cppaql/treeRepeatsTest.cpp | 4 ++-- 20 files changed, 36 insertions(+), 121 deletions(-) create mode 100644 alib2aux/src/compare/IsSame.cpp delete mode 100644 alib2aux/src/compare/PrimitiveCompare.cpp delete mode 100644 alib2aux/src/compare/PrimitiveCompare.h delete mode 100644 alib2aux/src/compare/SetCompare.cpp delete mode 100644 alib2aux/src/compare/SetCompare.h delete mode 100644 alib2aux/src/compare/TrieCompare.cpp delete mode 100644 alib2aux/src/compare/TrieCompare.h delete mode 100644 alib2aux/src/compare/VectorCompare.cpp delete mode 100644 alib2aux/src/compare/VectorCompare.h diff --git a/alib2aux/src/compare/IsSame.cpp b/alib2aux/src/compare/IsSame.cpp new file mode 100644 index 0000000000..a74347a04b --- /dev/null +++ b/alib2aux/src/compare/IsSame.cpp @@ -0,0 +1,19 @@ +#include <object/Object.h> +#include <registration/AlgoRegistration.hpp> + +namespace compare { + +class IsSame { +public: + static bool isSame ( const object::Object & a, const object::Object & b ) { + return a == b; + } +}; + +} /* namespace compare */ + +namespace { + +auto IsSame = registration::AbstractRegister < compare::IsSame, bool, const object::Object &, const object::Object & > ( compare::IsSame::isSame ); + +} /* namespace */ diff --git a/alib2aux/src/compare/PrimitiveCompare.cpp b/alib2aux/src/compare/PrimitiveCompare.cpp deleted file mode 100644 index 735346f2f9..0000000000 --- a/alib2aux/src/compare/PrimitiveCompare.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "PrimitiveCompare.h" -#include <registration/AlgoRegistration.hpp> - -#include <string/LinearString.h> - -namespace { - -auto PrimitiveCompareUnsignedInt = registration::AbstractRegister < compare::PrimitiveCompare, bool, const unsigned int &, const unsigned int & > ( compare::PrimitiveCompare::compare ); -auto PrimitiveCompareInt = registration::AbstractRegister < compare::PrimitiveCompare, bool, const int &, const int & > ( compare::PrimitiveCompare::compare ); -auto PrimitiveCompareBool = registration::AbstractRegister < compare::PrimitiveCompare, bool, const bool &, const bool & > ( compare::PrimitiveCompare::compare ); - -} /* namespace */ diff --git a/alib2aux/src/compare/PrimitiveCompare.h b/alib2aux/src/compare/PrimitiveCompare.h deleted file mode 100644 index 147403c447..0000000000 --- a/alib2aux/src/compare/PrimitiveCompare.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include <alib/set> - -namespace compare { - -class PrimitiveCompare { -public: - template < class T > - static bool compare ( const T & a, const T & b ) { - return a == b; - } -}; - -} /* namespace compare */ - diff --git a/alib2aux/src/compare/SetCompare.cpp b/alib2aux/src/compare/SetCompare.cpp deleted file mode 100644 index a8347128a1..0000000000 --- a/alib2aux/src/compare/SetCompare.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "SetCompare.h" -#include <registration/AlgoRegistration.hpp> - -#include <string/LinearString.h> - -namespace { - -auto SetCompareLinearString = registration::AbstractRegister < compare::SetCompare, bool, const ext::set < string::LinearString < > > &, const ext::set < string::LinearString < > > & > ( compare::SetCompare::compare ); -auto SetCompareUnsignedInt = registration::AbstractRegister < compare::SetCompare, bool, const ext::set < unsigned > &, const ext::set < unsigned > & > ( compare::SetCompare::compare ); - -} /* namespace */ diff --git a/alib2aux/src/compare/SetCompare.h b/alib2aux/src/compare/SetCompare.h deleted file mode 100644 index 9fb6d8c90b..0000000000 --- a/alib2aux/src/compare/SetCompare.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include <alib/set> - -namespace compare { - -class SetCompare { -public: - template < class T > - static bool compare ( const ext::set < T > & a, const ext::set < T > & b ) { - return a == b; - } -}; - -} /* namespace compare */ - diff --git a/alib2aux/src/compare/StringCompare.h b/alib2aux/src/compare/StringCompare.h index 6062d2168c..c9b770203f 100644 --- a/alib2aux/src/compare/StringCompare.h +++ b/alib2aux/src/compare/StringCompare.h @@ -16,7 +16,7 @@ public: template < class SymbolType > bool StringCompare::compare ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b ) { - return a.getAlphabet ( ) == b.getAlphabet ( ) && + return //a.getAlphabet ( ) == b.getAlphabet ( ) && a.getContent ( ) == b.getContent ( ) ; } diff --git a/alib2aux/src/compare/TrieCompare.cpp b/alib2aux/src/compare/TrieCompare.cpp deleted file mode 100644 index 920b9b71cf..0000000000 --- a/alib2aux/src/compare/TrieCompare.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "TrieCompare.h" -#include <registration/AlgoRegistration.hpp> - -namespace { - -auto TrieCompareLinearString = registration::AbstractRegister < compare::TrieCompare, bool, const ext::trie < DefaultSymbolType, bool > &, const ext::trie < DefaultSymbolType, bool > & > ( compare::TrieCompare::compare ); - -} /* namespace */ diff --git a/alib2aux/src/compare/TrieCompare.h b/alib2aux/src/compare/TrieCompare.h deleted file mode 100644 index fedde00a58..0000000000 --- a/alib2aux/src/compare/TrieCompare.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include <alib/trie> -#include <common/DefaultSymbolType.h> - -namespace compare { - -class TrieCompare { -public: - template < class R, class T > - static bool compare ( const ext::trie < R, T > & a, const ext::trie < R, T > & b ) { - return a == b; - } -}; - -} /* namespace compare */ - diff --git a/alib2aux/src/compare/VectorCompare.cpp b/alib2aux/src/compare/VectorCompare.cpp deleted file mode 100644 index 90e7381072..0000000000 --- a/alib2aux/src/compare/VectorCompare.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "VectorCompare.h" -#include <registration/AlgoRegistration.hpp> - -namespace { - -auto VectorCompareULI = registration::AbstractRegister < compare::VectorCompare, bool, const ext::vector < unsigned long > &, const ext::vector < unsigned long > & > ( compare::VectorCompare::compare ); - -} /* namespace */ diff --git a/alib2aux/src/compare/VectorCompare.h b/alib2aux/src/compare/VectorCompare.h deleted file mode 100644 index f64bb4ce0e..0000000000 --- a/alib2aux/src/compare/VectorCompare.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include <alib/vector> - -namespace compare { - -class VectorCompare { -public: - template < class T > - static bool compare ( const ext::vector < T > & a, const ext::vector < T > & b ) { - return a == b; - } -}; - -} /* namespace compare */ - diff --git a/tests/aql/ArbologyMPAlreadyMatchedPatternPrefixTest.aql b/tests/aql/ArbologyMPAlreadyMatchedPatternPrefixTest.aql index 168ef3631c..177bf895ac 100644 --- a/tests/aql/ArbologyMPAlreadyMatchedPatternPrefixTest.aql +++ b/tests/aql/ArbologyMPAlreadyMatchedPatternPrefixTest.aql @@ -2,4 +2,4 @@ execute string::Parse @Tree "RANKED_EXTENDED_PATTERN a 2 #N 2 #S #S #S" > $patte execute string::Parse @Tree "RANKED_TREE a 2 b 2 b 2 a 0 a 0 a 0 a 0" > $subject execute arbology::exact::ExactPatternMatch $subject $pattern > $res1 execute arbology::exact::KnuthMorrisPratt (PrefixRankedTree)$subject (PrefixRankedExtendedPattern) $pattern > $res2 -quit compare::PrimitiveCompare <(stats::SizeStat $res1) <(stats::SizeStat $res2) +quit compare::IsSame <(stats::SizeStat $res1) <(stats::SizeStat $res2) diff --git a/tests/aql/InfiniteLanguage.aql b/tests/aql/InfiniteLanguage.aql index 2224b02714..3309d66d65 100644 --- a/tests/aql/InfiniteLanguage.aql +++ b/tests/aql/InfiniteLanguage.aql @@ -7,7 +7,7 @@ begin execute automaton::properties::InfiniteLanguage $aut > $r1; execute regexp::properties::InfiniteLanguage $regexp > $r2; - execute compare::PrimitiveCompare $r1 $r2 > $res; + execute compare::IsSame $r1 $r2 > $res; if ( $res != 1 ) then begin print "Comparison returned non-OK value:"; print $res; diff --git a/tests/cppaql/approximateMatching.cpp b/tests/cppaql/approximateMatching.cpp index c88fb74c7c..052e4a56af 100644 --- a/tests/cppaql/approximateMatching.cpp +++ b/tests/cppaql/approximateMatching.cpp @@ -71,7 +71,7 @@ TEST_CASE ( "Approximate Matching", "[integration]" ) { qCreateMatchingAutomaton ( std::get < 0 > ( definition ), "pattern", "error", "automaton" ), qRunAutomaton ( "automaton", "subject", "res1" ), qRunDynamicAlgorithm ( std::get < 1 > ( definition ), "pattern", "subject", "error", "res2" ), - "quit compare::SetCompare $res1 $res2", + "quit compare::IsSame $res1 $res2", }; TimeoutAqlTest ( 2s, qs ); @@ -89,7 +89,7 @@ TEST_CASE ( "Approximate Matching", "[integration]" ) { qCreateMatchingAutomaton ( std::get < 0 > ( definition ), "pattern", "error", "automaton" ), qRunAutomaton ( "automaton", "subject", "res1" ), qRunDynamicAlgorithm ( std::get < 1 > ( definition ), "pattern", "subject", "error", "res2" ), - "quit compare::SetCompare $res1 $res2", + "quit compare::IsSame $res1 $res2", }; TimeoutAqlTest ( 5s, qs ); diff --git a/tests/cppaql/arbologyTest.cpp b/tests/cppaql/arbologyTest.cpp index 6a6d56c891..ea94925302 100644 --- a/tests/cppaql/arbologyTest.cpp +++ b/tests/cppaql/arbologyTest.cpp @@ -128,7 +128,7 @@ void runTest ( const std::string & exactPipeline, const std::string &pipeline, c ext::concat ( "execute < ", sFile, " > $subject" ), ext::concat ( "execute ", exactPipeline, " > $res1" ), ext::concat ( "execute ", pipeline, " > $res2" ), - "quit compare::PrimitiveCompare <(stats::SizeStat $res1) <(stats::SizeStat $res2)", + "quit compare::IsSame <(stats::SizeStat $res1) <(stats::SizeStat $res2)", }; TimeoutAqlTest ( 10s, qs ); @@ -140,7 +140,7 @@ void runRandom ( const std::string & exactPipeline, const std::string &pipeline, qGen ( subjectType, SUBJECT_HEIGHT, subjSize, ALPHABET_SIZE, "subject" ), ext::concat ( "execute ", exactPipeline, " > $res1" ), ext::concat ( "execute ", pipeline, " > $res2" ), - "quit compare::PrimitiveCompare <(stats::SizeStat $res1) <(stats::SizeStat $res2)", + "quit compare::IsSame <(stats::SizeStat $res1) <(stats::SizeStat $res2)", }; TimeoutAqlTest ( 10s, qs ); diff --git a/tests/cppaql/borderArrayTest.cpp b/tests/cppaql/borderArrayTest.cpp index b444f74bc7..64c7fbe40f 100644 --- a/tests/cppaql/borderArrayTest.cpp +++ b/tests/cppaql/borderArrayTest.cpp @@ -41,7 +41,7 @@ void run ( const std::string & prefixRankedType ) { // "execute $pattern | string::Compose - ", // "execute $res1", // "execute $res2", - "quit compare::VectorCompare $res1 $res2", + "quit compare::IsSame $res1 $res2", }; for ( size_t i = 0; i < RANDOM_ITERATIONS; i++ ) TimeoutAqlTest ( 1s, qs ); diff --git a/tests/cppaql/dummyTest.cpp b/tests/cppaql/dummyTest.cpp index 5ce955cd2d..74ce3d978b 100644 --- a/tests/cppaql/dummyTest.cpp +++ b/tests/cppaql/dummyTest.cpp @@ -59,7 +59,7 @@ TEST_CASE ( "Sanitizer Test", "[integration][dummy][!hide][!shouldfail]" ) { TEST_CASE ( "Failed Test", "[integration][dummy][!shouldfail]" ) { ext::vector < std::string > qs = { - "quit compare::PrimitiveCompare 1 2", + "quit compare::IsSame 1 2", }; TimeoutAqlTest ( 1s, qs ); diff --git a/tests/cppaql/exactMatching.cpp b/tests/cppaql/exactMatching.cpp index ecd81609dc..e05bc0a96d 100644 --- a/tests/cppaql/exactMatching.cpp +++ b/tests/cppaql/exactMatching.cpp @@ -60,7 +60,7 @@ TEST_CASE ( "ExactMatching", "[integration]" ) { qs.push_back ( qExtendAlphabet ( "pattern", "subject" ) ); qs.push_back ( ext::concat ( "execute ", std::get < 1 > ( definition ), " > $res2" ) ); - qs.push_back ( "quit compare::PrimitiveCompare <(stats::SizeStat $res1) <(stats::SizeStat $res2)" ); + qs.push_back ( "quit compare::IsSame <(stats::SizeStat $res1) <(stats::SizeStat $res2)" ); INFO ( std::get < 0 > ( definition ) ); TimeoutAqlTest ( 2s, qs ); @@ -79,7 +79,7 @@ TEST_CASE ( "ExactMatching", "[integration]" ) { qs.push_back ( qExtendAlphabet ( "pattern", "subject" ) ); qs.push_back ( ext::concat ( "execute ", std::get < 1 > ( definition ), " > $res2" ) ); - qs.push_back ( "quit compare::PrimitiveCompare <(stats::SizeStat $res1) <(stats::SizeStat $res2)" ); + qs.push_back ( "quit compare::IsSame <(stats::SizeStat $res1) <(stats::SizeStat $res2)" ); INFO ( std::get < 0 > ( definition ) ); TimeoutAqlTest ( 2s, qs ); diff --git a/tests/cppaql/normalizeTest.cpp b/tests/cppaql/normalizeTest.cpp index 03de54ab48..a1a8924cdd 100644 --- a/tests/cppaql/normalizeTest.cpp +++ b/tests/cppaql/normalizeTest.cpp @@ -26,7 +26,7 @@ TEST_CASE ( "Normalize test", "[integration]" ) { ext::concat ( "execute ", algorithm, " $cfg > $cfg2" ), ext::concat ( "execute grammar::generate::GenerateUpToLength $cfg ", STRING_LENGTHS, " > $str" ), ext::concat ( "execute grammar::generate::GenerateUpToLength $cfg2 ", STRING_LENGTHS, " > $str2" ), - "quit compare::TrieCompare $str $str2", + "quit compare::IsSame $str $str2", }; TimeoutAqlTest ( 1s, qs ); @@ -40,7 +40,7 @@ TEST_CASE ( "Normalize test", "[integration]" ) { ext::concat ( "execute ", algorithm, " $cfg > $cfg2" ), ext::concat ( "execute grammar::generate::GenerateUpToLength $cfg ", STRING_LENGTHS, " > $str" ), ext::concat ( "execute grammar::generate::GenerateUpToLength $cfg2 ", STRING_LENGTHS, " > $str2" ), - "quit compare::TrieCompare $str $str2", + "quit compare::IsSame $str $str2", }; TimeoutAqlTest ( 1s, qs ); diff --git a/tests/cppaql/treeNotationTest.cpp b/tests/cppaql/treeNotationTest.cpp index 457902fddf..3c687c3e7d 100644 --- a/tests/cppaql/treeNotationTest.cpp +++ b/tests/cppaql/treeNotationTest.cpp @@ -19,7 +19,7 @@ TEST_CASE ( "TreeNotation tests | Files", "[integration]" ) { ext::vector < std::string > qs = { ext::concat ( "execute < ", file, " > $res1" ), ext::concat ( "execute (RankedTree)", casts, "$res1 > $res2" ), - "quit compare::TreeCompare $res1 $res2", + "quit compare::IsSame $res1 $res2", }; TimeoutAqlTest ( 1s, qs ); @@ -33,7 +33,7 @@ TEST_CASE ( "TreeNotation tests | Files", "[integration]" ) { ext::vector < std::string > qs = { randomTree, ext::concat ( "execute (RankedTree)", casts, "$res1 > $res2" ), - "quit compare::TreeCompare $res1 $res2", + "quit compare::IsSame $res1 $res2", }; TimeoutAqlTest ( 2s, qs ); diff --git a/tests/cppaql/treeRepeatsTest.cpp b/tests/cppaql/treeRepeatsTest.cpp index c5271c80c7..ff0acc7507 100644 --- a/tests/cppaql/treeRepeatsTest.cpp +++ b/tests/cppaql/treeRepeatsTest.cpp @@ -23,7 +23,7 @@ TEST_CASE ( "TreeRepeats", "[integration]" ) { ext::concat ( "execute < ", file, " > $tree" ), "execute tree::properties::ExactSubtreeRepeatsNaive $tree | tree::simplify::NormalizeTreeLabels - > $res1", // naive ext::concat ( "execute ", pipeline, " > $res2" ), - "quit compare::TreeCompare $res1 $res2", + "quit compare::IsSame $res1 $res2", }; TimeoutAqlTest ( 2s, qs ); @@ -36,7 +36,7 @@ TEST_CASE ( "TreeRepeats", "[integration]" ) { ext::concat ( "execute tree::generate::RandomRankedTreeFactory ", HEIGHT, " ", SIZE, " ", rand ( ) % ALPHABET_SIZE + 1, " (bool)true 5 > $tree" ), "execute tree::properties::ExactSubtreeRepeatsNaive $tree | tree::simplify::NormalizeTreeLabels - > $res1", // naive ext::concat ( "execute ", pipeline, " > $res2" ), - "quit compare::TreeCompare $res1 $res2", + "quit compare::IsSame $res1 $res2", }; TimeoutAqlTest ( 2s, qs ); -- GitLab