Merge "Use ReadOnlyByteArrayView in Ver2ParticiaTrieNodeReader."
commit
b349b57476
|
@ -46,10 +46,9 @@ class PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
|||
FormatUtils::VERSION_2),
|
||||
mBuffer(mMmappedBuffer->getReadOnlyByteArrayView().skip(mHeaderPolicy.getSize())),
|
||||
mBigramListPolicy(mBuffer), mShortcutListPolicy(mBuffer),
|
||||
mPtNodeReader(mBuffer.data(), mBuffer.size(), &mBigramListPolicy,
|
||||
&mShortcutListPolicy),
|
||||
mPtNodeArrayReader(mBuffer),
|
||||
mTerminalPtNodePositionsForIteratingWords(), mIsCorrupted(false) {}
|
||||
mPtNodeReader(mBuffer, &mBigramListPolicy, &mShortcutListPolicy),
|
||||
mPtNodeArrayReader(mBuffer), mTerminalPtNodePositionsForIteratingWords(),
|
||||
mIsCorrupted(false) {}
|
||||
|
||||
AK_FORCE_INLINE int getRootPosition() const {
|
||||
return 0;
|
||||
|
|
|
@ -22,10 +22,10 @@ namespace latinime {
|
|||
|
||||
const PtNodeParams Ver2ParticiaTrieNodeReader::fetchPtNodeParamsInBufferFromPtNodePos(
|
||||
const int ptNodePos) const {
|
||||
if (ptNodePos < 0 || ptNodePos >= mDictSize) {
|
||||
if (ptNodePos < 0 || ptNodePos >= static_cast<int>(mBuffer.size())) {
|
||||
// Reading invalid position because of bug or broken dictionary.
|
||||
AKLOGE("Fetching PtNode info from invalid dictionary position: %d, dictionary size: %d",
|
||||
ptNodePos, mDictSize);
|
||||
AKLOGE("Fetching PtNode info from invalid dictionary position: %d, dictionary size: %zd",
|
||||
ptNodePos, mBuffer.size());
|
||||
ASSERT(false);
|
||||
return PtNodeParams();
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ const PtNodeParams Ver2ParticiaTrieNodeReader::fetchPtNodeParamsInBufferFromPtNo
|
|||
int shortcutPos = NOT_A_DICT_POS;
|
||||
int bigramPos = NOT_A_DICT_POS;
|
||||
int siblingPos = NOT_A_DICT_POS;
|
||||
PatriciaTrieReadingUtils::readPtNodeInfo(mDictBuffer, ptNodePos, mShortuctPolicy,
|
||||
PatriciaTrieReadingUtils::readPtNodeInfo(mBuffer.data(), ptNodePos, mShortuctPolicy,
|
||||
mBigramPolicy, &flags, &mergedNodeCodePointCount, mergedNodeCodePoints, &probability,
|
||||
&childrenPos, &shortcutPos, &bigramPos, &siblingPos);
|
||||
if (mergedNodeCodePointCount <= 0) {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "defines.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_params.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_reader.h"
|
||||
#include "utils/byte_array_view.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
|
@ -30,19 +31,17 @@ class DictionaryShortcutsStructurePolicy;
|
|||
|
||||
class Ver2ParticiaTrieNodeReader : public PtNodeReader {
|
||||
public:
|
||||
Ver2ParticiaTrieNodeReader(const uint8_t *const dictBuffer, const int dictSize,
|
||||
Ver2ParticiaTrieNodeReader(const ReadOnlyByteArrayView buffer,
|
||||
const DictionaryBigramsStructurePolicy *const bigramPolicy,
|
||||
const DictionaryShortcutsStructurePolicy *const shortcutPolicy)
|
||||
: mDictBuffer(dictBuffer), mDictSize(dictSize), mBigramPolicy(bigramPolicy),
|
||||
mShortuctPolicy(shortcutPolicy) {}
|
||||
: mBuffer(buffer), mBigramPolicy(bigramPolicy), mShortuctPolicy(shortcutPolicy) {}
|
||||
|
||||
virtual const PtNodeParams fetchPtNodeParamsInBufferFromPtNodePos(const int ptNodePos) const;
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(Ver2ParticiaTrieNodeReader);
|
||||
|
||||
const uint8_t *const mDictBuffer;
|
||||
const int mDictSize;
|
||||
const ReadOnlyByteArrayView mBuffer;
|
||||
const DictionaryBigramsStructurePolicy *const mBigramPolicy;
|
||||
const DictionaryShortcutsStructurePolicy *const mShortuctPolicy;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue