| OLD | NEW |
| 1 // Copyright 2008 Google Inc. All Rights Reserved. | 1 // Copyright 2008 Google Inc. All Rights Reserved. |
| 2 | 2 |
| 3 #include "chrome/third_party/hunspell/google/bdict_writer.h" | 3 #include "chrome/third_party/hunspell/google/bdict_writer.h" |
| 4 | 4 |
| 5 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "chrome/third_party/hunspell/google/bdict.h" | 7 #include "chrome/third_party/hunspell/google/bdict.h" |
| 8 | 8 |
| 9 namespace hunspell { | 9 namespace hunspell { |
| 10 | 10 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 154 } |
| 155 | 155 |
| 156 // Recursively fills in the storage strategy for this node and each of its | 156 // Recursively fills in the storage strategy for this node and each of its |
| 157 // children. This must be done before actually serializing because the storage | 157 // children. This must be done before actually serializing because the storage |
| 158 // mode will depend on the size of the children. | 158 // mode will depend on the size of the children. |
| 159 size_t ComputeTrieStorage(DicNode* node) { | 159 size_t ComputeTrieStorage(DicNode* node) { |
| 160 if (node->is_leaf()) { | 160 if (node->is_leaf()) { |
| 161 // The additional affix list holds affixes when there is more than one. Each | 161 // The additional affix list holds affixes when there is more than one. Each |
| 162 // entry is two bytes, plus an additional FFFF terminator. | 162 // entry is two bytes, plus an additional FFFF terminator. |
| 163 size_t supplimentary_size = 0; | 163 size_t supplimentary_size = 0; |
| 164 if (node->affix_indices.size() > 1 || | 164 if (node->affix_indices[0] > BDict::LEAF_NODE_MAX_FIRST_AFFIX_ID) { |
| 165 node->affix_indices[0] > BDict::LEAF_NODE_MAX_FIRST_AFFIX_ID) | 165 // We cannot store the first affix ID of the affix list into a leaf node. |
| 166 // In this case, we have to store all the affix IDs and a terminator |
| 167 // into a supplimentary list. |
| 168 supplimentary_size = node->affix_indices.size() * 2 + 2; |
| 169 } else if (node->affix_indices.size() > 1) { |
| 170 // We can store the first affix ID of the affix list into a leaf node. |
| 171 // In this case, we need to store the remaining affix IDs and a |
| 172 // terminator into a supplimentary list. |
| 166 supplimentary_size = node->affix_indices.size() * 2; | 173 supplimentary_size = node->affix_indices.size() * 2; |
| 174 } |
| 167 | 175 |
| 168 if (node->leaf_addition.empty()) { | 176 if (node->leaf_addition.empty()) { |
| 169 node->storage = DicNode::LEAF; | 177 node->storage = DicNode::LEAF; |
| 170 return 2 + supplimentary_size; | 178 return 2 + supplimentary_size; |
| 171 } | 179 } |
| 172 node->storage = DicNode::LEAFMORE; | 180 node->storage = DicNode::LEAFMORE; |
| 173 // Signature & affix (2) + null for leaf_addition (1) = 3 | 181 // Signature & affix (2) + null for leaf_addition (1) = 3 |
| 174 return 3 + node->leaf_addition.size() + supplimentary_size; | 182 return 3 + node->leaf_addition.size() + supplimentary_size; |
| 175 } | 183 } |
| 176 | 184 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 // Add the header now that we know the offsets. | 495 // Add the header now that we know the offsets. |
| 488 hunspell::BDict::AffHeader* header = | 496 hunspell::BDict::AffHeader* header = |
| 489 reinterpret_cast<hunspell::BDict::AffHeader*>(&(*output)[header_offset]); | 497 reinterpret_cast<hunspell::BDict::AffHeader*>(&(*output)[header_offset]); |
| 490 header->affix_group_offset = static_cast<uint32>(affix_group_offset); | 498 header->affix_group_offset = static_cast<uint32>(affix_group_offset); |
| 491 header->affix_rule_offset = static_cast<uint32>(affix_rule_offset); | 499 header->affix_rule_offset = static_cast<uint32>(affix_rule_offset); |
| 492 header->rep_offset = static_cast<uint32>(rep_offset); | 500 header->rep_offset = static_cast<uint32>(rep_offset); |
| 493 header->other_offset = static_cast<uint32>(other_offset); | 501 header->other_offset = static_cast<uint32>(other_offset); |
| 494 } | 502 } |
| 495 | 503 |
| 496 } // namespace hunspell | 504 } // namespace hunspell |
| OLD | NEW |