From 64a05bc972c48888cf2810a1409f0455e62abedb Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Fri, 17 May 2019 14:06:17 +0200 Subject: [PATCH] Use CHECK in TypedValueVectorCompare|Equal Reviewers: mtomic, llugovic Reviewed By: mtomic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2066 --- src/query/common.hpp | 4 +++- src/query/plan/operator.cpp | 32 +++++++++++++------------------- src/query/plan/operator.lcp | 11 ----------- 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/query/common.hpp b/src/query/common.hpp index 245af5a1c..76bdfb8f0 100644 --- a/src/query/common.hpp +++ b/src/query/common.hpp @@ -4,6 +4,8 @@ #include #include +#include + #include "database/graph_db_accessor.hpp" #include "query/exceptions.hpp" #include "query/frontend/ast/ast.hpp" @@ -50,7 +52,7 @@ class TypedValueVectorCompare final { const std::vector &c2) const { // ordering is invalid if there are more elements in the collections // then there are in the ordering_ vector - DCHECK(c1.size() <= ordering_.size() && c2.size() <= ordering_.size()) + CHECK(c1.size() <= ordering_.size() && c2.size() <= ordering_.size()) << "Collections contain more elements then there are orderings"; auto c1_it = c1.begin(); diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 80ea5495f..70f7597f7 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -56,25 +56,19 @@ namespace query::plan { -bool TypedValueVectorEqual::operator()( - const std::vector &left, - const std::vector &right) const { - DCHECK(left.size() == right.size()) - << "TypedValueVector comparison should only be done over vectors " - "of the same size"; - return std::equal(left.begin(), left.end(), right.begin(), - TypedValue::BoolEqual{}); -} - namespace { -struct TypedValueVectorAllocatorEqual { - bool operator()( - const std::vector> &left, - const std::vector> &right) - const { - return std::equal(left.begin(), left.end(), right.begin(), right.end(), - TypedValue::BoolEqual()); +// Custom equality function for a vector of typed values. +// Used in unordered_maps in Aggregate and Distinct operators. +struct TypedValueVectorEqual { + template + bool operator()(const std::vector &left, + const std::vector &right) const { + CHECK(left.size() == right.size()) + << "TypedValueVector comparison should only be done over vectors " + "of the same size"; + return std::equal(left.begin(), left.end(), right.begin(), + TypedValue::BoolEqual{}); } }; @@ -2489,7 +2483,7 @@ class AggregateCursor : public Cursor { std::vector>, TypedValue, TypedValue::Hash>, // custom equality - TypedValueVectorAllocatorEqual, + TypedValueVectorEqual, utils::Allocator< std::pair>, AggregationValue>>> @@ -3242,7 +3236,7 @@ class DistinctCursor : public Cursor { utils::FnvCollection< std::vector>, TypedValue, TypedValue::Hash>, - TypedValueVectorAllocatorEqual, + TypedValueVectorEqual, utils::Allocator>>> seen_rows_; }; diff --git a/src/query/plan/operator.lcp b/src/query/plan/operator.lcp index 898d89dfc..1eba32281 100644 --- a/src/query/plan/operator.lcp +++ b/src/query/plan/operator.lcp @@ -1541,17 +1541,6 @@ has been cached will be reconstructed before Pull returns. (:serialize (:slk)) (:clone)) -#>cpp -/** - * Custom equality function for a vector of typed values. - * Used in unordered_maps in Aggregate and Distinct operators. - */ -struct TypedValueVectorEqual { - bool operator()(const std::vector &left, - const std::vector &right) const; -}; -cpp<# - (lcp:define-class aggregate (logical-operator) ((input "std::shared_ptr" :scope :public :slk-save #'slk-save-operator-pointer