am 664d5c87: Merge "Use CodePointArrayView to create children DicNodes."

* commit '664d5c87a9319b5745290ccf4a1c04ccfa0e48d5':
  Use CodePointArrayView to create children DicNodes.
main
Keisuke Kuroyanagi 2014-09-10 13:06:39 +00:00 committed by Android Git Automerger
commit 7b1c2d24b9
6 changed files with 20 additions and 13 deletions

View File

@ -26,6 +26,7 @@
#include "suggest/core/dictionary/error_type_utils.h" #include "suggest/core/dictionary/error_type_utils.h"
#include "suggest/core/layout/proximity_info_state.h" #include "suggest/core/layout/proximity_info_state.h"
#include "utils/char_utils.h" #include "utils/char_utils.h"
#include "utils/int_array_view.h"
#if DEBUG_DICT #if DEBUG_DICT
#define LOGI_SHOW_ADD_COST_PROP \ #define LOGI_SHOW_ADD_COST_PROP \
@ -136,17 +137,17 @@ class DicNode {
} }
void initAsChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos, void initAsChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos,
const int unigramProbability, const int wordId, const uint16_t mergedNodeCodePointCount, const int unigramProbability, const int wordId,
const int *const mergedNodeCodePoints) { const CodePointArrayView mergedCodePoints) {
uint16_t newDepth = static_cast<uint16_t>(dicNode->getNodeCodePointCount() + 1); uint16_t newDepth = static_cast<uint16_t>(dicNode->getNodeCodePointCount() + 1);
mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion; mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion;
const uint16_t newLeavingDepth = static_cast<uint16_t>( const uint16_t newLeavingDepth = static_cast<uint16_t>(
dicNode->mDicNodeProperties.getLeavingDepth() + mergedNodeCodePointCount); dicNode->mDicNodeProperties.getLeavingDepth() + mergedCodePoints.size());
mDicNodeProperties.init(childrenPtNodeArrayPos, mergedNodeCodePoints[0], mDicNodeProperties.init(childrenPtNodeArrayPos, mergedCodePoints[0],
unigramProbability, wordId, newDepth, newLeavingDepth, unigramProbability, wordId, newDepth, newLeavingDepth,
dicNode->mDicNodeProperties.getPrevWordIds()); dicNode->mDicNodeProperties.getPrevWordIds());
mDicNodeState.init(&dicNode->mDicNodeState, mergedNodeCodePointCount, mDicNodeState.init(&dicNode->mDicNodeState, mergedCodePoints.size(),
mergedNodeCodePoints); mergedCodePoints.data());
PROF_NODE_COPY(&dicNode->mProfiler, mProfiler); PROF_NODE_COPY(&dicNode->mProfiler, mProfiler);
} }

View File

