Home | History | Annotate | Download | only in v2
      1 /*
      2  * Copyright (C) 2014, 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/v2/ver2_patricia_trie_node_reader.h"
     18 
     19 #include "suggest/policyimpl/dictionary/structure/pt_common/patricia_trie_reading_utils.h"
     20 
     21 namespace latinime {
     22 
     23 const PtNodeParams Ver2ParticiaTrieNodeReader::fetchPtNodeParamsInBufferFromPtNodePos(
     24         const int ptNodePos) const {
     25     if (ptNodePos < 0 || ptNodePos >= mDictSize) {
     26         // Reading invalid position because of bug or broken dictionary.
     27         AKLOGE("Fetching PtNode info from invalid dictionary position: %d, dictionary size: %d",
     28                 ptNodePos, mDictSize);
     29         ASSERT(false);
     30         return PtNodeParams();
     31     }
     32     PatriciaTrieReadingUtils::NodeFlags flags;
     33     int mergedNodeCodePointCount = 0;
     34     int mergedNodeCodePoints[MAX_WORD_LENGTH];
     35     int probability = NOT_A_PROBABILITY;
     36     int childrenPos = NOT_A_DICT_POS;
     37     int shortcutPos = NOT_A_DICT_POS;
     38     int bigramPos = NOT_A_DICT_POS;
     39     int siblingPos = NOT_A_DICT_POS;
     40     PatriciaTrieReadingUtils::readPtNodeInfo(mDictBuffer, ptNodePos, mShortuctPolicy,
     41             mBigramPolicy, &flags, &mergedNodeCodePointCount, mergedNodeCodePoints, &probability,
     42             &childrenPos, &shortcutPos, &bigramPos, &siblingPos);
     43     if (mergedNodeCodePointCount <= 0) {
     44         AKLOGE("Empty PtNode is not allowed. Code point count: %d", mergedNodeCodePointCount);
     45         ASSERT(false);
     46         return PtNodeParams();
     47     }
     48     return PtNodeParams(ptNodePos, flags, mergedNodeCodePointCount, mergedNodeCodePoints,
     49             probability, childrenPos, shortcutPos, bigramPos, siblingPos);
     50 }
     51 
     52 }
     53