Merge "Remove mHasChildrenPtNodes from DicNodeProperties."

main
Keisuke Kuroyanagi 2014-09-09 06:03:36 +00:00 committed by Android (Google) Code Review
commit 72ee1c7ee5
6 changed files with 13 additions and 23 deletions

View File

@ -136,16 +136,15 @@ class DicNode {
} }
void initAsChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos, void initAsChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos,
const int probability, const int wordId, const bool hasChildren, const int probability, const int wordId, const bool isBlacklistedOrNotAWord,
const bool isBlacklistedOrNotAWord, const uint16_t mergedNodeCodePointCount, const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) {
const int *const mergedNodeCodePoints) {
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() + mergedNodeCodePointCount);
mDicNodeProperties.init(childrenPtNodeArrayPos, mergedNodeCodePoints[0], mDicNodeProperties.init(childrenPtNodeArrayPos, mergedNodeCodePoints[0],
probability, wordId, hasChildren, isBlacklistedOrNotAWord, newDepth, probability, wordId, isBlacklistedOrNotAWord, newDepth, newLeavingDepth,
newLeavingDepth, dicNode->mDicNodeProperties.getPrevWordIds()); dicNode->mDicNodeProperties.getPrevWordIds());
mDicNodeState.init(&dicNode->mDicNodeState, mergedNodeCodePointCount, mDicNodeState.init(&dicNode->mDicNodeState, mergedNodeCodePointCount,
mergedNodeCodePoints); mergedNodeCodePoints);
PROF_NODE_COPY(&dicNode->mProfiler, mProfiler); PROF_NODE_COPY(&dicNode->mProfiler, mProfiler);

View File

