am af9d92f5: Rename BinaryDictionaryBigramsReadingUtils to BinaryDictionaryTerminalAttributesReadingUtils and remanme the class methods
* commit 'af9d92f590a51d3e5f493c75c2bbee9d9ce1cbfc': Rename BinaryDictionaryBigramsReadingUtils to BinaryDictionaryTerminalAttributesReadingUtils and remanme the class methodsmain
commit
796c91d1d5
|
@ -53,10 +53,10 @@ LATIN_IME_CORE_SRC_FILES := \
|
|||
dic_nodes_cache.cpp) \
|
||||
$(addprefix suggest/core/dictionary/, \
|
||||
bigram_dictionary.cpp \
|
||||
binary_dictionary_bigrams_reading_utils.cpp \
|
||||
binary_dictionary_format_utils.cpp \
|
||||
binary_dictionary_header.cpp \
|
||||
binary_dictionary_header_reading_utils.cpp \
|
||||
binary_dictionary_terminal_attributes_reading_utils.cpp \
|
||||
bloom_filter.cpp \
|
||||
byte_array_utils.cpp \
|
||||
dictionary.cpp \
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
#define LATINIME_BINARY_DICTIONARY_BIGRAMS_ITERATOR_H
|
||||
|
||||
#include "defines.h"
|
||||
#include "suggest/core/dictionary/binary_dictionary_bigrams_reading_utils.h"
|
||||
#include "suggest/core/dictionary/binary_dictionary_info.h"
|
||||
#include "suggest/core/dictionary/binary_dictionary_terminal_attributes_reading_utils.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
|
@ -35,15 +35,17 @@ class BinaryDictionaryBigramsIterator {
|
|||
}
|
||||
|
||||
AK_FORCE_INLINE void next() {
|
||||
mBigramFlags = BinaryDictionaryBigramsReadingUtils::getFlagsAndForwardPointer(
|
||||
mBigramFlags = BinaryDictionaryTerminalAttributesReadingUtils::getFlagsAndForwardPointer(
|
||||
mBinaryDictionaryInfo, &mPos);
|
||||
mBigramPos = BinaryDictionaryBigramsReadingUtils::getBigramAddressAndForwardPointer(
|
||||
mBinaryDictionaryInfo, mBigramFlags, &mPos);
|
||||
mHasNext = BinaryDictionaryBigramsReadingUtils::hasNext(mBigramFlags);
|
||||
mBigramPos =
|
||||
BinaryDictionaryTerminalAttributesReadingUtils::getBigramAddressAndForwardPointer(
|
||||
mBinaryDictionaryInfo, mBigramFlags, &mPos);
|
||||
mHasNext = BinaryDictionaryTerminalAttributesReadingUtils::hasNext(mBigramFlags);
|
||||
}
|
||||
|
||||
AK_FORCE_INLINE int getProbability() const {
|
||||
return BinaryDictionaryBigramsReadingUtils::getBigramProbability(mBigramFlags);
|
||||
return BinaryDictionaryTerminalAttributesReadingUtils::getProbabilityFromFlags(
|
||||
mBigramFlags);
|
||||
}
|
||||
|
||||
AK_FORCE_INLINE int getBigramPos() const {
|
||||
|
@ -59,7 +61,7 @@ class BinaryDictionaryBigramsIterator {
|
|||
|
||||
const BinaryDictionaryInfo *const mBinaryDictionaryInfo;
|
||||
int mPos;
|
||||
BinaryDictionaryBigramsReadingUtils::BigramFlags mBigramFlags;
|
||||
BinaryDictionaryTerminalAttributesReadingUtils::BigramFlags mBigramFlags;
|
||||
int mBigramPos;
|
||||
bool mHasNext;
|
||||
};
|
||||
|
|
|
@ -14,33 +14,28 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "suggest/core/dictionary/binary_dictionary_bigrams_reading_utils.h"
|
||||
#include "suggest/core/dictionary/binary_dictionary_terminal_attributes_reading_utils.h"
|
||||
|
||||
#include "suggest/core/dictionary/binary_dictionary_info.h"
|
||||
#include "suggest/core/dictionary/byte_array_utils.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
const BinaryDictionaryBigramsReadingUtils::BigramFlags
|
||||
BinaryDictionaryBigramsReadingUtils::MASK_ATTRIBUTE_ADDRESS_TYPE = 0x30;
|
||||
const BinaryDictionaryBigramsReadingUtils::BigramFlags
|
||||
BinaryDictionaryBigramsReadingUtils::FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE = 0x10;
|
||||
const BinaryDictionaryBigramsReadingUtils::BigramFlags
|
||||
BinaryDictionaryBigramsReadingUtils::FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES = 0x20;
|
||||
const BinaryDictionaryBigramsReadingUtils::BigramFlags
|
||||
BinaryDictionaryBigramsReadingUtils::FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES = 0x30;
|
||||
const BinaryDictionaryBigramsReadingUtils::BigramFlags
|
||||
BinaryDictionaryBigramsReadingUtils::FLAG_ATTRIBUTE_OFFSET_NEGATIVE = 0x40;
|
||||
// Flag for presence of more attributes
|
||||
const BinaryDictionaryBigramsReadingUtils::BigramFlags
|
||||
BinaryDictionaryBigramsReadingUtils::FLAG_ATTRIBUTE_HAS_NEXT = 0x80;
|
||||
// Mask for attribute probability, stored on 4 bits inside the flags byte.
|
||||
const BinaryDictionaryBigramsReadingUtils::BigramFlags
|
||||
BinaryDictionaryBigramsReadingUtils::MASK_ATTRIBUTE_PROBABILITY = 0x0F;
|
||||
const int BinaryDictionaryBigramsReadingUtils::ATTRIBUTE_ADDRESS_SHIFT = 4;
|
||||
typedef BinaryDictionaryTerminalAttributesReadingUtils TaUtils;
|
||||
|
||||
/* static */ int BinaryDictionaryBigramsReadingUtils::getBigramAddressAndForwardPointer(
|
||||
const BinaryDictionaryInfo *const binaryDictionaryInfo, const BigramFlags flags,
|
||||
const TaUtils::TerminalAttributeFlags TaUtils::MASK_ATTRIBUTE_ADDRESS_TYPE = 0x30;
|
||||
const TaUtils::TerminalAttributeFlags TaUtils::FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE = 0x10;
|
||||
const TaUtils::TerminalAttributeFlags TaUtils::FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES = 0x20;
|
||||
const TaUtils::TerminalAttributeFlags TaUtils::FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES = 0x30;
|
||||
const TaUtils::TerminalAttributeFlags TaUtils::FLAG_ATTRIBUTE_OFFSET_NEGATIVE = 0x40;
|
||||
// Flag for presence of more attributes
|
||||
const TaUtils::TerminalAttributeFlags TaUtils::FLAG_ATTRIBUTE_HAS_NEXT = 0x80;
|
||||
// Mask for attribute probability, stored on 4 bits inside the flags byte.
|
||||
const TaUtils::TerminalAttributeFlags TaUtils::MASK_ATTRIBUTE_PROBABILITY = 0x0F;
|
||||
const int TaUtils::ATTRIBUTE_ADDRESS_SHIFT = 4;
|
||||
|
||||
/* static */ int TaUtils::getBigramAddressAndForwardPointer(
|
||||
const BinaryDictionaryInfo *const binaryDictionaryInfo, const TerminalAttributeFlags flags,
|
||||
int *const pos) {
|
||||
int offset = 0;
|
||||
const int origin = *pos;
|
|
@ -14,8 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LATINIME_BINARY_DICTIONARY_BIGRAM_READING_UTILS_H
|
||||
#define LATINIME_BINARY_DICTIONARY_BIGRAM_READING_UTILS_H
|
||||
#ifndef LATINIME_BINARY_DICTIONARY_TERMINAL_ATTRIBUTES_READING_UTILS_H
|
||||
#define LATINIME_BINARY_DICTIONARY_TERMINAL_ATTRIBUTES_READING_UTILS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -25,10 +25,26 @@
|
|||
|
||||
namespace latinime {
|
||||
|
||||
class BinaryDictionaryBigramsReadingUtils {
|
||||
class BinaryDictionaryTerminalAttributesReadingUtils {
|
||||
public:
|
||||
typedef uint8_t BigramFlags;
|
||||
typedef uint8_t TerminalAttributeFlags;
|
||||
typedef TerminalAttributeFlags BigramFlags;
|
||||
|
||||
static AK_FORCE_INLINE TerminalAttributeFlags getFlagsAndForwardPointer(
|
||||
const BinaryDictionaryInfo *const binaryDictionaryInfo, int *const pos) {
|
||||
return ByteArrayUtils::readUint8andAdvancePosition(
|
||||
binaryDictionaryInfo->getDictRoot(), pos);
|
||||
}
|
||||
|
||||
static AK_FORCE_INLINE int getProbabilityFromFlags(const TerminalAttributeFlags flags) {
|
||||
return flags & MASK_ATTRIBUTE_PROBABILITY;
|
||||
}
|
||||
|
||||
static AK_FORCE_INLINE bool hasNext(const TerminalAttributeFlags flags) {
|
||||
return (flags & FLAG_ATTRIBUTE_HAS_NEXT) != 0;
|
||||
}
|
||||
|
||||
// Bigrams reading methods
|
||||
static AK_FORCE_INLINE void skipExistingBigrams(
|
||||
const BinaryDictionaryInfo *const binaryDictionaryInfo, int *const pos) {
|
||||
BigramFlags flags = getFlagsAndForwardPointer(binaryDictionaryInfo, pos);
|
||||
|
@ -39,41 +55,27 @@ class BinaryDictionaryBigramsReadingUtils {
|
|||
*pos += attributeAddressSize(flags);
|
||||
}
|
||||
|
||||
static AK_FORCE_INLINE BigramFlags getFlagsAndForwardPointer(
|
||||
const BinaryDictionaryInfo *const binaryDictionaryInfo, int *const pos) {
|
||||
return ByteArrayUtils::readUint8andAdvancePosition(
|
||||
binaryDictionaryInfo->getDictRoot(), pos);
|
||||
}
|
||||
static int getBigramAddressAndForwardPointer(
|
||||
const BinaryDictionaryInfo *const binaryDictionaryInfo, const BigramFlags flags,
|
||||
int *const pos);
|
||||
|
||||
static AK_FORCE_INLINE int getBigramProbability(const BigramFlags flags) {
|
||||
return flags & MASK_ATTRIBUTE_PROBABILITY;
|
||||
}
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryDictionaryTerminalAttributesReadingUtils);
|
||||
|
||||
static AK_FORCE_INLINE bool isOffsetNegative(const BigramFlags flags) {
|
||||
static const TerminalAttributeFlags MASK_ATTRIBUTE_ADDRESS_TYPE;
|
||||
static const TerminalAttributeFlags FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE;
|
||||
static const TerminalAttributeFlags FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES;
|
||||
static const TerminalAttributeFlags FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES;
|
||||
static const TerminalAttributeFlags FLAG_ATTRIBUTE_OFFSET_NEGATIVE;
|
||||
static const TerminalAttributeFlags FLAG_ATTRIBUTE_HAS_NEXT;
|
||||
static const TerminalAttributeFlags MASK_ATTRIBUTE_PROBABILITY;
|
||||
static const int ATTRIBUTE_ADDRESS_SHIFT;
|
||||
|
||||
static AK_FORCE_INLINE bool isOffsetNegative(const TerminalAttributeFlags flags) {
|
||||
return (flags & FLAG_ATTRIBUTE_OFFSET_NEGATIVE) != 0;
|
||||
}
|
||||
|
||||
static AK_FORCE_INLINE bool hasNext(const BigramFlags flags) {
|
||||
return (flags & FLAG_ATTRIBUTE_HAS_NEXT) != 0;
|
||||
}
|
||||
|
||||
static int getBigramAddressAndForwardPointer(
|
||||
const BinaryDictionaryInfo *const binaryDictionaryInfo,
|
||||
const BigramFlags flags, int *const pos);
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryDictionaryBigramsReadingUtils);
|
||||
|
||||
static const BigramFlags MASK_ATTRIBUTE_ADDRESS_TYPE;
|
||||
static const BigramFlags FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE;
|
||||
static const BigramFlags FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES;
|
||||
static const BigramFlags FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES;
|
||||
static const BigramFlags FLAG_ATTRIBUTE_OFFSET_NEGATIVE;
|
||||
static const BigramFlags FLAG_ATTRIBUTE_HAS_NEXT;
|
||||
static const BigramFlags MASK_ATTRIBUTE_PROBABILITY;
|
||||
static const int ATTRIBUTE_ADDRESS_SHIFT;
|
||||
|
||||
static AK_FORCE_INLINE int attributeAddressSize(const BigramFlags flags) {
|
||||
static AK_FORCE_INLINE int attributeAddressSize(const TerminalAttributeFlags flags) {
|
||||
return (flags & MASK_ATTRIBUTE_ADDRESS_TYPE) >> ATTRIBUTE_ADDRESS_SHIFT;
|
||||
/* Note: this is a value-dependant optimization of what may probably be
|
||||
more readably written this way:
|
||||
|
@ -87,4 +89,4 @@ class BinaryDictionaryBigramsReadingUtils {
|
|||
}
|
||||
};
|
||||
}
|
||||
#endif /* LATINIME_BINARY_DICTIONARY_BIGRAM_READING_UTILS_H */
|
||||
#endif /* LATINIME_BINARY_DICTIONARY_TERMINAL_ATTRIBUTES_READING_UTILS_H */
|
Loading…
Reference in New Issue