terminal_position_lookup_table.h revision 2ac934296c0571ea252f3fb5a23fba29eb89c666
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_TERMINAL_POSITION_LOOKUP_TABLE_H 18#define LATINIME_TERMINAL_POSITION_LOOKUP_TABLE_H 19 20#include <cstdint> 21#include <cstdio> 22#include <unordered_map> 23 24#include "defines.h" 25#include "suggest/policyimpl/dictionary/structure/v4/content/single_dict_content.h" 26#include "suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.h" 27 28namespace latinime { 29 30class TerminalPositionLookupTable : public SingleDictContent { 31 public: 32 typedef std::unordered_map<int, int> TerminalIdMap; 33 34 TerminalPositionLookupTable(uint8_t *const buffer, const int bufferSize, 35 const bool isUpdatable) 36 : SingleDictContent(buffer, bufferSize, isUpdatable), 37 mSize(getBuffer()->getTailPosition() 38 / Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE) {} 39 40 TerminalPositionLookupTable() : mSize(0) {} 41 42 int getTerminalPtNodePosition(const int terminalId) const; 43 44 bool setTerminalPtNodePosition(const int terminalId, const int terminalPtNodePos); 45 46 int getNextTerminalId() const { 47 return mSize; 48 } 49 50 bool flushToFile(FILE *const file) const; 51 52 bool runGCTerminalIds(TerminalIdMap *const terminalIdMap); 53 54 private: 55 DISALLOW_COPY_AND_ASSIGN(TerminalPositionLookupTable); 56 57 int getEntryPos(const int terminalId) const { 58 return terminalId * Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE; 59 } 60 61 int mSize; 62}; 63} // namespace latinime 64#endif // LATINIME_TERMINAL_POSITION_LOOKUP_TABLE_H 65