@ -59,14 +59,12 @@ class DicNodeVector {
} }
void pushLeavingChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos, void pushLeavingChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos,
const int probability, const int wordId, const bool hasChildren, const int probability, const int wordId, const bool isBlacklistedOrNotAWord,
const bool isBlacklistedOrNotAWord, const uint16_t mergedNodeCodePointCount, const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) {
const int *const mergedNodeCodePoints) {
ASSERT(!mLock); ASSERT(!mLock);
mDicNodes.emplace_back(); mDicNodes.emplace_back();
mDicNodes.back().initAsChild(dicNode, childrenPtNodeArrayPos, probability, mDicNodes.back().initAsChild(dicNode, childrenPtNodeArrayPos, probability,
wordId, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount, wordId, isBlacklistedOrNotAWord, mergedNodeCodePointCount, mergedNodeCodePoints);
mergedNodeCodePoints);
} }
DicNode *operator[](const int id) { DicNode *operator[](const int id) {

View File

@ -31,20 +31,18 @@ class DicNodeProperties {
AK_FORCE_INLINE DicNodeProperties() AK_FORCE_INLINE DicNodeProperties()
: mChildrenPtNodeArrayPos(NOT_A_DICT_POS), mProbability(NOT_A_PROBABILITY), : mChildrenPtNodeArrayPos(NOT_A_DICT_POS), mProbability(NOT_A_PROBABILITY),
mDicNodeCodePoint(NOT_A_CODE_POINT), mWordId(NOT_A_WORD_ID), mDicNodeCodePoint(NOT_A_CODE_POINT), mWordId(NOT_A_WORD_ID),
mHasChildrenPtNodes(false), mIsBlacklistedOrNotAWord(false), mDepth(0), mIsBlacklistedOrNotAWord(false), mDepth(0), mLeavingDepth(0) {}
mLeavingDepth(0) {}
~DicNodeProperties() {} ~DicNodeProperties() {}
// Should be called only once per DicNode is initialized. // Should be called only once per DicNode is initialized.
void init(const int childrenPos, const int nodeCodePoint, const int probability, void init(const int childrenPos, const int nodeCodePoint, const int probability,
const int wordId, const bool hasChildren, const bool isBlacklistedOrNotAWord, const int wordId, const bool isBlacklistedOrNotAWord, const uint16_t depth,
const uint16_t depth, const uint16_t leavingDepth, const int *const prevWordIds) { const uint16_t leavingDepth, const int *const prevWordIds) {
mChildrenPtNodeArrayPos = childrenPos; mChildrenPtNodeArrayPos = childrenPos;
mDicNodeCodePoint = nodeCodePoint; mDicNodeCodePoint = nodeCodePoint;
mProbability = probability; mProbability = probability;
mWordId = wordId; mWordId = wordId;
mHasChildrenPtNodes = hasChildren;
mIsBlacklistedOrNotAWord = isBlacklistedOrNotAWord; mIsBlacklistedOrNotAWord = isBlacklistedOrNotAWord;
mDepth = depth; mDepth = depth;
mLeavingDepth = leavingDepth; mLeavingDepth = leavingDepth;
@ -57,7 +55,6 @@ class DicNodeProperties {
mDicNodeCodePoint = NOT_A_CODE_POINT; mDicNodeCodePoint = NOT_A_CODE_POINT;
mProbability = NOT_A_PROBABILITY; mProbability = NOT_A_PROBABILITY;
mWordId = NOT_A_WORD_ID; mWordId = NOT_A_WORD_ID;
mHasChildrenPtNodes = true;
mIsBlacklistedOrNotAWord = false; mIsBlacklistedOrNotAWord = false;
mDepth = 0; mDepth = 0;
mLeavingDepth = 0; mLeavingDepth = 0;
@ -69,7 +66,6 @@ class DicNodeProperties {
mDicNodeCodePoint = dicNodeProp->mDicNodeCodePoint; mDicNodeCodePoint = dicNodeProp->mDicNodeCodePoint;
mProbability = dicNodeProp->mProbability; mProbability = dicNodeProp->mProbability;
mWordId = dicNodeProp->mWordId; mWordId = dicNodeProp->mWordId;
mHasChildrenPtNodes = dicNodeProp->mHasChildrenPtNodes;
mIsBlacklistedOrNotAWord = dicNodeProp->mIsBlacklistedOrNotAWord; mIsBlacklistedOrNotAWord = dicNodeProp->mIsBlacklistedOrNotAWord;
mDepth = dicNodeProp->mDepth; mDepth = dicNodeProp->mDepth;
mLeavingDepth = dicNodeProp->mLeavingDepth; mLeavingDepth = dicNodeProp->mLeavingDepth;
@ -82,7 +78,6 @@ class DicNodeProperties {
mDicNodeCodePoint = codePoint; // Overwrite the node char of a passing child mDicNodeCodePoint = codePoint; // Overwrite the node char of a passing child
mProbability = dicNodeProp->mProbability; mProbability = dicNodeProp->mProbability;
mWordId = dicNodeProp->mWordId; mWordId = dicNodeProp->mWordId;
mHasChildrenPtNodes = dicNodeProp->mHasChildrenPtNodes;
mIsBlacklistedOrNotAWord = dicNodeProp->mIsBlacklistedOrNotAWord; mIsBlacklistedOrNotAWord = dicNodeProp->mIsBlacklistedOrNotAWord;
mDepth = dicNodeProp->mDepth + 1; // Increment the depth of a passing child mDepth = dicNodeProp->mDepth + 1; // Increment the depth of a passing child
mLeavingDepth = dicNodeProp->mLeavingDepth; mLeavingDepth = dicNodeProp->mLeavingDepth;
@ -115,7 +110,7 @@ class DicNodeProperties {
} }
bool hasChildren() const { bool hasChildren() const {
return mHasChildrenPtNodes || mDepth != mLeavingDepth; return (mChildrenPtNodeArrayPos != NOT_A_DICT_POS) || mDepth != mLeavingDepth;
} }
bool isBlacklistedOrNotAWord() const { bool isBlacklistedOrNotAWord() const {
@ -138,7 +133,6 @@ class DicNodeProperties {
int mProbability; int mProbability;
int mDicNodeCodePoint; int mDicNodeCodePoint;
int mWordId; int mWordId;
bool mHasChildrenPtNodes;
bool mIsBlacklistedOrNotAWord; bool mIsBlacklistedOrNotAWord;
uint16_t mDepth; uint16_t mDepth;
uint16_t mLeavingDepth; uint16_t mLeavingDepth;

View File

@ -78,7 +78,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.hasChildren(), ptNodeParams.getProbability(), wordId,
ptNodeParams.isBlacklisted() ptNodeParams.isBlacklisted()
|| ptNodeParams.isNotAWord() /* isBlacklistedOrNotAWord */, || ptNodeParams.isNotAWord() /* isBlacklistedOrNotAWord */,
ptNodeParams.getCodePointCount(), ptNodeParams.getCodePoints()); ptNodeParams.getCodePointCount(), ptNodeParams.getCodePoints());

View File

@ -378,7 +378,6 @@ 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,
PatriciaTrieReadingUtils::hasChildrenInFlags(flags),
PatriciaTrieReadingUtils::isBlacklisted(flags) PatriciaTrieReadingUtils::isBlacklisted(flags)
|| PatriciaTrieReadingUtils::isNotAWord(flags), || PatriciaTrieReadingUtils::isNotAWord(flags),
mergedNodeCodePointCount, mergedNodeCodePoints); mergedNodeCodePointCount, mergedNodeCodePoints);

View File

@ -68,7 +68,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.hasChildren(), ptNodeParams.getProbability(), wordId,
ptNodeParams.isBlacklisted() ptNodeParams.isBlacklisted()
|| ptNodeParams.isNotAWord() /* isBlacklistedOrNotAWord */, || ptNodeParams.isNotAWord() /* isBlacklistedOrNotAWord */,
ptNodeParams.getCodePointCount(), ptNodeParams.getCodePoints()); ptNodeParams.getCodePointCount(), ptNodeParams.getCodePoints());