2014-04-08 06:51:53 +00:00
|
|
|
#pragma once
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Types.h>
|
2017-07-10 03:28:12 +00:00
|
|
|
#include <Parsers/TokenIterator.h>
|
2010-06-24 19:12:10 +00:00
|
|
|
#include <map>
|
2017-02-02 22:08:19 +00:00
|
|
|
#include <memory>
|
2018-05-16 10:25:10 +00:00
|
|
|
#include <Common/SipHash.h>
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
struct StringRange
|
|
|
|
{
|
2018-02-26 03:37:08 +00:00
|
|
|
const char * first = nullptr;
|
|
|
|
const char * second = nullptr;
|
2017-07-10 03:28:12 +00:00
|
|
|
|
2018-05-16 10:25:10 +00:00
|
|
|
StringRange() = default;
|
2017-07-10 03:28:12 +00:00
|
|
|
StringRange(const char * begin, const char * end) : first(begin), second(end) {}
|
2018-05-16 10:25:10 +00:00
|
|
|
explicit StringRange(TokenIterator token) : first(token->begin), second(token->end) {}
|
2017-07-12 19:20:57 +00:00
|
|
|
|
|
|
|
StringRange(TokenIterator token_begin, TokenIterator token_end)
|
|
|
|
{
|
|
|
|
/// Empty range.
|
|
|
|
if (token_begin == token_end)
|
|
|
|
{
|
|
|
|
first = token_begin->begin;
|
|
|
|
second = token_begin->begin;
|
2017-09-06 02:37:36 +00:00
|
|
|
return;
|
2017-07-12 19:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TokenIterator token_last = token_end;
|
|
|
|
--token_last;
|
|
|
|
|
|
|
|
first = token_begin->begin;
|
|
|
|
second = token_last->end;
|
|
|
|
}
|
2017-07-10 03:28:12 +00:00
|
|
|
};
|
|
|
|
|
2016-05-28 10:15:36 +00:00
|
|
|
using StringPtr = std::shared_ptr<String>;
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2016-11-23 19:58:33 +00:00
|
|
|
|
|
|
|
inline String toString(const StringRange & range)
|
|
|
|
{
|
2018-02-26 03:37:08 +00:00
|
|
|
return range.first ? String(range.first, range.second) : String();
|
2016-11-23 19:58:33 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 10:47:27 +00:00
|
|
|
/// Hashes only the values of pointers in StringRange. Is used with StringRangePointersEqualTo comparator.
|
|
|
|
struct StringRangePointersHash
|
2018-05-16 10:25:10 +00:00
|
|
|
{
|
|
|
|
UInt64 operator()(const StringRange & range) const
|
|
|
|
{
|
|
|
|
SipHash hash;
|
|
|
|
hash.update(range.first);
|
|
|
|
hash.update(range.second);
|
|
|
|
return hash.get64();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-21 10:47:27 +00:00
|
|
|
/// 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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-10 04:02:56 +00:00
|
|
|
}
|
2018-05-16 10:25:10 +00:00
|
|
|
|