Use CodePointArrayView to create children DicNodes.
Change-Id: Ie940b6595f3f3f804fbb8dd03c710ea062b75af3
This commit is contained in:
parent
87a5c76906
commit
521e2382da
6 changed files with 20 additions and 13 deletions
|
@ -26,6 +26,7 @@
|
|||
#include "suggest/core/dictionary/error_type_utils.h"
|
||||
#include "suggest/core/layout/proximity_info_state.h"
|
||||
#include "utils/char_utils.h"
|
||||
#include "utils/int_array_view.h"
|
||||
|
||||
#if DEBUG_DICT
|
||||
#define LOGI_SHOW_ADD_COST_PROP \
|
||||
|
@ -136,17 +137,17 @@ class DicNode {
|
|||
}
|
||||
|
||||
void initAsChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos,
|
||||
const int unigramProbability, const int wordId, const uint16_t mergedNodeCodePointCount,
|
||||
const int *const mergedNodeCodePoints) {
|
||||
const int unigramProbability, const int wordId,
|
||||
const CodePointArrayView mergedCodePoints) {
|
||||
uint16_t newDepth = static_cast<uint16_t>(dicNode->getNodeCodePointCount() + 1);
|
||||
mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion;
|
||||
const uint16_t newLeavingDepth = static_cast<uint16_t>(
|
||||
dicNode->mDicNodeProperties.getLeavingDepth() + mergedNodeCodePointCount);
|
||||
mDicNodeProperties.init(childrenPtNodeArrayPos, mergedNodeCodePoints[0],
|
||||
dicNode->mDicNodeProperties.getLeavingDepth() + mergedCodePoints.size());
|
||||
mDicNodeProperties.init(childrenPtNodeArrayPos, mergedCodePoints[0],
|
||||
unigramProbability, wordId, newDepth, newLeavingDepth,
|
||||
dicNode->mDicNodeProperties.getPrevWordIds());
|
||||
mDicNodeState.init(&dicNode->mDicNodeState, mergedNodeCodePointCount,
|
||||
mergedNodeCodePoints);
|
||||
mDicNodeState.init(&dicNode->mDicNodeState, mergedCodePoints.size(),
|
||||
mergedCodePoints.data());
|
||||
PROF_NODE_COPY(&dicNode->mProfiler, mProfiler);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "defines.h"
|
||||
#include "suggest/core/dicnode/dic_node.h"
|
||||
#include "utils/int_array_view.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
|
@ -60,11 +61,11 @@ class DicNodeVector {
|
|||
|
||||
void pushLeavingChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos,
|
||||
const int unigramProbability, const int wordId,
|
||||
const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) {
|
||||
const CodePointArrayView mergedCodePoints) {
|
||||
ASSERT(!mLock);
|
||||
mDicNodes.emplace_back();
|
||||
mDicNodes.back().initAsChild(dicNode, childrenPtNodeArrayPos, unigramProbability,
|
||||
wordId, mergedNodeCodePointCount, mergedNodeCodePoints);
|
||||
wordId, mergedCodePoints);
|
||||
}
|
||||
|
||||
DicNode *operator[](const int id) {
|
||||
|
|
|
@ -79,8 +79,7 @@ void Ver4PatriciaTriePolicy::createAndGetAllChildDicNodes(const DicNode *const d
|
|||
}
|
||||
const int wordId = isTerminal ? ptNodeParams.getHeadPos() : NOT_A_WORD_ID;
|
||||
childDicNodes->pushLeavingChild(dicNode, ptNodeParams.getChildrenPos(),
|
||||
ptNodeParams.getProbability(), wordId, ptNodeParams.getCodePointCount(),
|
||||
ptNodeParams.getCodePoints());
|
||||
ptNodeParams.getProbability(), wordId, ptNodeParams.getCodePointArrayView());
|
||||
}
|
||||
if (readingHelper.isError()) {
|
||||
mIsCorrupted = true;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "suggest/policyimpl/dictionary/structure/pt_common/patricia_trie_reading_utils.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.h"
|
||||
#include "utils/char_utils.h"
|
||||
#include "utils/int_array_view.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
|
@ -174,11 +175,17 @@ class PtNodeParams {
|
|||
return mParentPos;
|
||||
}
|
||||
|
||||
AK_FORCE_INLINE const CodePointArrayView getCodePointArrayView() const {
|
||||
return CodePointArrayView(mCodePoints, mCodePointCount);
|
||||
}
|
||||
|
||||
// TODO: Remove
|
||||
// Number of code points
|
||||
AK_FORCE_INLINE uint8_t getCodePointCount() const {
|
||||
return mCodePointCount;
|
||||
}
|
||||
|
||||
// TODO: Remove
|
||||
AK_FORCE_INLINE const int *getCodePoints() const {
|
||||
return mCodePoints;
|
||||
}
|
||||
|
|
|
@ -408,7 +408,7 @@ int PatriciaTriePolicy::createAndGetLeavingChildNode(const DicNode *const dicNod
|
|||
if (CharUtils::isInUnicodeSpace(mergedNodeCodePoints[0])) {
|
||||
const int wordId = PatriciaTrieReadingUtils::isTerminal(flags) ? ptNodePos : NOT_A_WORD_ID;
|
||||
childDicNodes->pushLeavingChild(dicNode, childrenPos, probability, wordId,
|
||||
mergedNodeCodePointCount, mergedNodeCodePoints);
|
||||
CodePointArrayView(mergedNodeCodePoints, mergedNodeCodePointCount));
|
||||
}
|
||||
return siblingPos;
|
||||
}
|
||||
|
|
|
@ -69,8 +69,7 @@ void Ver4PatriciaTriePolicy::createAndGetAllChildDicNodes(const DicNode *const d
|
|||
}
|
||||
const int wordId = isTerminal ? ptNodeParams.getTerminalId() : NOT_A_WORD_ID;
|
||||
childDicNodes->pushLeavingChild(dicNode, ptNodeParams.getChildrenPos(),
|
||||
ptNodeParams.getProbability(), wordId,
|
||||
ptNodeParams.getCodePointCount(), ptNodeParams.getCodePoints());
|
||||
ptNodeParams.getProbability(), wordId, ptNodeParams.getCodePointArrayView());
|
||||
}
|
||||
if (readingHelper.isError()) {
|
||||
mIsCorrupted = true;
|
||||
|
|
Loading…
Reference in a new issue