Move methods using ByteArrayUtils from .h to .cpp.
Bug: 10402083 Change-Id: Ic5f1aa11eb403f5bdc83de8e38a6457200519cae
This commit is contained in:
parent
f874728496
commit
9ea9c61c99
8 changed files with 120 additions and 89 deletions
|
@ -38,6 +38,22 @@ const BigramListReadWriteUtils::BigramFlags
|
||||||
BigramListReadWriteUtils::MASK_ATTRIBUTE_PROBABILITY = 0x0F;
|
BigramListReadWriteUtils::MASK_ATTRIBUTE_PROBABILITY = 0x0F;
|
||||||
const int BigramListReadWriteUtils::ATTRIBUTE_ADDRESS_SHIFT = 4;
|
const int BigramListReadWriteUtils::ATTRIBUTE_ADDRESS_SHIFT = 4;
|
||||||
|
|
||||||
|
/* static */ BigramListReadWriteUtils::BigramFlags
|
||||||
|
BigramListReadWriteUtils::getFlagsAndForwardPointer(const uint8_t *const bigramsBuf,
|
||||||
|
int *const pos) {
|
||||||
|
return ByteArrayUtils::readUint8AndAdvancePosition(bigramsBuf, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ void BigramListReadWriteUtils::skipExistingBigrams(const uint8_t *const bigramsBuf,
|
||||||
|
int *const pos) {
|
||||||
|
BigramFlags flags = getFlagsAndForwardPointer(bigramsBuf, pos);
|
||||||
|
while (hasNext(flags)) {
|
||||||
|
*pos += attributeAddressSize(flags);
|
||||||
|
flags = getFlagsAndForwardPointer(bigramsBuf, pos);
|
||||||
|
}
|
||||||
|
*pos += attributeAddressSize(flags);
|
||||||
|
}
|
||||||
|
|
||||||
/* static */ int BigramListReadWriteUtils::getBigramAddressAndForwardPointer(
|
/* static */ int BigramListReadWriteUtils::getBigramAddressAndForwardPointer(
|
||||||
const uint8_t *const bigramsBuf, const BigramFlags flags, int *const pos) {
|
const uint8_t *const bigramsBuf, const BigramFlags flags, int *const pos) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "suggest/policyimpl/dictionary/utils/byte_array_utils.h"
|
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -29,10 +28,7 @@ class BigramListReadWriteUtils {
|
||||||
public:
|
public:
|
||||||
typedef uint8_t BigramFlags;
|
typedef uint8_t BigramFlags;
|
||||||
|
|
||||||
static AK_FORCE_INLINE BigramFlags getFlagsAndForwardPointer(
|
static BigramFlags getFlagsAndForwardPointer(const uint8_t *const bigramsBuf, int *const pos);
|
||||||
const uint8_t *const bigramsBuf, int *const pos) {
|
|
||||||
return ByteArrayUtils::readUint8AndAdvancePosition(bigramsBuf, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
static AK_FORCE_INLINE int getProbabilityFromFlags(const BigramFlags flags) {
|
static AK_FORCE_INLINE int getProbabilityFromFlags(const BigramFlags flags) {
|
||||||
return flags & MASK_ATTRIBUTE_PROBABILITY;
|
return flags & MASK_ATTRIBUTE_PROBABILITY;
|
||||||
|
@ -43,15 +39,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bigrams reading methods
|
// Bigrams reading methods
|
||||||
static AK_FORCE_INLINE void skipExistingBigrams(const uint8_t *const bigramsBuf,
|
static void skipExistingBigrams(const uint8_t *const bigramsBuf, int *const pos);
|
||||||
int *const pos) {
|
|
||||||
BigramFlags flags = getFlagsAndForwardPointer(bigramsBuf, pos);
|
|
||||||
while (hasNext(flags)) {
|
|
||||||
*pos += attributeAddressSize(flags);
|
|
||||||
flags = getFlagsAndForwardPointer(bigramsBuf, pos);
|
|
||||||
}
|
|
||||||
*pos += attributeAddressSize(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getBigramAddressAndForwardPointer(const uint8_t *const bigramsBuf,
|
static int getBigramAddressAndForwardPointer(const uint8_t *const bigramsBuf,
|
||||||
const BigramFlags flags, int *const pos);
|
const BigramFlags flags, int *const pos);
|
||||||
|
|
|
@ -28,6 +28,17 @@ const DptReadingUtils::NodeFlags DptReadingUtils::FLAG_IS_NOT_MOVED = 0xC0;
|
||||||
const DptReadingUtils::NodeFlags DptReadingUtils::FLAG_IS_MOVED = 0x40;
|
const DptReadingUtils::NodeFlags DptReadingUtils::FLAG_IS_MOVED = 0x40;
|
||||||
const DptReadingUtils::NodeFlags DptReadingUtils::FLAG_IS_DELETED = 0x80;
|
const DptReadingUtils::NodeFlags DptReadingUtils::FLAG_IS_DELETED = 0x80;
|
||||||
|
|
||||||
|
/* static */ int DptReadingUtils::getForwardLinkPosition(const uint8_t *const buffer,
|
||||||
|
const int pos) {
|
||||||
|
int linkAddressPos = pos;
|
||||||
|
return ByteArrayUtils::readSint24AndAdvancePosition(buffer, &linkAddressPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ int DptReadingUtils::getParentPosAndAdvancePosition(const uint8_t *const buffer,
|
||||||
|
int *const pos) {
|
||||||
|
return ByteArrayUtils::readSint24AndAdvancePosition(buffer, pos);
|
||||||
|
}
|
||||||
|
|
||||||
/* static */ int DptReadingUtils::readChildrenPositionAndAdvancePosition(
|
/* static */ int DptReadingUtils::readChildrenPositionAndAdvancePosition(
|
||||||
const uint8_t *const buffer, int *const pos) {
|
const uint8_t *const buffer, int *const pos) {
|
||||||
const int base = *pos;
|
const int base = *pos;
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "suggest/policyimpl/dictionary/utils/byte_array_utils.h"
|
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -28,19 +27,13 @@ class DynamicPatriciaTrieReadingUtils {
|
||||||
public:
|
public:
|
||||||
typedef uint8_t NodeFlags;
|
typedef uint8_t NodeFlags;
|
||||||
|
|
||||||
static AK_FORCE_INLINE int getForwardLinkPosition(const uint8_t *const buffer, const int pos) {
|
static int getForwardLinkPosition(const uint8_t *const buffer, const int pos);
|
||||||
int linkAddressPos = pos;
|
|
||||||
return ByteArrayUtils::readSint24AndAdvancePosition(buffer, &linkAddressPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
static AK_FORCE_INLINE bool isValidForwardLinkPosition(const int forwardLinkAddress) {
|
static AK_FORCE_INLINE bool isValidForwardLinkPosition(const int forwardLinkAddress) {
|
||||||
return forwardLinkAddress != 0;
|
return forwardLinkAddress != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AK_FORCE_INLINE int getParentPosAndAdvancePosition(const uint8_t *const buffer,
|
static int getParentPosAndAdvancePosition(const uint8_t *const buffer, int *const pos);
|
||||||
int *const pos) {
|
|
||||||
return ByteArrayUtils::readSint24AndAdvancePosition(buffer, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int readChildrenPositionAndAdvancePosition(const uint8_t *const buffer, int *const pos);
|
static int readChildrenPositionAndAdvancePosition(const uint8_t *const buffer, int *const pos);
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,63 @@ const PtReadingUtils::NodeFlags PtReadingUtils::FLAG_IS_NOT_A_WORD = 0x02;
|
||||||
// Flag for blacklist
|
// Flag for blacklist
|
||||||
const PtReadingUtils::NodeFlags PtReadingUtils::FLAG_IS_BLACKLISTED = 0x01;
|
const PtReadingUtils::NodeFlags PtReadingUtils::FLAG_IS_BLACKLISTED = 0x01;
|
||||||
|
|
||||||
|
/* static */ int PtReadingUtils::getPtNodeArraySizeAndAdvancePosition(
|
||||||
|
const uint8_t *const buffer, int *const pos) {
|
||||||
|
const uint8_t firstByte = ByteArrayUtils::readUint8AndAdvancePosition(buffer, pos);
|
||||||
|
if (firstByte < 0x80) {
|
||||||
|
return firstByte;
|
||||||
|
} else {
|
||||||
|
return ((firstByte & 0x7F) << 8) ^ ByteArrayUtils::readUint8AndAdvancePosition(
|
||||||
|
buffer, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ PtReadingUtils::NodeFlags PtReadingUtils::getFlagsAndAdvancePosition(
|
||||||
|
const uint8_t *const buffer, int *const pos) {
|
||||||
|
return ByteArrayUtils::readUint8AndAdvancePosition(buffer, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ int PtReadingUtils::getCodePointAndAdvancePosition(const uint8_t *const buffer,
|
||||||
|
int *const pos) {
|
||||||
|
return ByteArrayUtils::readCodePointAndAdvancePosition(buffer, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the number of read characters.
|
||||||
|
/* static */ int PtReadingUtils::getCharsAndAdvancePosition(const uint8_t *const buffer,
|
||||||
|
const NodeFlags flags, const int maxLength, int *const outBuffer, int *const pos) {
|
||||||
|
int length = 0;
|
||||||
|
if (hasMultipleChars(flags)) {
|
||||||
|
length = ByteArrayUtils::readStringAndAdvancePosition(buffer, maxLength, outBuffer,
|
||||||
|
pos);
|
||||||
|
} else {
|
||||||
|
if (maxLength > 0) {
|
||||||
|
outBuffer[0] = getCodePointAndAdvancePosition(buffer, pos);
|
||||||
|
length = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the number of skipped characters.
|
||||||
|
/* static */ int PtReadingUtils::skipCharacters(const uint8_t *const buffer, const NodeFlags flags,
|
||||||
|
const int maxLength, int *const pos) {
|
||||||
|
if (hasMultipleChars(flags)) {
|
||||||
|
return ByteArrayUtils::advancePositionToBehindString(buffer, maxLength, pos);
|
||||||
|
} else {
|
||||||
|
if (maxLength > 0) {
|
||||||
|
getCodePointAndAdvancePosition(buffer, pos);
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ int PtReadingUtils::readProbabilityAndAdvancePosition(const uint8_t *const buffer,
|
||||||
|
int *const pos) {
|
||||||
|
return ByteArrayUtils::readUint8AndAdvancePosition(buffer, pos);
|
||||||
|
}
|
||||||
|
|
||||||
/* static */ int PtReadingUtils::readChildrenPositionAndAdvancePosition(
|
/* static */ int PtReadingUtils::readChildrenPositionAndAdvancePosition(
|
||||||
const uint8_t *const buffer, const NodeFlags flags, int *const pos) {
|
const uint8_t *const buffer, const NodeFlags flags, int *const pos) {
|
||||||
const int base = *pos;
|
const int base = *pos;
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "suggest/policyimpl/dictionary/utils/byte_array_utils.h"
|
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -28,62 +27,21 @@ class PatriciaTrieReadingUtils {
|
||||||
public:
|
public:
|
||||||
typedef uint8_t NodeFlags;
|
typedef uint8_t NodeFlags;
|
||||||
|
|
||||||
static AK_FORCE_INLINE int getPtNodeArraySizeAndAdvancePosition(
|
static int getPtNodeArraySizeAndAdvancePosition(const uint8_t *const buffer, int *const pos);
|
||||||
const uint8_t *const buffer, int *const pos) {
|
|
||||||
const uint8_t firstByte = ByteArrayUtils::readUint8AndAdvancePosition(buffer, pos);
|
|
||||||
if (firstByte < 0x80) {
|
|
||||||
return firstByte;
|
|
||||||
} else {
|
|
||||||
return ((firstByte & 0x7F) << 8) ^ ByteArrayUtils::readUint8AndAdvancePosition(
|
|
||||||
buffer, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static AK_FORCE_INLINE NodeFlags getFlagsAndAdvancePosition(const uint8_t *const buffer,
|
static NodeFlags getFlagsAndAdvancePosition(const uint8_t *const buffer, int *const pos);
|
||||||
int *const pos) {
|
|
||||||
return ByteArrayUtils::readUint8AndAdvancePosition(buffer, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
static AK_FORCE_INLINE int getCodePointAndAdvancePosition(const uint8_t *const buffer,
|
static int getCodePointAndAdvancePosition(const uint8_t *const buffer, int *const pos);
|
||||||
int *const pos) {
|
|
||||||
return ByteArrayUtils::readCodePointAndAdvancePosition(buffer, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the number of read characters.
|
// Returns the number of read characters.
|
||||||
static AK_FORCE_INLINE int getCharsAndAdvancePosition(const uint8_t *const buffer,
|
static int getCharsAndAdvancePosition(const uint8_t *const buffer, const NodeFlags flags,
|
||||||
const NodeFlags flags, const int maxLength, int *const outBuffer, int *const pos) {
|
const int maxLength, int *const outBuffer, int *const pos);
|
||||||
int length = 0;
|
|
||||||
if (hasMultipleChars(flags)) {
|
|
||||||
length = ByteArrayUtils::readStringAndAdvancePosition(buffer, maxLength, outBuffer,
|
|
||||||
pos);
|
|
||||||
} else {
|
|
||||||
if (maxLength > 0) {
|
|
||||||
outBuffer[0] = getCodePointAndAdvancePosition(buffer, pos);
|
|
||||||
length = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the number of skipped characters.
|
// Returns the number of skipped characters.
|
||||||
static AK_FORCE_INLINE int skipCharacters(const uint8_t *const buffer, const NodeFlags flags,
|
static int skipCharacters(const uint8_t *const buffer, const NodeFlags flags,
|
||||||
const int maxLength, int *const pos) {
|
const int maxLength, int *const pos);
|
||||||
if (hasMultipleChars(flags)) {
|
|
||||||
return ByteArrayUtils::advancePositionToBehindString(buffer, maxLength, pos);
|
|
||||||
} else {
|
|
||||||
if (maxLength > 0) {
|
|
||||||
getCodePointAndAdvancePosition(buffer, pos);
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static AK_FORCE_INLINE int readProbabilityAndAdvancePosition(const uint8_t *const buffer,
|
static int readProbabilityAndAdvancePosition(const uint8_t *const buffer, int *const pos);
|
||||||
int *const pos) {
|
|
||||||
return ByteArrayUtils::readUint8AndAdvancePosition(buffer, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int readChildrenPositionAndAdvancePosition(const uint8_t *const buffer,
|
static int readChildrenPositionAndAdvancePosition(const uint8_t *const buffer,
|
||||||
const NodeFlags flags, int *const pos);
|
const NodeFlags flags, int *const pos);
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
#include "suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.h"
|
#include "suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.h"
|
||||||
|
|
||||||
|
#include "suggest/policyimpl/dictionary/utils/byte_array_utils.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
// Flag for presence of more attributes
|
// Flag for presence of more attributes
|
||||||
|
@ -28,4 +30,22 @@ const int ShortcutListReadingUtils::SHORTCUT_LIST_SIZE_FIELD_SIZE = 2;
|
||||||
// The numeric value of the shortcut probability that means 'whitelist'.
|
// The numeric value of the shortcut probability that means 'whitelist'.
|
||||||
const int ShortcutListReadingUtils::WHITELIST_SHORTCUT_PROBABILITY = 15;
|
const int ShortcutListReadingUtils::WHITELIST_SHORTCUT_PROBABILITY = 15;
|
||||||
|
|
||||||
|
/* static */ ShortcutListReadingUtils::ShortcutFlags
|
||||||
|
ShortcutListReadingUtils::getFlagsAndForwardPointer(const uint8_t *const dictRoot,
|
||||||
|
int *const pos) {
|
||||||
|
return ByteArrayUtils::readUint8AndAdvancePosition(dictRoot, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ int ShortcutListReadingUtils::getShortcutListSizeAndForwardPointer(
|
||||||
|
const uint8_t *const dictRoot, int *const pos) {
|
||||||
|
// readUint16andAdvancePosition() returns an offset *including* the uint16 field itself.
|
||||||
|
return ByteArrayUtils::readUint16AndAdvancePosition(dictRoot, pos)
|
||||||
|
- SHORTCUT_LIST_SIZE_FIELD_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ int ShortcutListReadingUtils::readShortcutTarget(
|
||||||
|
const uint8_t *const dictRoot, const int maxLength, int *const outWord, int *const pos) {
|
||||||
|
return ByteArrayUtils::readStringAndAdvancePosition(dictRoot, maxLength, outWord, pos);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "suggest/policyimpl/dictionary/utils/byte_array_utils.h"
|
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -28,10 +27,7 @@ class ShortcutListReadingUtils {
|
||||||
public:
|
public:
|
||||||
typedef uint8_t ShortcutFlags;
|
typedef uint8_t ShortcutFlags;
|
||||||
|
|
||||||
static AK_FORCE_INLINE ShortcutFlags getFlagsAndForwardPointer(
|
static ShortcutFlags getFlagsAndForwardPointer(const uint8_t *const dictRoot, int *const pos);
|
||||||
const uint8_t *const dictRoot, int *const pos) {
|
|
||||||
return ByteArrayUtils::readUint8AndAdvancePosition(dictRoot, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
static AK_FORCE_INLINE int getProbabilityFromFlags(const ShortcutFlags flags) {
|
static AK_FORCE_INLINE int getProbabilityFromFlags(const ShortcutFlags flags) {
|
||||||
return flags & MASK_ATTRIBUTE_PROBABILITY;
|
return flags & MASK_ATTRIBUTE_PROBABILITY;
|
||||||
|
@ -43,12 +39,7 @@ class ShortcutListReadingUtils {
|
||||||
|
|
||||||
// This method returns the size of the shortcut list region excluding the shortcut list size
|
// This method returns the size of the shortcut list region excluding the shortcut list size
|
||||||
// field at the beginning.
|
// field at the beginning.
|
||||||
static AK_FORCE_INLINE int getShortcutListSizeAndForwardPointer(
|
static int getShortcutListSizeAndForwardPointer(const uint8_t *const dictRoot, int *const pos);
|
||||||
const uint8_t *const dictRoot, int *const pos) {
|
|
||||||
// readUint16andAdvancePosition() returns an offset *including* the uint16 field itself.
|
|
||||||
return ByteArrayUtils::readUint16AndAdvancePosition(dictRoot, pos)
|
|
||||||
- SHORTCUT_LIST_SIZE_FIELD_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static AK_FORCE_INLINE int getShortcutListSizeFieldSize() {
|
static AK_FORCE_INLINE int getShortcutListSizeFieldSize() {
|
||||||
return SHORTCUT_LIST_SIZE_FIELD_SIZE;
|
return SHORTCUT_LIST_SIZE_FIELD_SIZE;
|
||||||
|
@ -63,11 +54,8 @@ class ShortcutListReadingUtils {
|
||||||
return getProbabilityFromFlags(flags) == WHITELIST_SHORTCUT_PROBABILITY;
|
return getProbabilityFromFlags(flags) == WHITELIST_SHORTCUT_PROBABILITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AK_FORCE_INLINE int readShortcutTarget(
|
static int readShortcutTarget(const uint8_t *const dictRoot, const int maxLength,
|
||||||
const uint8_t *const dictRoot, const int maxLength, int *const outWord,
|
int *const outWord, int *const pos);
|
||||||
int *const pos) {
|
|
||||||
return ByteArrayUtils::readStringAndAdvancePosition(dictRoot, maxLength, outWord, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ShortcutListReadingUtils);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(ShortcutListReadingUtils);
|
||||||
|
|
Loading…
Reference in a new issue