forked from organicmaps/organicmaps
[search] Implicit TokenRange.
This commit is contained in:
parent
3634449c05
commit
08dd5edd71
9 changed files with 29 additions and 16 deletions
|
@ -83,12 +83,12 @@ struct ScopedMarkTokens
|
|||
: m_usedTokens(usedTokens), m_range(range)
|
||||
{
|
||||
ASSERT(m_range.IsValid(), ());
|
||||
ASSERT_LESS_OR_EQUAL(m_range.m_end, m_usedTokens.size(), ());
|
||||
ASSERT_LESS_OR_EQUAL(m_range.End(), m_usedTokens.size(), ());
|
||||
#if defined(DEBUG)
|
||||
for (size_t i : m_range)
|
||||
ASSERT(!m_usedTokens[i], (i));
|
||||
#endif
|
||||
fill(m_usedTokens.begin() + m_range.m_begin, m_usedTokens.begin() + m_range.m_end,
|
||||
fill(m_usedTokens.begin() + m_range.Begin(), m_usedTokens.begin() + m_range.End(),
|
||||
true /* used */);
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ struct ScopedMarkTokens
|
|||
for (size_t i : m_range)
|
||||
ASSERT(m_usedTokens[i], (i));
|
||||
#endif
|
||||
fill(m_usedTokens.begin() + m_range.m_begin, m_usedTokens.begin() + m_range.m_end,
|
||||
fill(m_usedTokens.begin() + m_range.Begin(), m_usedTokens.begin() + m_range.End(),
|
||||
false /* used */);
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ void JoinQueryTokens(QueryParams const & params, TokenRange const & range, UniSt
|
|||
for (size_t i : range)
|
||||
{
|
||||
res.append(params.GetToken(i).m_original);
|
||||
if (i + 1 != range.m_end)
|
||||
if (i + 1 != range.End())
|
||||
res.append(sep);
|
||||
}
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ void Geocoder::InitLayer(SearchModel::SearchType type, TokenRange const & tokenR
|
|||
|
||||
JoinQueryTokens(m_params, layer.m_tokenRange, kUniSpace /* sep */, layer.m_subQuery);
|
||||
layer.m_lastTokenIsPrefix =
|
||||
!layer.m_tokenRange.Empty() && m_params.IsPrefixToken(layer.m_tokenRange.m_end - 1);
|
||||
!layer.m_tokenRange.Empty() && m_params.IsPrefixToken(layer.m_tokenRange.End() - 1);
|
||||
}
|
||||
|
||||
void Geocoder::FillLocalityCandidates(BaseContext const & ctx, CBV const & filter,
|
||||
|
|
|
@ -24,7 +24,7 @@ bool BaseContext::AllTokensUsed() const
|
|||
bool BaseContext::HasUsedTokensInRange(TokenRange const & range) const
|
||||
{
|
||||
ASSERT(range.IsValid(), (range));
|
||||
return any_of(m_usedTokens.begin() + range.m_begin, m_usedTokens.begin() + range.m_end,
|
||||
return any_of(m_usedTokens.begin() + range.Begin(), m_usedTokens.begin() + range.End(),
|
||||
IdFunctor());
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace search
|
||||
{
|
||||
class FeaturesFilter;
|
||||
struct TokenRange;
|
||||
class TokenRange;
|
||||
|
||||
struct BaseContext
|
||||
{
|
||||
|
|
|
@ -42,7 +42,7 @@ struct ComparePreResult1
|
|||
auto const & rinfo = rhs.GetInfo();
|
||||
if (linfo.GetNumTokens() != rinfo.GetNumTokens())
|
||||
return linfo.GetNumTokens() > rinfo.GetNumTokens();
|
||||
return linfo.m_tokenRange.m_begin < rinfo.m_tokenRange.m_begin;
|
||||
return linfo.m_tokenRange.Begin() < rinfo.m_tokenRange.Begin();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ QueryParams::Token & QueryParams::GetToken(size_t i)
|
|||
bool QueryParams::IsNumberTokens(TokenRange const & range) const
|
||||
{
|
||||
ASSERT(range.IsValid(), (range));
|
||||
ASSERT_LESS_OR_EQUAL(range.m_end, GetNumTokens(), ());
|
||||
ASSERT_LESS_OR_EQUAL(range.End(), GetNumTokens(), ());
|
||||
|
||||
for (size_t i : range)
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
namespace search
|
||||
{
|
||||
struct TokenRange;
|
||||
class TokenRange;
|
||||
|
||||
class QueryParams
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ bool LessByHash(StreetsMatcher::Prediction const & lhs, StreetsMatcher::Predicti
|
|||
if (lhs.GetNumTokens() != rhs.GetNumTokens())
|
||||
return lhs.GetNumTokens() > rhs.GetNumTokens();
|
||||
|
||||
return lhs.m_tokenRange.m_begin < rhs.m_tokenRange.m_begin;
|
||||
return lhs.m_tokenRange.Begin() < rhs.m_tokenRange.Begin();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "search/common.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
#include "base/range_iterator.hpp"
|
||||
|
||||
|
@ -9,11 +11,16 @@
|
|||
|
||||
namespace search
|
||||
{
|
||||
struct TokenRange final
|
||||
class TokenRange final
|
||||
{
|
||||
public:
|
||||
TokenRange() = default;
|
||||
TokenRange(size_t begin, size_t end) : m_begin(begin), m_end(end)
|
||||
TokenRange(size_t begin, size_t end)
|
||||
: m_begin(static_cast<uint8_t>(begin)), m_end(static_cast<uint8_t>(end))
|
||||
|
||||
{
|
||||
ASSERT_LESS_OR_EQUAL(begin, MAX_TOKENS, ());
|
||||
ASSERT_LESS_OR_EQUAL(end, MAX_TOKENS, ());
|
||||
ASSERT(IsValid(), (*this));
|
||||
}
|
||||
|
||||
|
@ -52,14 +59,20 @@ struct TokenRange final
|
|||
return m_begin == rhs.m_begin && m_end == rhs.m_end;
|
||||
}
|
||||
|
||||
inline size_t Begin() const { return m_begin; }
|
||||
inline size_t End() const { return m_end; }
|
||||
|
||||
inline my::RangeIterator<size_t> begin() const { return my::RangeIterator<size_t>(m_begin); }
|
||||
inline my::RangeIterator<size_t> end() const { return my::RangeIterator<size_t>(m_end); }
|
||||
|
||||
inline my::RangeIterator<size_t> cbegin() const { return my::RangeIterator<size_t>(m_begin); }
|
||||
inline my::RangeIterator<size_t> cend() const { return my::RangeIterator<size_t>(m_end); }
|
||||
|
||||
size_t m_begin = 0;
|
||||
size_t m_end = 0;
|
||||
private:
|
||||
friend std::string DebugPrint(TokenRange const & tokenRange);
|
||||
|
||||
uint8_t m_begin = 0;
|
||||
uint8_t m_end = 0;
|
||||
};
|
||||
|
||||
inline std::string DebugPrint(TokenRange const & tokenRange)
|
||||
|
|
|
@ -24,7 +24,7 @@ string SliceToString(string const & name, TSlice const & slice)
|
|||
|
||||
// TokenSlice --------------------------------------------------------------------------------------
|
||||
TokenSlice::TokenSlice(QueryParams const & params, TokenRange const & range)
|
||||
: m_params(params), m_offset(range.m_begin), m_size(range.Size())
|
||||
: m_params(params), m_offset(range.Begin()), m_size(range.Size())
|
||||
{
|
||||
ASSERT(range.IsValid(), (range));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue