From af9d92f590a51d3e5f493c75c2bbee9d9ce1cbfc Mon Sep 17 00:00:00 2001 From: Keisuke Kuroynagi Date: Mon, 24 Jun 2013 09:42:37 +0900 Subject: [PATCH] Rename BinaryDictionaryBigramsReadingUtils to BinaryDictionaryTerminalAttributesReadingUtils and remanme the class methods Bug: 6669677 Change-Id: I960dcf51a950ead2c3d7b9dedcde0a450569cbe9 --- native/jni/Android.mk | 2 +- .../binary_dictionary_bigrams_iterator.h | 16 +++-- ...ary_terminal_attributes_reading_utils.cpp} | 35 ++++----- ...onary_terminal_attributes_reading_utils.h} | 72 ++++++++++--------- 4 files changed, 62 insertions(+), 63 deletions(-) rename native/jni/src/suggest/core/dictionary/{binary_dictionary_bigrams_reading_utils.cpp => binary_dictionary_terminal_attributes_reading_utils.cpp} (59%) rename native/jni/src/suggest/core/dictionary/{binary_dictionary_bigrams_reading_utils.h => binary_dictionary_terminal_attributes_reading_utils.h} (61%) diff --git a/native/jni/Android.mk b/native/jni/Android.mk index fb60139d3..d5df6b62e 100644 --- a/native/jni/Android.mk +++ b/native/jni/Android.mk @@ -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 \ diff --git a/native/jni/src/suggest/core/dictionary/binary_dictionary_bigrams_iterator.h b/native/jni/src/suggest/core/dictionary/binary_dictionary_bigrams_iterator.h index 0856840b2..f2b48e960 100644 --- a/native/jni/src/suggest/core/dictionary/binary_dictionary_bigrams_iterator.h +++ b/native/jni/src/suggest/core/dictionary/binary_dictionary_bigrams_iterator.h @@ -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; }; diff --git a/native/jni/src/suggest/core/dictionary/binary_dictionary_bigrams_reading_utils.cpp b/native/jni/src/suggest/core/dictionary/binary_dictionary_terminal_attributes_reading_utils.cpp similarity index 59% rename from native/jni/src/suggest/core/dictionary/binary_dictionary_bigrams_reading_utils.cpp rename to native/jni/src/suggest/core/dictionary/binary_dictionary_terminal_attributes_reading_utils.cpp index 78a54b141..0a7509c8b 100644 --- a/native/jni/src/suggest/core/dictionary/binary_dictionary_bigrams_reading_utils.cpp +++ b/native/jni/src/suggest/core/dictionary/binary_dictionary_terminal_attributes_reading_utils.cpp @@ -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; diff --git a/native/jni/src/suggest/core/dictionary/binary_dictionary_bigrams_reading_utils.h b/native/jni/src/suggest/core/dictionary/binary_dictionary_terminal_attributes_reading_utils.h similarity index 61% rename from native/jni/src/suggest/core/dictionary/binary_dictionary_bigrams_reading_utils.h rename to native/jni/src/suggest/core/dictionary/binary_dictionary_terminal_attributes_reading_utils.h index e71f2a17a..f38fd5aaa 100644 --- a/native/jni/src/suggest/core/dictionary/binary_dictionary_bigrams_reading_utils.h +++ b/native/jni/src/suggest/core/dictionary/binary_dictionary_terminal_attributes_reading_utils.h @@ -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 @@ -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 */