2022-11-17 20:53:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-11-17 11:26:39 +00:00
|
|
|
#include <Analyzer/IQueryTreeNode.h>
|
|
|
|
|
|
|
|
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<QueryTreeNodeConstRawPtrWithHash, std::string> map;
|
|
|
|
*/
|
|
|
|
template <typename QueryTreeNodePtrType>
|
|
|
|
struct QueryTreeNodeWithHash
|
|
|
|
{
|
|
|
|
QueryTreeNodeWithHash(QueryTreeNodePtrType node_) /// NOLINT
|
|
|
|
: node(std::move(node_))
|
|
|
|
, hash(node->getTreeHash().first)
|
|
|
|
{}
|
|
|
|
|
|
|
|
QueryTreeNodePtrType node = nullptr;
|
|
|
|
size_t hash = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool operator==(const QueryTreeNodeWithHash<T> & lhs, const QueryTreeNodeWithHash<T> & rhs)
|
|
|
|
{
|
|
|
|
return lhs.hash == rhs.hash && lhs.node->isEqual(*rhs.node);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool operator!=(const QueryTreeNodeWithHash<T> & lhs, const QueryTreeNodeWithHash<T> & rhs)
|
|
|
|
{
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
using QueryTreeNodePtrWithHash = QueryTreeNodeWithHash<QueryTreeNodePtr>;
|
|
|
|
using QueryTreeNodeRawPtrWithHash = QueryTreeNodeWithHash<IQueryTreeNode *>;
|
|
|
|
using QueryTreeNodeConstRawPtrWithHash = QueryTreeNodeWithHash<const IQueryTreeNode *>;
|
|
|
|
|
2022-11-17 20:51:56 +00:00
|
|
|
using QueryTreeNodePtrWithHashSet = std::unordered_set<QueryTreeNodePtrWithHash>;
|
2022-11-17 11:26:39 +00:00
|
|
|
using QueryTreeNodeConstRawPtrWithHashSet = std::unordered_set<QueryTreeNodeConstRawPtrWithHash>;
|
|
|
|
|
|
|
|
template <typename Value>
|
2022-11-17 20:51:56 +00:00
|
|
|
using QueryTreeNodePtrWithHashMap = std::unordered_map<QueryTreeNodePtrWithHash, Value>;
|
2022-11-17 11:26:39 +00:00
|
|
|
|
|
|
|
template <typename Value>
|
|
|
|
using QueryTreeNodeConstRawPtrWithHashMap = std::unordered_map<QueryTreeNodeConstRawPtrWithHash, Value>;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct std::hash<DB::QueryTreeNodeWithHash<T>>
|
|
|
|
{
|
|
|
|
size_t operator()(const DB::QueryTreeNodeWithHash<T> & node_with_hash) const
|
|
|
|
{
|
|
|
|
return node_with_hash.hash;
|
|
|
|
}
|
|
|
|
};
|