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_DYNAMIC_PATRICIA_TRIE_WRITING_UTILS_H 18 #define LATINIME_DYNAMIC_PATRICIA_TRIE_WRITING_UTILS_H 19 20 #include <cstddef> 21 22 #include "defines.h" 23 #include "suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.h" 24 25 namespace latinime { 26 27 class BufferWithExtendableBuffer; 28 29 class DynamicPatriciaTrieWritingUtils { 30 public: 31 static const int NODE_FLAG_FIELD_SIZE; 32 33 static bool writeEmptyDictionary(BufferWithExtendableBuffer *const buffer, const int rootPos); 34 35 static bool writeForwardLinkPositionAndAdvancePosition( 36 BufferWithExtendableBuffer *const buffer, const int forwardLinkPos, 37 int *const forwardLinkFieldPos); 38 39 static bool writePtNodeArraySizeAndAdvancePosition(BufferWithExtendableBuffer *const buffer, 40 const size_t arraySize, int *const arraySizeFieldPos); 41 42 static bool writeFlagsAndAdvancePosition(BufferWithExtendableBuffer *const buffer, 43 const DynamicPatriciaTrieReadingUtils::NodeFlags nodeFlags, 44 int *const nodeFlagsFieldPos); 45 46 static bool writeParentPosOffsetAndAdvancePosition(BufferWithExtendableBuffer *const buffer, 47 const int parentPosition, const int basePos, int *const parentPosFieldPos); 48 49 static bool writeCodePointsAndAdvancePosition(BufferWithExtendableBuffer *const buffer, 50 const int *const codePoints, const int codePointCount, int *const codePointFieldPos); 51 52 static bool writeProbabilityAndAdvancePosition(BufferWithExtendableBuffer *const buffer, 53 const int probability, int *const probabilityFieldPos); 54 55 static bool writeChildrenPositionAndAdvancePosition(BufferWithExtendableBuffer *const buffer, 56 const int childrenPosition, int *const childrenPositionFieldPos); 57 58 private: 59 DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicPatriciaTrieWritingUtils); 60 61 static const size_t MAX_PTNODE_ARRAY_SIZE_TO_USE_SMALL_SIZE_FIELD; 62 static const size_t MAX_PTNODE_ARRAY_SIZE; 63 static const int SMALL_PTNODE_ARRAY_SIZE_FIELD_SIZE; 64 static const int LARGE_PTNODE_ARRAY_SIZE_FIELD_SIZE; 65 static const int LARGE_PTNODE_ARRAY_SIZE_FIELD_SIZE_FLAG; 66 static const int DICT_OFFSET_FIELD_SIZE; 67 static const int MAX_DICT_OFFSET_VALUE; 68 static const int MIN_DICT_OFFSET_VALUE; 69 static const int DICT_OFFSET_NEGATIVE_FLAG; 70 static const int PROBABILITY_FIELD_SIZE; 71 72 static bool writeDictOffset(BufferWithExtendableBuffer *const buffer, const int targetPos, 73 const int basePos, int *const offsetFieldPos); 74 }; 75 } // namespace latinime 76 #endif /* LATINIME_DYNAMIC_PATRICIA_TRIE_WRITING_UTILS_H */ 77