mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
am 874ef755
: Merge "Move methods using ByteArrayUtils from .h to .cpp."
* commit '874ef755e3a12acf066969367314fa9f6598c443': Move methods using ByteArrayUtils from .h to .cpp.
This commit is contained in:
commit
51c78871a2
@ -38,6 +38,22 @@ const BigramListReadWriteUtils::BigramFlags
|
||||
BigramListReadWriteUtils::MASK_ATTRIBUTE_PROBABILITY = 0x0F;
|
||||
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(
|
||||
const uint8_t *const bigramsBuf, const BigramFlags flags, int *const pos) {
|
||||
int offset = 0;
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "suggest/policyimpl/dictionary/utils/byte_array_utils.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
@ -29,10 +28,7 @@ class BigramListReadWriteUtils {
|
||||
public:
|
||||
typedef uint8_t BigramFlags;
|
||||
|
||||
static AK_FORCE_INLINE BigramFlags getFlagsAndForwardPointer(
|
||||
const uint8_t *const bigramsBuf, int *const pos) {
|
||||
return ByteArrayUtils::readUint8AndAdvancePosition(bigramsBuf, pos);
|
||||
}
|
||||
static BigramFlags getFlagsAndForwardPointer(const uint8_t *const bigramsBuf, int *const pos);
|
||||
|
||||
static AK_FORCE_INLINE int getProbabilityFromFlags(const BigramFlags flags) {
|
||||
return flags & MASK_ATTRIBUTE_PROBABILITY;
|
||||
@ -43,15 +39,7 @@ public:
|
||||
}
|
||||
|
||||
// Bigrams reading methods
|
||||
static AK_FORCE_INLINE void 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 void skipExistingBigrams(const uint8_t *const bigramsBuf, int *const pos);
|
||||
|
||||
static int getBigramAddressAndForwardPointer(const uint8_t *const bigramsBuf,
|
||||
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_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(
|
||||
const uint8_t *const buffer, int *const pos) {
|
||||
const int base = *pos;
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "suggest/policyimpl/dictionary/utils/byte_array_utils.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
@ -28,19 +27,13 @@ class DynamicPatriciaTrieReadingUtils {
|
||||
public:
|
||||
typedef uint8_t NodeFlags;
|
||||
|
||||
static AK_FORCE_INLINE int getForwardLinkPosition(const uint8_t *const buffer, const int pos) {
|
||||
int linkAddressPos = pos;
|
||||
return ByteArrayUtils::readSint24AndAdvancePosition(buffer, &linkAddressPos);
|
||||
}
|
||||
static int getForwardLinkPosition(const uint8_t *const buffer, const int pos);
|
||||
|
||||
static AK_FORCE_INLINE bool isValidForwardLinkPosition(const int forwardLinkAddress) {
|
||||
return forwardLinkAddress != 0;
|
||||
}
|
||||
|
||||
static AK_FORCE_INLINE int getParentPosAndAdvancePosition(const uint8_t *const buffer,
|
||||
int *const pos) {
|
||||
return ByteArrayUtils::readSint24AndAdvancePosition(buffer, pos);
|
||||
}
|
||||
static int getParentPosAndAdvancePosition(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
|
||||
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(
|
||||
const uint8_t *const buffer, const NodeFlags flags, int *const pos) {
|
||||
const int base = *pos;
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "suggest/policyimpl/dictionary/utils/byte_array_utils.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
@ -28,62 +27,21 @@ class PatriciaTrieReadingUtils {
|
||||
public:
|
||||
typedef uint8_t NodeFlags;
|
||||
|
||||
static AK_FORCE_INLINE int 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 int getPtNodeArraySizeAndAdvancePosition(const uint8_t *const buffer, int *const pos);
|
||||
|
||||
static AK_FORCE_INLINE NodeFlags getFlagsAndAdvancePosition(const uint8_t *const buffer,
|
||||
int *const pos) {
|
||||
return ByteArrayUtils::readUint8AndAdvancePosition(buffer, pos);
|
||||
}
|
||||
static NodeFlags getFlagsAndAdvancePosition(const uint8_t *const buffer, int *const pos);
|
||||
|
||||
static AK_FORCE_INLINE int getCodePointAndAdvancePosition(const uint8_t *const buffer,
|
||||
int *const pos) {
|
||||
return ByteArrayUtils::readCodePointAndAdvancePosition(buffer, pos);
|
||||
}
|
||||
static int getCodePointAndAdvancePosition(const uint8_t *const buffer, int *const pos);
|
||||
|
||||
// Returns the number of read characters.
|
||||
static AK_FORCE_INLINE int 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;
|
||||
}
|
||||
static int getCharsAndAdvancePosition(const uint8_t *const buffer, const NodeFlags flags,
|
||||
const int maxLength, int *const outBuffer, int *const pos);
|
||||
|
||||
// Returns the number of skipped characters.
|
||||
static AK_FORCE_INLINE int 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 skipCharacters(const uint8_t *const buffer, const NodeFlags flags,
|
||||
const int maxLength, int *const pos);
|
||||
|
||||
static AK_FORCE_INLINE int readProbabilityAndAdvancePosition(const uint8_t *const buffer,
|
||||
int *const pos) {
|
||||
return ByteArrayUtils::readUint8AndAdvancePosition(buffer, pos);
|
||||
}
|
||||
static int readProbabilityAndAdvancePosition(const uint8_t *const buffer, int *const pos);
|
||||
|
||||
static int readChildrenPositionAndAdvancePosition(const uint8_t *const buffer,
|
||||
const NodeFlags flags, int *const pos);
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
#include "suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.h"
|
||||
|
||||
#include "suggest/policyimpl/dictionary/utils/byte_array_utils.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
// 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'.
|
||||
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
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "suggest/policyimpl/dictionary/utils/byte_array_utils.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
@ -28,10 +27,7 @@ class ShortcutListReadingUtils {
|
||||
public:
|
||||
typedef uint8_t ShortcutFlags;
|
||||
|
||||
static AK_FORCE_INLINE ShortcutFlags getFlagsAndForwardPointer(
|
||||
const uint8_t *const dictRoot, int *const pos) {
|
||||
return ByteArrayUtils::readUint8AndAdvancePosition(dictRoot, pos);
|
||||
}
|
||||
static ShortcutFlags getFlagsAndForwardPointer(const uint8_t *const dictRoot, int *const pos);
|
||||
|
||||
static AK_FORCE_INLINE int getProbabilityFromFlags(const ShortcutFlags flags) {
|
||||
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
|
||||
// field at the beginning.
|
||||
static AK_FORCE_INLINE int 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 getShortcutListSizeAndForwardPointer(const uint8_t *const dictRoot, int *const pos);
|
||||
|
||||
static AK_FORCE_INLINE int getShortcutListSizeFieldSize() {
|
||||
return SHORTCUT_LIST_SIZE_FIELD_SIZE;
|
||||
@ -63,11 +54,8 @@ class ShortcutListReadingUtils {
|
||||
return getProbabilityFromFlags(flags) == WHITELIST_SHORTCUT_PROBABILITY;
|
||||
}
|
||||
|
||||
static AK_FORCE_INLINE int readShortcutTarget(
|
||||
const uint8_t *const dictRoot, const int maxLength, int *const outWord,
|
||||
int *const pos) {
|
||||
return ByteArrayUtils::readStringAndAdvancePosition(dictRoot, maxLength, outWord, pos);
|
||||
}
|
||||
static int readShortcutTarget(const uint8_t *const dictRoot, const int maxLength,
|
||||
int *const outWord, int *const pos);
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ShortcutListReadingUtils);
|
||||
|
Loading…
Reference in New Issue
Block a user