#pragma once #include namespace DB { /** This structure holds query tree node ptr and its hash. It can be used as hash map key to avoid unnecessary hash * recalculations. * * Example of usage: * std::unordered_map map; */ template struct QueryTreeNodeWithHash { QueryTreeNodeWithHash(QueryTreeNodePtrType node_) /// NOLINT : node(std::move(node_)) , hash(node->getTreeHash()) {} QueryTreeNodePtrType node = nullptr; CityHash_v1_0_2::uint128 hash; }; template inline bool operator==(const QueryTreeNodeWithHash & lhs, const QueryTreeNodeWithHash & rhs) { return lhs.hash == rhs.hash && lhs.node->isEqual(*rhs.node); } template inline bool operator!=(const QueryTreeNodeWithHash & lhs, const QueryTreeNodeWithHash & rhs) { return !(lhs == rhs); } using QueryTreeNodePtrWithHash = QueryTreeNodeWithHash; using QueryTreeNodeRawPtrWithHash = QueryTreeNodeWithHash; using QueryTreeNodeConstRawPtrWithHash = QueryTreeNodeWithHash; using QueryTreeNodePtrWithHashSet = std::unordered_set; using QueryTreeNodeConstRawPtrWithHashSet = std::unordered_set; template using QueryTreeNodePtrWithHashMap = std::unordered_map; template using QueryTreeNodeConstRawPtrWithHashMap = std::unordered_map; } template struct std::hash> { size_t operator()(const DB::QueryTreeNodeWithHash & node_with_hash) const { return node_with_hash.hash.low64; } };