Skip to content

Commit

Permalink
add Hash for in_expression
Browse files Browse the repository at this point in the history
  • Loading branch information
yangzq50 committed Nov 26, 2024
1 parent 72aecd4 commit d1c8f55
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/expression/in_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,37 @@ String InExpression::ToString() const {
return op.str();
}

u64 InExpression::Hash() const {
auto h = left_operand_ptr_->Hash();
for (const auto &arg : arguments_) {
h ^= arg->Hash();
}
if (in_type_ != InType::kIn) {
h ^= 0x1;
}
return h;
}

bool InExpression::Eq(const BaseExpression &other_base) const {
if (other_base.type() != ExpressionType::kIn) {
return false;
}
const auto &other = static_cast<const InExpression &>(other_base);
if (in_type_ != other.in_type_) {
return false;
}
if (!left_operand_ptr_->Eq(*other.left_operand_ptr_)) {
return false;
}
if (arguments_.size() != other.arguments_.size()) {
return false;
}
for (SizeT i = 0; i < arguments_.size(); ++i) {
if (!arguments_[i]->Eq(*other.arguments_[i])) {
return false;
}
}
return true;
}

} // namespace infinity
4 changes: 4 additions & 0 deletions src/expression/in_expression.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public:

inline DataType TypeOfArguments() const { return set_.Type(); }

u64 Hash() const override;

bool Eq(const BaseExpression &other) const override;

private:
SharedPtr<BaseExpression> left_operand_ptr_;
InType in_type_;
Expand Down

0 comments on commit d1c8f55

Please sign in to comment.