Merge "Stop passing buffer directly to DynamicPtReadingHelper."
commit
64faafbb0e
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
class BufferWithExtendableBuffer;
|
|
||||||
class DictionaryBigramsStructurePolicy;
|
class DictionaryBigramsStructurePolicy;
|
||||||
class DictionaryShortcutsStructurePolicy;
|
class DictionaryShortcutsStructurePolicy;
|
||||||
class PtNodeArrayReader;
|
class PtNodeArrayReader;
|
||||||
|
@ -75,12 +74,10 @@ class DynamicPtReadingHelper {
|
||||||
std::vector<int> *const mTerminalPositions;
|
std::vector<int> *const mTerminalPositions;
|
||||||
};
|
};
|
||||||
|
|
||||||
DynamicPtReadingHelper(const BufferWithExtendableBuffer *const buffer,
|
DynamicPtReadingHelper(const PtNodeReader *const ptNodeReader,
|
||||||
const PtNodeReader *const ptNodeReader,
|
|
||||||
const PtNodeArrayReader *const ptNodeArrayReader)
|
const PtNodeArrayReader *const ptNodeArrayReader)
|
||||||
: mIsError(false), mReadingState(), mBuffer(buffer),
|
: mIsError(false), mReadingState(), mPtNodeReader(ptNodeReader),
|
||||||
mPtNodeReader(ptNodeReader), mPtNodeArrayReader(ptNodeArrayReader),
|
mPtNodeArrayReader(ptNodeArrayReader), mReadingStateStack() {}
|
||||||
mReadingStateStack() {}
|
|
||||||
|
|
||||||
~DynamicPtReadingHelper() {}
|
~DynamicPtReadingHelper() {}
|
||||||
|
|
||||||
|
@ -255,7 +252,6 @@ class DynamicPtReadingHelper {
|
||||||
// TODO: Introduce error code to track what caused the error.
|
// TODO: Introduce error code to track what caused the error.
|
||||||
bool mIsError;
|
bool mIsError;
|
||||||
PtNodeReadingState mReadingState;
|
PtNodeReadingState mReadingState;
|
||||||
const BufferWithExtendableBuffer *const mBuffer;
|
|
||||||
const PtNodeReader *const mPtNodeReader;
|
const PtNodeReader *const mPtNodeReader;
|
||||||
const PtNodeArrayReader *const mPtNodeArrayReader;
|
const PtNodeArrayReader *const mPtNodeArrayReader;
|
||||||
std::vector<PtNodeReadingState> mReadingStateStack;
|
std::vector<PtNodeReadingState> mReadingStateStack;
|
||||||
|
|
|
@ -44,8 +44,8 @@ class Ver4PatriciaTrieNodeWriter : public PtNodeWriter {
|
||||||
const PtNodeArrayReader *const ptNodeArrayReader,
|
const PtNodeArrayReader *const ptNodeArrayReader,
|
||||||
Ver4BigramListPolicy *const bigramPolicy, Ver4ShortcutListPolicy *const shortcutPolicy)
|
Ver4BigramListPolicy *const bigramPolicy, Ver4ShortcutListPolicy *const shortcutPolicy)
|
||||||
: mTrieBuffer(trieBuffer), mBuffers(buffers),
|
: mTrieBuffer(trieBuffer), mBuffers(buffers),
|
||||||
mReadingHelper(mTrieBuffer, ptNodeReader, ptNodeArrayReader),
|
mReadingHelper(ptNodeReader, ptNodeArrayReader), mBigramPolicy(bigramPolicy),
|
||||||
mBigramPolicy(bigramPolicy), mShortcutPolicy(shortcutPolicy) {}
|
mShortcutPolicy(shortcutPolicy) {}
|
||||||
|
|
||||||
virtual ~Ver4PatriciaTrieNodeWriter() {}
|
virtual ~Ver4PatriciaTrieNodeWriter() {}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ void Ver4PatriciaTriePolicy::createAndGetAllChildDicNodes(const DicNode *const d
|
||||||
if (!dicNode->hasChildren()) {
|
if (!dicNode->hasChildren()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DynamicPtReadingHelper readingHelper(mDictBuffer, &mNodeReader, &mPtNodeArrayReader);
|
DynamicPtReadingHelper readingHelper(&mNodeReader, &mPtNodeArrayReader);
|
||||||
readingHelper.initWithPtNodeArrayPos(dicNode->getChildrenPtNodeArrayPos());
|
readingHelper.initWithPtNodeArrayPos(dicNode->getChildrenPtNodeArrayPos());
|
||||||
while (!readingHelper.isEnd()) {
|
while (!readingHelper.isEnd()) {
|
||||||
const PtNodeParams ptNodeParams = readingHelper.getPtNodeParams();
|
const PtNodeParams ptNodeParams = readingHelper.getPtNodeParams();
|
||||||
|
@ -70,7 +70,7 @@ void Ver4PatriciaTriePolicy::createAndGetAllChildDicNodes(const DicNode *const d
|
||||||
int Ver4PatriciaTriePolicy::getCodePointsAndProbabilityAndReturnCodePointCount(
|
int Ver4PatriciaTriePolicy::getCodePointsAndProbabilityAndReturnCodePointCount(
|
||||||
const int ptNodePos, const int maxCodePointCount, int *const outCodePoints,
|
const int ptNodePos, const int maxCodePointCount, int *const outCodePoints,
|
||||||
int *const outUnigramProbability) const {
|
int *const outUnigramProbability) const {
|
||||||
DynamicPtReadingHelper readingHelper(mDictBuffer, &mNodeReader, &mPtNodeArrayReader);
|
DynamicPtReadingHelper readingHelper(&mNodeReader, &mPtNodeArrayReader);
|
||||||
readingHelper.initWithPtNodePos(ptNodePos);
|
readingHelper.initWithPtNodePos(ptNodePos);
|
||||||
return readingHelper.getCodePointsAndProbabilityAndReturnCodePointCount(
|
return readingHelper.getCodePointsAndProbabilityAndReturnCodePointCount(
|
||||||
maxCodePointCount, outCodePoints, outUnigramProbability);
|
maxCodePointCount, outCodePoints, outUnigramProbability);
|
||||||
|
@ -78,7 +78,7 @@ int Ver4PatriciaTriePolicy::getCodePointsAndProbabilityAndReturnCodePointCount(
|
||||||
|
|
||||||
int Ver4PatriciaTriePolicy::getTerminalPtNodePositionOfWord(const int *const inWord,
|
int Ver4PatriciaTriePolicy::getTerminalPtNodePositionOfWord(const int *const inWord,
|
||||||
const int length, const bool forceLowerCaseSearch) const {
|
const int length, const bool forceLowerCaseSearch) const {
|
||||||
DynamicPtReadingHelper readingHelper(mDictBuffer, &mNodeReader, &mPtNodeArrayReader);
|
DynamicPtReadingHelper readingHelper(&mNodeReader, &mPtNodeArrayReader);
|
||||||
readingHelper.initWithPtNodeArrayPos(getRootPosition());
|
readingHelper.initWithPtNodeArrayPos(getRootPosition());
|
||||||
return readingHelper.getTerminalPtNodePositionOfWord(inWord, length, forceLowerCaseSearch);
|
return readingHelper.getTerminalPtNodePositionOfWord(inWord, length, forceLowerCaseSearch);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ bool Ver4PatriciaTriePolicy::addUnigramWord(const int *const word, const int len
|
||||||
shortcutLength);
|
shortcutLength);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
DynamicPtReadingHelper readingHelper(mDictBuffer, &mNodeReader, &mPtNodeArrayReader);
|
DynamicPtReadingHelper readingHelper(&mNodeReader, &mPtNodeArrayReader);
|
||||||
readingHelper.initWithPtNodeArrayPos(getRootPosition());
|
readingHelper.initWithPtNodeArrayPos(getRootPosition());
|
||||||
bool addedNewUnigram = false;
|
bool addedNewUnigram = false;
|
||||||
if (mUpdatingHelper.addUnigramWord(&readingHelper, word, length, probability, isNotAWord,
|
if (mUpdatingHelper.addUnigramWord(&readingHelper, word, length, probability, isNotAWord,
|
||||||
|
@ -397,7 +397,7 @@ int Ver4PatriciaTriePolicy::getNextWordAndNextToken(const int token, int *const
|
||||||
mTerminalPtNodePositionsForIteratingWords.clear();
|
mTerminalPtNodePositionsForIteratingWords.clear();
|
||||||
DynamicPtReadingHelper::TraversePolicyToGetAllTerminalPtNodePositions traversePolicy(
|
DynamicPtReadingHelper::TraversePolicyToGetAllTerminalPtNodePositions traversePolicy(
|
||||||
&mTerminalPtNodePositionsForIteratingWords);
|
&mTerminalPtNodePositionsForIteratingWords);
|
||||||
DynamicPtReadingHelper readingHelper(mDictBuffer, &mNodeReader, &mPtNodeArrayReader);
|
DynamicPtReadingHelper readingHelper(&mNodeReader, &mPtNodeArrayReader);
|
||||||
readingHelper.initWithPtNodeArrayPos(getRootPosition());
|
readingHelper.initWithPtNodeArrayPos(getRootPosition());
|
||||||
readingHelper.traverseAllPtNodesInPostorderDepthFirstManner(&traversePolicy);
|
readingHelper.traverseAllPtNodesInPostorderDepthFirstManner(&traversePolicy);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,8 +83,7 @@ bool Ver4PatriciaTrieWritingHelper::runGC(const int rootPtNodeArrayPos,
|
||||||
Ver4PatriciaTrieNodeWriter ptNodeWriter(mBuffers->getWritableTrieBuffer(),
|
Ver4PatriciaTrieNodeWriter ptNodeWriter(mBuffers->getWritableTrieBuffer(),
|
||||||
mBuffers, &ptNodeReader, &ptNodeArrayReader, &bigramPolicy, &shortcutPolicy);
|
mBuffers, &ptNodeReader, &ptNodeArrayReader, &bigramPolicy, &shortcutPolicy);
|
||||||
|
|
||||||
DynamicPtReadingHelper readingHelper(mBuffers->getTrieBuffer(), &ptNodeReader,
|
DynamicPtReadingHelper readingHelper(&ptNodeReader, &ptNodeArrayReader);
|
||||||
&ptNodeArrayReader);
|
|
||||||
readingHelper.initWithPtNodeArrayPos(rootPtNodeArrayPos);
|
readingHelper.initWithPtNodeArrayPos(rootPtNodeArrayPos);
|
||||||
DynamicPtGcEventListeners
|
DynamicPtGcEventListeners
|
||||||
::TraversePolicyToUpdateUnigramProbabilityAndMarkUselessPtNodesAsDeleted
|
::TraversePolicyToUpdateUnigramProbabilityAndMarkUselessPtNodesAsDeleted
|
||||||
|
@ -168,8 +167,7 @@ bool Ver4PatriciaTrieWritingHelper::runGC(const int rootPtNodeArrayPos,
|
||||||
mBuffers->getShortcutDictContent())) {
|
mBuffers->getShortcutDictContent())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
DynamicPtReadingHelper newDictReadingHelper(buffersToWrite->getTrieBuffer(),
|
DynamicPtReadingHelper newDictReadingHelper(&newPtNodeReader, &newPtNodeArrayreader);
|
||||||
&newPtNodeReader, &newPtNodeArrayreader);
|
|
||||||
newDictReadingHelper.initWithPtNodeArrayPos(rootPtNodeArrayPos);
|
newDictReadingHelper.initWithPtNodeArrayPos(rootPtNodeArrayPos);
|
||||||
DynamicPtGcEventListeners::TraversePolicyToUpdateAllPositionFields
|
DynamicPtGcEventListeners::TraversePolicyToUpdateAllPositionFields
|
||||||
traversePolicyToUpdateAllPositionFields(&newPtNodeWriter, &dictPositionRelocationMap);
|
traversePolicyToUpdateAllPositionFields(&newPtNodeWriter, &dictPositionRelocationMap);
|
||||||
|
|
Loading…
Reference in New Issue