Update children's parent position when the node get moved.
Bug: 6669677 Change-Id: Ifcaf784afd218c7afd70167045cd2aed8b7909c2main
parent
dd072e3201
commit
0243c9ae3d
|
@ -28,6 +28,7 @@ void DynamicPatriciaTrieNodeReader::fetchNodeInfoFromBufferAndProcessMovedNode(c
|
||||||
const bool usesAdditionalBuffer = mBuffer->isInAdditionalBuffer(nodePos);
|
const bool usesAdditionalBuffer = mBuffer->isInAdditionalBuffer(nodePos);
|
||||||
const uint8_t *const dictBuf = mBuffer->getBuffer(usesAdditionalBuffer);
|
const uint8_t *const dictBuf = mBuffer->getBuffer(usesAdditionalBuffer);
|
||||||
int pos = nodePos;
|
int pos = nodePos;
|
||||||
|
mHeadPos = nodePos;
|
||||||
if (usesAdditionalBuffer) {
|
if (usesAdditionalBuffer) {
|
||||||
pos -= mBuffer->getOriginalBufferSize();
|
pos -= mBuffer->getOriginalBufferSize();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,8 @@ class DynamicPatriciaTrieNodeReader {
|
||||||
const DictionaryBigramsStructurePolicy *const bigramsPolicy,
|
const DictionaryBigramsStructurePolicy *const bigramsPolicy,
|
||||||
const DictionaryShortcutsStructurePolicy *const shortcutsPolicy)
|
const DictionaryShortcutsStructurePolicy *const shortcutsPolicy)
|
||||||
: mBuffer(buffer), mBigramsPolicy(bigramsPolicy),
|
: mBuffer(buffer), mBigramsPolicy(bigramsPolicy),
|
||||||
mShortcutsPolicy(shortcutsPolicy), mNodePos(NOT_A_VALID_WORD_POS), mFlags(0),
|
mShortcutsPolicy(shortcutsPolicy), mNodePos(NOT_A_VALID_WORD_POS),
|
||||||
mParentPos(NOT_A_DICT_POS), mCodePointCount(0),
|
mHeadPos(NOT_A_DICT_POS), mFlags(0), mParentPos(NOT_A_DICT_POS), mCodePointCount(0),
|
||||||
mProbabilityFieldPos(NOT_A_DICT_POS), mProbability(NOT_A_PROBABILITY),
|
mProbabilityFieldPos(NOT_A_DICT_POS), mProbability(NOT_A_PROBABILITY),
|
||||||
mChildrenPosFieldPos(NOT_A_DICT_POS), mChildrenPos(NOT_A_DICT_POS),
|
mChildrenPosFieldPos(NOT_A_DICT_POS), mChildrenPos(NOT_A_DICT_POS),
|
||||||
mShortcutPos(NOT_A_DICT_POS), mBigramPos(NOT_A_DICT_POS),
|
mShortcutPos(NOT_A_DICT_POS), mBigramPos(NOT_A_DICT_POS),
|
||||||
|
@ -65,6 +65,11 @@ class DynamicPatriciaTrieNodeReader {
|
||||||
return mNodePos;
|
return mNodePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HeadPos is different from NodePos when the current PtNode is a moved PtNode.
|
||||||
|
AK_FORCE_INLINE int getHeadPos() const {
|
||||||
|
return mHeadPos;
|
||||||
|
}
|
||||||
|
|
||||||
// Flags
|
// Flags
|
||||||
AK_FORCE_INLINE bool isDeleted() const {
|
AK_FORCE_INLINE bool isDeleted() const {
|
||||||
return DynamicPatriciaTrieReadingUtils::isDeleted(mFlags);
|
return DynamicPatriciaTrieReadingUtils::isDeleted(mFlags);
|
||||||
|
@ -136,6 +141,7 @@ class DynamicPatriciaTrieNodeReader {
|
||||||
const DictionaryBigramsStructurePolicy *const mBigramsPolicy;
|
const DictionaryBigramsStructurePolicy *const mBigramsPolicy;
|
||||||
const DictionaryShortcutsStructurePolicy *const mShortcutsPolicy;
|
const DictionaryShortcutsStructurePolicy *const mShortcutsPolicy;
|
||||||
int mNodePos;
|
int mNodePos;
|
||||||
|
int mHeadPos;
|
||||||
DynamicPatriciaTrieReadingUtils::NodeFlags mFlags;
|
DynamicPatriciaTrieReadingUtils::NodeFlags mFlags;
|
||||||
int mParentPos;
|
int mParentPos;
|
||||||
uint8_t mCodePointCount;
|
uint8_t mCodePointCount;
|
||||||
|
|
|
@ -125,6 +125,24 @@ bool DynamicPatriciaTrieWritingHelper::markNodeAsMovedAndSetPosition(
|
||||||
mBuffer, movedPosOffset, &writingPos)) {
|
mBuffer, movedPosOffset, &writingPos)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (originalNode->hasChildren()) {
|
||||||
|
// Update children's parent position.
|
||||||
|
DynamicPatriciaTrieReadingHelper readingHelper(mBuffer, mBigramPolicy, mShortcutPolicy);
|
||||||
|
const DynamicPatriciaTrieNodeReader *const nodeReader = readingHelper.getNodeReader();
|
||||||
|
readingHelper.initWithNodeArrayPos(originalNode->getChildrenPos());
|
||||||
|
while (!readingHelper.isEnd()) {
|
||||||
|
const int childPtNodeWrittenPos = nodeReader->getHeadPos();
|
||||||
|
const int parentOffset = movedPos - childPtNodeWrittenPos;
|
||||||
|
int parentOffsetFieldPos = childPtNodeWrittenPos + 1 /* Flags */;
|
||||||
|
if (!DynamicPatriciaTrieWritingUtils::writeParentOffsetAndAdvancePosition(
|
||||||
|
mBuffer, parentOffset, &parentOffsetFieldPos)) {
|
||||||
|
// Parent offset cannot be written because of a bug or a broken dictionary; thus,
|
||||||
|
// we give up to update dictionary.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
readingHelper.readNextSiblingNode();
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue