[base] Switch from uint8_t to size_t for errors counts in LevenshteinDFA.

This commit is contained in:
Yuri Gorshenin 2017-08-15 17:52:26 +03:00 committed by tatiana-kondakova
parent b64b273155
commit 1178e9ad68
2 changed files with 16 additions and 18 deletions

View file

@ -77,8 +77,7 @@ private:
bool FindRelevant(LevenshteinDFA::Position const & p, UniChar c, size_t & i) const
{
size_t const limit =
std::min(m_size - p.m_offset, static_cast<size_t>(p.m_errorsLeft) + 1);
size_t const limit = std::min(m_size - p.m_offset, p.m_errorsLeft + 1);
for (i = 0; i < limit; ++i)
{
@ -99,7 +98,7 @@ size_t const LevenshteinDFA::kStartingState = 0;
size_t const LevenshteinDFA::kRejectingState = 1;
// LevenshteinDFA::Position ------------------------------------------------------------------------
LevenshteinDFA::Position::Position(size_t offset, uint8_t errorsLeft, bool transposed)
LevenshteinDFA::Position::Position(size_t offset, size_t errorsLeft, bool transposed)
: m_offset(offset), m_errorsLeft(errorsLeft), m_transposed(transposed)
{
}
@ -109,7 +108,7 @@ bool LevenshteinDFA::Position::SubsumedBy(Position const & rhs) const
if (m_errorsLeft >= rhs.m_errorsLeft)
return false;
auto const errorsAvail = static_cast<uint8_t>(rhs.m_errorsLeft - m_errorsLeft);
auto const errorsAvail = rhs.m_errorsLeft - m_errorsLeft;
if (IsStandard() && rhs.IsStandard())
return AbsDiff(m_offset, rhs.m_offset) <= errorsAvail;
@ -170,7 +169,7 @@ void LevenshteinDFA::State::Normalize()
// LevenshteinDFA ----------------------------------------------------------------------------------
// static
LevenshteinDFA::LevenshteinDFA(UniString const & s, size_t prefixCharsToKeep, uint8_t maxErrors)
LevenshteinDFA::LevenshteinDFA(UniString const & s, size_t prefixCharsToKeep, size_t maxErrors)
: m_size(s.size()), m_maxErrors(maxErrors)
{
m_alphabet.assign(s.begin(), s.end());
@ -239,17 +238,17 @@ LevenshteinDFA::LevenshteinDFA(UniString const & s, size_t prefixCharsToKeep, ui
}
}
LevenshteinDFA::LevenshteinDFA(std::string const & s, size_t prefixCharsToKeep, uint8_t maxErrors)
LevenshteinDFA::LevenshteinDFA(std::string const & s, size_t prefixCharsToKeep, size_t maxErrors)
: LevenshteinDFA(MakeUniString(s), prefixCharsToKeep, maxErrors)
{
}
LevenshteinDFA::LevenshteinDFA(UniString const & s, uint8_t maxErrors)
LevenshteinDFA::LevenshteinDFA(UniString const & s, size_t maxErrors)
: LevenshteinDFA(s, 0 /* prefixCharsToKeep */, maxErrors)
{
}
LevenshteinDFA::LevenshteinDFA(std::string const & s, uint8_t maxErrors)
LevenshteinDFA::LevenshteinDFA(std::string const & s, size_t maxErrors)
: LevenshteinDFA(s, 0 /* prefixCharsToKeep */, maxErrors)
{
}
@ -315,8 +314,7 @@ size_t LevenshteinDFA::Move(size_t s, UniChar c) const
std::string DebugPrint(LevenshteinDFA::Position const & p)
{
std::ostringstream os;
os << "Position [" << p.m_offset << ", " << static_cast<uint32_t>(p.m_errorsLeft) << ", "
<< p.m_transposed << "]";
os << "Position [" << p.m_offset << ", " << p.m_errorsLeft << ", " << p.m_transposed << "]";
return os.str();
}

View file

@ -2,7 +2,7 @@
#include "base/string_utils.hpp"
#include <cstdint>
#include <cstddef>
#include <vector>
namespace strings
@ -34,7 +34,7 @@ public:
struct Position
{
Position() = default;
Position(size_t offset, uint8_t errorsLeft, bool transposed);
Position(size_t offset, size_t errorsLeft, bool transposed);
// SubsumedBy is a relation on two positions, which allows to
// efficiently remove unnecessary positions in a state. When the
@ -50,7 +50,7 @@ public:
inline bool IsTransposed() const { return m_transposed; }
size_t m_offset = 0;
uint8_t m_errorsLeft = 0;
size_t m_errorsLeft = 0;
bool m_transposed = false;
};
@ -89,10 +89,10 @@ public:
LevenshteinDFA const & m_dfa;
};
LevenshteinDFA(UniString const & s, size_t prefixCharsToKeep, uint8_t maxErrors);
LevenshteinDFA(std::string const & s, size_t prefixCharsToKeep, uint8_t maxErrors);
LevenshteinDFA(UniString const & s, uint8_t maxErrors);
LevenshteinDFA(std::string const & s, uint8_t maxErrors);
LevenshteinDFA(UniString const & s, size_t prefixCharsToKeep, size_t maxErrors);
LevenshteinDFA(std::string const & s, size_t prefixCharsToKeep, size_t maxErrors);
LevenshteinDFA(UniString const & s, size_t maxErrors);
LevenshteinDFA(std::string const & s, size_t maxErrors);
inline Iterator Begin() const { return Iterator(*this); }
@ -118,7 +118,7 @@ private:
size_t Move(size_t s, UniChar c) const;
size_t const m_size;
uint8_t const m_maxErrors;
size_t const m_maxErrors;
std::vector<UniChar> m_alphabet;