| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <string> |
| 4 | #include <tuple> |
| 5 | #include <Common/SipHash.h> |
| 6 | |
| 7 | namespace DB |
| 8 | { |
| 9 | |
| 10 | struct QualifiedTableName |
| 11 | { |
| 12 | std::string database; |
| 13 | std::string table; |
| 14 | |
| 15 | bool operator==(const QualifiedTableName & other) const |
| 16 | { |
| 17 | return database == other.database && table == other.table; |
| 18 | } |
| 19 | |
| 20 | bool operator<(const QualifiedTableName & other) const |
| 21 | { |
| 22 | return std::forward_as_tuple(database, table) < std::forward_as_tuple(other.database, other.table); |
| 23 | } |
| 24 | |
| 25 | UInt64 hash() const |
| 26 | { |
| 27 | SipHash hash_state; |
| 28 | hash_state.update(database.data(), database.size()); |
| 29 | hash_state.update(table.data(), table.size()); |
| 30 | return hash_state.get64(); |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | } |
| 35 | |
| 36 | namespace std |
| 37 | { |
| 38 | |
| 39 | template <> struct hash<DB::QualifiedTableName> |
| 40 | { |
| 41 | using argument_type = DB::QualifiedTableName; |
| 42 | using result_type = size_t; |
| 43 | |
| 44 | result_type operator()(const argument_type & qualified_table) const |
| 45 | { |
| 46 | return qualified_table.hash(); |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | } |
| 51 |