Merge pull request #2395 from yandex/string_range-pointers-comparsion

Renamed StringRangeHash to StringRangePointersHash and added StringRa…
This commit is contained in:
alexey-milovidov 2018-05-21 22:42:42 +03:00 committed by GitHub
commit 55cfebc36b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View File

@ -23,7 +23,9 @@ using ASTPtr = std::shared_ptr<IAST>;
class Set;
using SetPtr = std::shared_ptr<Set>;
using PreparedSets = std::unordered_map<StringRange, SetPtr, StringRangeHash>;
/// Will compare sets by their position in query string. It's possible because IAST::clone() doesn't chane IAST::range.
/// It should be taken into account when we want to change AST part which contains sets.
using PreparedSets = std::unordered_map<StringRange, SetPtr, StringRangePointersHash, StringRangePointersEqualTo>;
class IBlockInputStream;
using BlockInputStreamPtr = std::shared_ptr<IBlockInputStream>;

View File

@ -36,8 +36,6 @@ struct StringRange
first = token_begin->begin;
second = token_last->end;
}
bool operator==(const StringRange & rhs) const { return std::tie(first, second) == std::tie(rhs.first, rhs.second); }
};
using StringPtr = std::shared_ptr<String>;
@ -48,7 +46,8 @@ inline String toString(const StringRange & range)
return range.first ? String(range.first, range.second) : String();
}
struct StringRangeHash
/// Hashes only the values of pointers in StringRange. Is used with StringRangePointersEqualTo comparator.
struct StringRangePointersHash
{
UInt64 operator()(const StringRange & range) const
{
@ -59,5 +58,15 @@ struct StringRangeHash
}
};
}
/// Ranges are equal only when they point to the same memory region.
/// It may be used when it's enough to compare substrings by their position in the same string.
struct StringRangePointersEqualTo
{
constexpr bool operator()(const StringRange &lhs, const StringRange &rhs) const
{
return std::tie(lhs.first, lhs.second) == std::tie(rhs.first, rhs.second);
}
};
};

View File

@ -14,7 +14,7 @@ class Set;
using SetPtr = std::shared_ptr<Set>;
/// Information about calculated sets in right hand side of IN.
using PreparedSets = std::unordered_map<StringRange, SetPtr, StringRangeHash>;
using PreparedSets = std::unordered_map<StringRange, SetPtr, StringRangePointersHash, StringRangePointersEqualTo>;
/** Query along with some additional data,