1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef LATINIME_SHORTCUT_LIST_READING_UTILS_H 18 #define LATINIME_SHORTCUT_LIST_READING_UTILS_H 19 20 #include <cstdint> 21 22 #include "defines.h" 23 24 namespace latinime { 25 26 class ShortcutListReadingUtils { 27 public: 28 typedef uint8_t ShortcutFlags; 29 30 static ShortcutFlags getFlagsAndForwardPointer(const uint8_t *const dictRoot, int *const pos); 31 32 static AK_FORCE_INLINE int getProbabilityFromFlags(const ShortcutFlags flags) { 33 return flags & MASK_ATTRIBUTE_PROBABILITY; 34 } 35 36 static AK_FORCE_INLINE bool hasNext(const ShortcutFlags flags) { 37 return (flags & FLAG_ATTRIBUTE_HAS_NEXT) != 0; 38 } 39 40 // This method returns the size of the shortcut list region excluding the shortcut list size 41 // field at the beginning. 42 static int getShortcutListSizeAndForwardPointer(const uint8_t *const dictRoot, int *const pos); 43 44 static AK_FORCE_INLINE int getShortcutListSizeFieldSize() { 45 return SHORTCUT_LIST_SIZE_FIELD_SIZE; 46 } 47 48 static AK_FORCE_INLINE void skipShortcuts(const uint8_t *const dictRoot, int *const pos) { 49 const int shortcutListSize = getShortcutListSizeAndForwardPointer(dictRoot, pos); 50 *pos += shortcutListSize; 51 } 52 53 static AK_FORCE_INLINE bool isWhitelist(const ShortcutFlags flags) { 54 return getProbabilityFromFlags(flags) == WHITELIST_SHORTCUT_PROBABILITY; 55 } 56 57 static int readShortcutTarget(const uint8_t *const dictRoot, const int maxLength, 58 int *const outWord, int *const pos); 59 60 private: 61 DISALLOW_IMPLICIT_CONSTRUCTORS(ShortcutListReadingUtils); 62 63 static const ShortcutFlags FLAG_ATTRIBUTE_HAS_NEXT; 64 static const ShortcutFlags MASK_ATTRIBUTE_PROBABILITY; 65 static const int SHORTCUT_LIST_SIZE_FIELD_SIZE; 66 static const int WHITELIST_SHORTCUT_PROBABILITY; 67 }; 68 } // namespace latinime 69 #endif // LATINIME_SHORTCUT_LIST_READING_UTILS_H 70