ver4_dict_constants.cpp revision a245d15da5d295af21ead9a01583c64796a31ad7
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#include "suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.h"
18
19namespace latinime {
20
21// These values MUST match the definitions in FormatSpec.java.
22const char *const Ver4DictConstants::TRIE_FILE_EXTENSION = ".trie";
23const char *const Ver4DictConstants::HEADER_FILE_EXTENSION = ".header";
24const char *const Ver4DictConstants::FREQ_FILE_EXTENSION = ".freq";
25// tat = Terminal Address Table
26const char *const Ver4DictConstants::TERMINAL_ADDRESS_TABLE_FILE_EXTENSION = ".tat";
27const char *const Ver4DictConstants::BIGRAM_FILE_EXTENSION = ".bigram_freq";
28const char *const Ver4DictConstants::BIGRAM_LOOKUP_TABLE_FILE_EXTENSION = ".bigram_lookup";
29const char *const Ver4DictConstants::BIGRAM_CONTENT_TABLE_FILE_EXTENSION = ".bigram_index_freq";
30const char *const Ver4DictConstants::SHORTCUT_FILE_EXTENSION = ".shortcut_shortcut";
31const char *const Ver4DictConstants::SHORTCUT_LOOKUP_TABLE_FILE_EXTENSION = ".shortcut_lookup";
32const char *const Ver4DictConstants::SHORTCUT_CONTENT_TABLE_FILE_EXTENSION =
33        ".shortcut_index_shortcut";
34
35// Version 4 dictionary size is implicitly limited to 8MB due to 3-byte offsets.
36const int Ver4DictConstants::MAX_DICTIONARY_SIZE = 8 * 1024 * 1024;
37// Extended region size, which is not GCed region size in dict file + additional buffer size, is
38// limited to 1MB to prevent from inefficient traversing.
39const int Ver4DictConstants::MAX_DICT_EXTENDED_REGION_SIZE = 1 * 1024 * 1024;
40
41const int Ver4DictConstants::NOT_A_TERMINAL_ID = -1;
42const int Ver4DictConstants::PROBABILITY_SIZE = 1;
43const int Ver4DictConstants::FLAGS_IN_PROBABILITY_FILE_SIZE = 1;
44const int Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE = 3;
45const int Ver4DictConstants::NOT_A_TERMINAL_ADDRESS = 0;
46const int Ver4DictConstants::TERMINAL_ID_FIELD_SIZE = 4;
47const int Ver4DictConstants::TIME_STAMP_FIELD_SIZE = 4;
48const int Ver4DictConstants::WORD_LEVEL_FIELD_SIZE = 1;
49const int Ver4DictConstants::WORD_COUNT_FIELD_SIZE = 1;
50
51const int Ver4DictConstants::BIGRAM_ADDRESS_TABLE_BLOCK_SIZE = 4;
52const int Ver4DictConstants::BIGRAM_ADDRESS_TABLE_DATA_SIZE = 4;
53const int Ver4DictConstants::SHORTCUT_ADDRESS_TABLE_BLOCK_SIZE = 16;
54const int Ver4DictConstants::SHORTCUT_ADDRESS_TABLE_DATA_SIZE = 4;
55
56const int Ver4DictConstants::BIGRAM_TARGET_TERMINAL_ID_FIELD_SIZE = 3;
57// Unsigned int max value of BIGRAM_TARGET_TERMINAL_ID_FIELD_SIZE-byte is used for representing
58// invalid terminal ID in bigram lists.
59const int Ver4DictConstants::INVALID_BIGRAM_TARGET_TERMINAL_ID =
60        (1 << (BIGRAM_TARGET_TERMINAL_ID_FIELD_SIZE * 8)) - 1;
61const int Ver4DictConstants::BIGRAM_FLAGS_FIELD_SIZE = 1;
62const int Ver4DictConstants::BIGRAM_PROBABILITY_MASK = 0x0F;
63const int Ver4DictConstants::BIGRAM_HAS_NEXT_MASK = 0x80;
64const int Ver4DictConstants::BIGRAM_LARGE_PROBABILITY_FIELD_SIZE = 1;
65
66const int Ver4DictConstants::SHORTCUT_FLAGS_FIELD_SIZE = 1;
67const int Ver4DictConstants::SHORTCUT_PROBABILITY_MASK = 0x0F;
68const int Ver4DictConstants::SHORTCUT_HAS_NEXT_MASK = 0x80;
69
70} // namespace latinime
71