Cleanup ShortcutListReadingUtils.

Bug: 6669677
Change-Id: Ifd61022665c89f492933dde9811ec644f7e1f5c4
This commit is contained in:
Keisuke Kuroyanagi 2013-08-12 17:43:47 +09:00
parent 51f0c95f21
commit f4688f8df0
3 changed files with 26 additions and 63 deletions

View file

@ -34,33 +34,29 @@ class ShortcutListPolicy : public DictionaryShortcutsStructurePolicy {
int getStartPos(const int pos) const {
int listPos = pos;
BinaryDictionaryTerminalAttributesReadingUtils::getShortcutListSizeAndForwardPointer(
mShortcutsBuf, &listPos);
ShortcutListReadingUtils::getShortcutListSizeAndForwardPointer(mShortcutsBuf, &listPos);
return listPos;
}
void getNextShortcut(const int maxCodePointCount, int *const outCodePoint,
int *const outCodePointCount, bool *const outIsWhitelist, bool *const outHasNext,
int *const pos) const {
const BinaryDictionaryTerminalAttributesReadingUtils::ShortcutFlags flags =
BinaryDictionaryTerminalAttributesReadingUtils::getFlagsAndForwardPointer(
mShortcutsBuf, pos);
const ShortcutListReadingUtils::ShortcutFlags flags =
ShortcutListReadingUtils::getFlagsAndForwardPointer(mShortcutsBuf, pos);
if (outHasNext) {
*outHasNext = BinaryDictionaryTerminalAttributesReadingUtils::hasNext(flags);
*outHasNext = ShortcutListReadingUtils::hasNext(flags);
}
if (outIsWhitelist) {
*outIsWhitelist =
BinaryDictionaryTerminalAttributesReadingUtils::isWhitelist(flags);
*outIsWhitelist = ShortcutListReadingUtils::isWhitelist(flags);
}
if (outCodePoint) {
*outCodePointCount =
BinaryDictionaryTerminalAttributesReadingUtils::readShortcutTarget(
mShortcutsBuf, maxCodePointCount, outCodePoint, pos);
*outCodePointCount = ShortcutListReadingUtils::readShortcutTarget(
mShortcutsBuf, maxCodePointCount, outCodePoint, pos);
}
}
void skipAllShortcuts(int *const pos) const {
const int shortcutListSize = BinaryDictionaryTerminalAttributesReadingUtils
const int shortcutListSize = ShortcutListReadingUtils
::getShortcutListSizeAndForwardPointer(mShortcutsBuf, pos);
*pos += shortcutListSize;
}

View file

@ -16,24 +16,16 @@
#include "suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.h"
#include "suggest/core/dictionary/byte_array_utils.h"
namespace latinime {
typedef BinaryDictionaryTerminalAttributesReadingUtils TaUtils;
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;
const ShortcutListReadingUtils::ShortcutFlags
ShortcutListReadingUtils::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;
const int TaUtils::SHORTCUT_LIST_SIZE_FIELD_SIZE = 2;
const ShortcutListReadingUtils::ShortcutFlags
ShortcutListReadingUtils::MASK_ATTRIBUTE_PROBABILITY = 0x0F;
const int ShortcutListReadingUtils::SHORTCUT_LIST_SIZE_FIELD_SIZE = 2;
// The numeric value of the shortcut probability that means 'whitelist'.
const int TaUtils::WHITELIST_SHORTCUT_PROBABILITY = 15;
const int ShortcutListReadingUtils::WHITELIST_SHORTCUT_PROBABILITY = 15;
} // namespace latinime

View file

@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef LATINIME_BINARY_DICTIONARY_TERMINAL_ATTRIBUTES_READING_UTILS_H
#define LATINIME_BINARY_DICTIONARY_TERMINAL_ATTRIBUTES_READING_UTILS_H
#ifndef LATINIME_SHORTCUT_LIST_READING_UTILS_H
#define LATINIME_SHORTCUT_LIST_READING_UTILS_H
#include <stdint.h>
@ -24,25 +24,23 @@
namespace latinime {
class BinaryDictionaryTerminalAttributesReadingUtils {
class ShortcutListReadingUtils {
public:
typedef uint8_t TerminalAttributeFlags;
typedef TerminalAttributeFlags ShortcutFlags;
typedef uint8_t ShortcutFlags;
static AK_FORCE_INLINE TerminalAttributeFlags getFlagsAndForwardPointer(
static AK_FORCE_INLINE ShortcutFlags getFlagsAndForwardPointer(
const uint8_t *const dictRoot, int *const pos) {
return ByteArrayUtils::readUint8AndAdvancePosition(dictRoot, pos);
}
static AK_FORCE_INLINE int getProbabilityFromFlags(const TerminalAttributeFlags flags) {
static AK_FORCE_INLINE int getProbabilityFromFlags(const ShortcutFlags flags) {
return flags & MASK_ATTRIBUTE_PROBABILITY;
}
static AK_FORCE_INLINE bool hasNext(const TerminalAttributeFlags flags) {
static AK_FORCE_INLINE bool hasNext(const ShortcutFlags flags) {
return (flags & FLAG_ATTRIBUTE_HAS_NEXT) != 0;
}
// Shortcuts reading methods
// 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(
@ -68,35 +66,12 @@ class BinaryDictionaryTerminalAttributesReadingUtils {
}
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryDictionaryTerminalAttributesReadingUtils);
DISALLOW_IMPLICIT_CONSTRUCTORS(ShortcutListReadingUtils);
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 const ShortcutFlags FLAG_ATTRIBUTE_HAS_NEXT;
static const ShortcutFlags MASK_ATTRIBUTE_PROBABILITY;
static const int SHORTCUT_LIST_SIZE_FIELD_SIZE;
static const int WHITELIST_SHORTCUT_PROBABILITY;
static AK_FORCE_INLINE bool isOffsetNegative(const TerminalAttributeFlags flags) {
return (flags & FLAG_ATTRIBUTE_OFFSET_NEGATIVE) != 0;
}
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:
switch (flags * BinaryFormat::MASK_ATTRIBUTE_ADDRESS_TYPE) {
case FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE: return 1;
case FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES: return 2;
case FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTE: return 3;
default: return 0;
}
*/
}
};
}
#endif /* LATINIME_BINARY_DICTIONARY_TERMINAL_ATTRIBUTES_READING_UTILS_H */
} // namespace latinime
#endif // LATINIME_SHORTCUT_LIST_READING_UTILS_H