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