am 0be559d9: Merge "Use CodePointArrayView in DictionaryUtils."

* commit '0be559d907b6caf5f5155a70735eead13e98c3a2':
  Use CodePointArrayView in DictionaryUtils.
main
Keisuke Kuroyanagi 2014-09-17 12:37:26 +00:00 committed by Android Git Automerger
commit 7656ac947e
3 changed files with 8 additions and 7 deletions

View File

@ -109,7 +109,7 @@ int Dictionary::getProbability(const CodePointArrayView codePoints) const {
int Dictionary::getMaxProbabilityOfExactMatches(const CodePointArrayView codePoints) const { int Dictionary::getMaxProbabilityOfExactMatches(const CodePointArrayView codePoints) const {
TimeKeeper::setCurrentTime(); TimeKeeper::setCurrentTime();
return DictionaryUtils::getMaxProbabilityOfExactMatches( return DictionaryUtils::getMaxProbabilityOfExactMatches(
mDictionaryStructureWithBufferPolicy.get(), codePoints.data(), codePoints.size()); mDictionaryStructureWithBufferPolicy.get(), codePoints);
} }
int Dictionary::getNgramProbability(const PrevWordsInfo *const prevWordsInfo, int Dictionary::getNgramProbability(const PrevWordsInfo *const prevWordsInfo,

View File

@ -29,7 +29,7 @@ namespace latinime {
/* static */ int DictionaryUtils::getMaxProbabilityOfExactMatches( /* static */ int DictionaryUtils::getMaxProbabilityOfExactMatches(
const DictionaryStructureWithBufferPolicy *const dictionaryStructurePolicy, const DictionaryStructureWithBufferPolicy *const dictionaryStructurePolicy,
const int *const codePoints, const int codePointCount) { const CodePointArrayView codePoints) {
std::vector<DicNode> current; std::vector<DicNode> current;
std::vector<DicNode> next; std::vector<DicNode> next;
@ -40,16 +40,16 @@ namespace latinime {
dictionaryStructurePolicy, &prevWordIdArray, false /* tryLowerCaseSearch */); dictionaryStructurePolicy, &prevWordIdArray, false /* tryLowerCaseSearch */);
current.emplace_back(); current.emplace_back();
DicNodeUtils::initAsRoot(dictionaryStructurePolicy, prevWordIds, &current.front()); DicNodeUtils::initAsRoot(dictionaryStructurePolicy, prevWordIds, &current.front());
for (int i = 0; i < codePointCount; ++i) { for (const int codePoint : codePoints) {
// The base-lower input is used to ignore case errors and accent errors. // The base-lower input is used to ignore case errors and accent errors.
const int codePoint = CharUtils::toBaseLowerCase(codePoints[i]); const int baseLowerCodePoint = CharUtils::toBaseLowerCase(codePoint);
for (const DicNode &dicNode : current) { for (const DicNode &dicNode : current) {
if (dicNode.isInDigraph() && dicNode.getNodeCodePoint() == codePoint) { if (dicNode.isInDigraph() && dicNode.getNodeCodePoint() == baseLowerCodePoint) {
next.emplace_back(dicNode); next.emplace_back(dicNode);
next.back().advanceDigraphIndex(); next.back().advanceDigraphIndex();
continue; continue;
} }
processChildDicNodes(dictionaryStructurePolicy, codePoint, &dicNode, &next); processChildDicNodes(dictionaryStructurePolicy, baseLowerCodePoint, &dicNode, &next);
} }
current.clear(); current.clear();
current.swap(next); current.swap(next);

View File

@ -20,6 +20,7 @@
#include <vector> #include <vector>
#include "defines.h" #include "defines.h"
#include "utils/int_array_view.h"
namespace latinime { namespace latinime {
@ -30,7 +31,7 @@ class DictionaryUtils {
public: public:
static int getMaxProbabilityOfExactMatches( static int getMaxProbabilityOfExactMatches(
const DictionaryStructureWithBufferPolicy *const dictionaryStructurePolicy, const DictionaryStructureWithBufferPolicy *const dictionaryStructurePolicy,
const int *const codePoints, const int codePointCount); const CodePointArrayView codePoints);
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(DictionaryUtils); DISALLOW_IMPLICIT_CONSTRUCTORS(DictionaryUtils);