Use CHECK in TypedValueVectorCompare|Equal

Reviewers: mtomic, llugovic

Reviewed By: mtomic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2066
This commit is contained in:
Teon Banek 2019-05-17 14:06:17 +02:00
parent e4fd49a530
commit 64a05bc972
3 changed files with 16 additions and 31 deletions

View File

@ -4,6 +4,8 @@
#include <cstdint>
#include <string>
#include <glog/logging.h>
#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<TypedValue, TAllocator> &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();

View File

@ -56,25 +56,19 @@
namespace query::plan {
bool TypedValueVectorEqual::operator()(
const std::vector<TypedValue> &left,
const std::vector<TypedValue> &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<TypedValue, utils::Allocator<TypedValue>> &left,
const std::vector<TypedValue, utils::Allocator<TypedValue>> &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 <class TAllocator>
bool operator()(const std::vector<TypedValue, TAllocator> &left,
const std::vector<TypedValue, TAllocator> &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, utils::Allocator<TypedValue>>, TypedValue,
TypedValue::Hash>,
// custom equality
TypedValueVectorAllocatorEqual,
TypedValueVectorEqual,
utils::Allocator<
std::pair<const std::vector<TypedValue, utils::Allocator<TypedValue>>,
AggregationValue>>>
@ -3242,7 +3236,7 @@ class DistinctCursor : public Cursor {
utils::FnvCollection<
std::vector<TypedValue, utils::Allocator<TypedValue>>, TypedValue,
TypedValue::Hash>,
TypedValueVectorAllocatorEqual,
TypedValueVectorEqual,
utils::Allocator<std::vector<TypedValue, utils::Allocator<TypedValue>>>>
seen_rows_;
};

View File

@ -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<TypedValue> &left,
const std::vector<TypedValue> &right) const;
};
cpp<#
(lcp:define-class aggregate (logical-operator)
((input "std::shared_ptr<LogicalOperator>" :scope :public
:slk-save #'slk-save-operator-pointer