@ -21,6 +21,7 @@
#include "defines.h" #include "defines.h"
#include "suggest/core/dicnode/dic_node.h" #include "suggest/core/dicnode/dic_node.h"
#include "utils/int_array_view.h"
namespace latinime { namespace latinime {
@ -60,11 +61,11 @@ class DicNodeVector {
void pushLeavingChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos, void pushLeavingChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos,
const int unigramProbability, const int wordId, const int unigramProbability, const int wordId,
const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) { const CodePointArrayView mergedCodePoints) {
ASSERT(!mLock); ASSERT(!mLock);
mDicNodes.emplace_back(); mDicNodes.emplace_back();
mDicNodes.back().initAsChild(dicNode, childrenPtNodeArrayPos, unigramProbability, mDicNodes.back().initAsChild(dicNode, childrenPtNodeArrayPos, unigramProbability,
wordId, mergedNodeCodePointCount, mergedNodeCodePoints); wordId, mergedCodePoints);
} }
DicNode *operator[](const int id) { DicNode *operator[](const int id) {

View File

@ -79,8 +79,7 @@ void Ver4PatriciaTriePolicy::createAndGetAllChildDicNodes(const DicNode *const d
} }
const int wordId = isTerminal ? ptNodeParams.getHeadPos() : NOT_A_WORD_ID; const int wordId = isTerminal ? ptNodeParams.getHeadPos() : NOT_A_WORD_ID;
childDicNodes->pushLeavingChild(dicNode, ptNodeParams.getChildrenPos(), childDicNodes->pushLeavingChild(dicNode, ptNodeParams.getChildrenPos(),
ptNodeParams.getProbability(), wordId, ptNodeParams.getCodePointCount(), ptNodeParams.getProbability(), wordId, ptNodeParams.getCodePointArrayView());
ptNodeParams.getCodePoints());
} }
if (readingHelper.isError()) { if (readingHelper.isError()) {
mIsCorrupted = true; mIsCorrupted = true;

View File

@ -24,6 +24,7 @@
#include "suggest/policyimpl/dictionary/structure/pt_common/patricia_trie_reading_utils.h" #include "suggest/policyimpl/dictionary/structure/pt_common/patricia_trie_reading_utils.h"
#include "suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.h" #include "suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.h"
#include "utils/char_utils.h" #include "utils/char_utils.h"
#include "utils/int_array_view.h"
namespace latinime { namespace latinime {
@ -174,11 +175,17 @@ class PtNodeParams {
return mParentPos; return mParentPos;
} }
AK_FORCE_INLINE const CodePointArrayView getCodePointArrayView() const {
return CodePointArrayView(mCodePoints, mCodePointCount);
}
// TODO: Remove
// Number of code points // Number of code points
AK_FORCE_INLINE uint8_t getCodePointCount() const { AK_FORCE_INLINE uint8_t getCodePointCount() const {
return mCodePointCount; return mCodePointCount;
} }
// TODO: Remove
AK_FORCE_INLINE const int *getCodePoints() const { AK_FORCE_INLINE const int *getCodePoints() const {
return mCodePoints; return mCodePoints;
} }

View File

@ -408,7 +408,7 @@ int PatriciaTriePolicy::createAndGetLeavingChildNode(const DicNode *const dicNod
if (CharUtils::isInUnicodeSpace(mergedNodeCodePoints[0])) { if (CharUtils::isInUnicodeSpace(mergedNodeCodePoints[0])) {
const int wordId = PatriciaTrieReadingUtils::isTerminal(flags) ? ptNodePos : NOT_A_WORD_ID; const int wordId = PatriciaTrieReadingUtils::isTerminal(flags) ? ptNodePos : NOT_A_WORD_ID;
childDicNodes->pushLeavingChild(dicNode, childrenPos, probability, wordId, childDicNodes->pushLeavingChild(dicNode, childrenPos, probability, wordId,
mergedNodeCodePointCount, mergedNodeCodePoints); CodePointArrayView(mergedNodeCodePoints, mergedNodeCodePointCount));
} }
return siblingPos; return siblingPos;
} }

View File

@ -69,8 +69,7 @@ void Ver4PatriciaTriePolicy::createAndGetAllChildDicNodes(const DicNode *const d
} }
const int wordId = isTerminal ? ptNodeParams.getTerminalId() : NOT_A_WORD_ID; const int wordId = isTerminal ? ptNodeParams.getTerminalId() : NOT_A_WORD_ID;
childDicNodes->pushLeavingChild(dicNode, ptNodeParams.getChildrenPos(), childDicNodes->pushLeavingChild(dicNode, ptNodeParams.getChildrenPos(),
ptNodeParams.getProbability(), wordId, ptNodeParams.getProbability(), wordId, ptNodeParams.getCodePointArrayView());
ptNodeParams.getCodePointCount(), ptNodeParams.getCodePoints());
} }
if (readingHelper.isError()) { if (readingHelper.isError()) {
mIsCorrupted = true; mIsCorrupted = true;