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  *   dictionary/structure/v4/content/terminal_position_lookup_table.h
22  */
23 
24 #ifndef LATINIME_BACKWARD_V402_TERMINAL_POSITION_LOOKUP_TABLE_H
25 #define LATINIME_BACKWARD_V402_TERMINAL_POSITION_LOOKUP_TABLE_H
26 
27 #include <unordered_map>
28 
29 #include "defines.h"
30 #include "dictionary/structure/backward/v402/content/single_dict_content.h"
31 #include "dictionary/structure/backward/v402/ver4_dict_constants.h"
32 
33 namespace latinime {
34 namespace backward {
35 namespace v402 {
36 
37 class TerminalPositionLookupTable : public SingleDictContent {
38  public:
39     typedef std::unordered_map<int, int> TerminalIdMap;
40 
TerminalPositionLookupTable(const char * const dictPath,const bool isUpdatable)41     TerminalPositionLookupTable(const char *const dictPath, const bool isUpdatable)
42             : SingleDictContent(dictPath,
43                       Ver4DictConstants::TERMINAL_ADDRESS_TABLE_FILE_EXTENSION, isUpdatable),
44               mSize(getBuffer()->getTailPosition()
45                       / Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE) {}
46 
TerminalPositionLookupTable()47     TerminalPositionLookupTable() : mSize(0) {}
48 
49     int getTerminalPtNodePosition(const int terminalId) const;
50 
51     bool setTerminalPtNodePosition(const int terminalId, const int terminalPtNodePos);
52 
getNextTerminalId()53     int getNextTerminalId() const {
54         return mSize;
55     }
56 
57     bool flushToFile(const char *const dictPath) const;
58 
59     bool runGCTerminalIds(TerminalIdMap *const terminalIdMap);
60 
61  private:
62     DISALLOW_COPY_AND_ASSIGN(TerminalPositionLookupTable);
63 
getEntryPos(const int terminalId)64     int getEntryPos(const int terminalId) const {
65         return terminalId * Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE;
66     }
67 
68     int mSize;
69 };
70 } // namespace v402
71 } // namespace backward
72 } // namespace latinime
73 #endif // LATINIME_BACKWARD_V402_TERMINAL_POSITION_LOOKUP_TABLE_H
74