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 /* 18 * !!!!! DO NOT EDIT THIS FILE !!!!! 19 * 20 * This file was generated from 21 * suggest/policyimpl/dictionary/structure/v4/content/shortcut_dict_content.h 22 */ 23 24 #ifndef LATINIME_BACKWARD_V402_SHORTCUT_DICT_CONTENT_H 25 #define LATINIME_BACKWARD_V402_SHORTCUT_DICT_CONTENT_H 26 27 #include "defines.h" 28 #include "suggest/policyimpl/dictionary/structure/backward/v402/content/sparse_table_dict_content.h" 29 #include "suggest/policyimpl/dictionary/structure/backward/v402/content/terminal_position_lookup_table.h" 30 #include "suggest/policyimpl/dictionary/structure/backward/v402/ver4_dict_constants.h" 31 32 namespace latinime { 33 namespace backward { 34 namespace v402 { 35 36 class ShortcutDictContent : public SparseTableDictContent { 37 public: 38 ShortcutDictContent(const char *const dictPath, const bool isUpdatable) 39 : SparseTableDictContent(dictPath, 40 Ver4DictConstants::SHORTCUT_LOOKUP_TABLE_FILE_EXTENSION, 41 Ver4DictConstants::SHORTCUT_CONTENT_TABLE_FILE_EXTENSION, 42 Ver4DictConstants::SHORTCUT_FILE_EXTENSION, isUpdatable, 43 Ver4DictConstants::SHORTCUT_ADDRESS_TABLE_BLOCK_SIZE, 44 Ver4DictConstants::SHORTCUT_ADDRESS_TABLE_DATA_SIZE) {} 45 46 ShortcutDictContent() 47 : SparseTableDictContent(Ver4DictConstants::SHORTCUT_ADDRESS_TABLE_BLOCK_SIZE, 48 Ver4DictConstants::SHORTCUT_ADDRESS_TABLE_DATA_SIZE) {} 49 50 void getShortcutEntry(const int maxCodePointCount, int *const outCodePoint, 51 int *const outCodePointCount, int *const outProbability, bool *const outhasNext, 52 const int shortcutEntryPos) { 53 int readingPos = shortcutEntryPos; 54 return getShortcutEntryAndAdvancePosition(maxCodePointCount, outCodePoint, 55 outCodePointCount, outProbability, outhasNext, &readingPos); 56 } 57 58 void getShortcutEntryAndAdvancePosition(const int maxCodePointCount, 59 int *const outCodePoint, int *const outCodePointCount, int *const outProbability, 60 bool *const outhasNext, int *const shortcutEntryPos) const; 61 62 // Returns head position of shortcut list for a PtNode specified by terminalId. 63 int getShortcutListHeadPos(const int terminalId) const; 64 65 bool flushToFile(const char *const dictPath) const; 66 67 bool runGC(const TerminalPositionLookupTable::TerminalIdMap *const terminalIdMap, 68 const ShortcutDictContent *const originalShortcutDictContent); 69 70 bool createNewShortcutList(const int terminalId); 71 72 bool copyShortcutList(const int shortcutListPos, const int toPos); 73 74 bool setProbability(const int probability, const int shortcutEntryPos); 75 76 bool writeShortcutEntry(const int *const codePoint, const int codePointCount, 77 const int probability, const bool hasNext, const int shortcutEntryPos) { 78 int writingPos = shortcutEntryPos; 79 return writeShortcutEntryAndAdvancePosition(codePoint, codePointCount, probability, 80 hasNext, &writingPos); 81 } 82 83 bool writeShortcutEntryAndAdvancePosition(const int *const codePoint, 84 const int codePointCount, const int probability, const bool hasNext, 85 int *const shortcutEntryPos); 86 87 int findShortcutEntryAndGetPos(const int shortcutListPos, 88 const int *const targetCodePointsToFind, const int codePointCount) const; 89 90 private: 91 DISALLOW_COPY_AND_ASSIGN(ShortcutDictContent); 92 93 bool copyShortcutListFromDictContent(const int shortcutListPos, 94 const ShortcutDictContent *const sourceShortcutDictContent, const int toPos); 95 96 int createAndGetShortcutFlags(const int probability, const bool hasNext) const; 97 }; 98 } // namespace v402 99 } // namespace backward 100 } // namespace latinime 101 #endif /* LATINIME_BACKWARD_V402_SHORTCUT_DICT_CONTENT_H */ 102