Use ReadOnlyByteArrayView in Ver2PtNodeArrayReader.
Change-Id: Ia1065465abdf7c64fadb3ff1efd2a4d2df343264main
parent
59ebd51718
commit
a892628fa3
|
@ -48,7 +48,7 @@ class PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
|||
mBigramListPolicy(mBuffer), mShortcutListPolicy(mBuffer),
|
||||
mPtNodeReader(mBuffer.data(), mBuffer.size(), &mBigramListPolicy,
|
||||
&mShortcutListPolicy),
|
||||
mPtNodeArrayReader(mBuffer.data(), mBuffer.size()),
|
||||
mPtNodeArrayReader(mBuffer),
|
||||
mTerminalPtNodePositionsForIteratingWords(), mIsCorrupted(false) {}
|
||||
|
||||
AK_FORCE_INLINE int getRootPosition() const {
|
||||
|
|
|
@ -22,16 +22,16 @@ namespace latinime {
|
|||
|
||||
bool Ver2PtNodeArrayReader::readPtNodeArrayInfoAndReturnIfValid(const int ptNodeArrayPos,
|
||||
int *const outPtNodeCount, int *const outFirstPtNodePos) const {
|
||||
if (ptNodeArrayPos < 0 || ptNodeArrayPos >= mDictSize) {
|
||||
if (ptNodeArrayPos < 0 || ptNodeArrayPos >= static_cast<int>(mBuffer.size())) {
|
||||
// Reading invalid position because of a bug or a broken dictionary.
|
||||
AKLOGE("Reading PtNode array info from invalid dictionary position: %d, dict size: %d",
|
||||
ptNodeArrayPos, mDictSize);
|
||||
AKLOGE("Reading PtNode array info from invalid dictionary position: %d, dict size: %zd",
|
||||
ptNodeArrayPos, mBuffer.size());
|
||||
ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
int readingPos = ptNodeArrayPos;
|
||||
const int ptNodeCountInArray = PatriciaTrieReadingUtils::getPtNodeArraySizeAndAdvancePosition(
|
||||
mDictBuffer, &readingPos);
|
||||
mBuffer.data(), &readingPos);
|
||||
*outPtNodeCount = ptNodeCountInArray;
|
||||
*outFirstPtNodePos = readingPos;
|
||||
return true;
|
||||
|
@ -39,10 +39,10 @@ bool Ver2PtNodeArrayReader::readPtNodeArrayInfoAndReturnIfValid(const int ptNode
|
|||
|
||||
bool Ver2PtNodeArrayReader::readForwardLinkAndReturnIfValid(const int forwordLinkPos,
|
||||
int *const outNextPtNodeArrayPos) const {
|
||||
if (forwordLinkPos < 0 || forwordLinkPos >= mDictSize) {
|
||||
if (forwordLinkPos < 0 || forwordLinkPos >= static_cast<int>(mBuffer.size())) {
|
||||
// Reading invalid position because of bug or broken dictionary.
|
||||
AKLOGE("Reading forward link from invalid dictionary position: %d, dict size: %d",
|
||||
forwordLinkPos, mDictSize);
|
||||
AKLOGE("Reading forward link from invalid dictionary position: %d, dict size: %zd",
|
||||
forwordLinkPos, mBuffer.size());
|
||||
ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -21,13 +21,13 @@
|
|||
|
||||
#include "defines.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_array_reader.h"
|
||||
#include "utils/byte_array_view.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
class Ver2PtNodeArrayReader : public PtNodeArrayReader {
|
||||
public:
|
||||
Ver2PtNodeArrayReader(const uint8_t *const dictBuffer, const int dictSize)
|
||||
: mDictBuffer(dictBuffer), mDictSize(dictSize) {};
|
||||
Ver2PtNodeArrayReader(const ReadOnlyByteArrayView buffer) : mBuffer(buffer) {};
|
||||
|
||||
virtual bool readPtNodeArrayInfoAndReturnIfValid(const int ptNodeArrayPos,
|
||||
int *const outPtNodeCount, int *const outFirstPtNodePos) const;
|
||||
|
@ -37,8 +37,7 @@ class Ver2PtNodeArrayReader : public PtNodeArrayReader {
|
|||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Ver2PtNodeArrayReader);
|
||||
|
||||
const uint8_t *const mDictBuffer;
|
||||
const int mDictSize;
|
||||
const ReadOnlyByteArrayView mBuffer;
|
||||
};
|
||||
} // namespace latinime
|
||||
#endif /* LATINIME_VER2_PT_NODE_ARRAY_READER_H */
|
||||
|
|
Loading…
Reference in New Issue