Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 95d16561 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi
Browse files

Remove unused code.

Bug: 12810574
Change-Id: I9c7fff60ae0e94d52f3bd19c3e88de5a53b917d7
parent 0fc93fe4
Loading
Loading
Loading
Loading
+1 −75
Original line number Diff line number Diff line
@@ -17,14 +17,10 @@
package com.android.inputmethod.latin.makedict;

import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.CharEncoding;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeMap;

/**
@@ -35,34 +31,6 @@ public abstract class AbstractDictDecoder implements DictDecoder {
    private static final int ERROR_CANNOT_READ = 1;
    private static final int ERROR_WRONG_FORMAT = 2;

    protected DictionaryHeader readHeader(final DictBuffer headerBuffer)
            throws IOException, UnsupportedFormatException {
        if (headerBuffer == null) {
            openDictBuffer();
        }

        final int version = HeaderReader.readVersion(headerBuffer);
        if (version < FormatSpec.MINIMUM_SUPPORTED_VERSION
                || version > FormatSpec.MAXIMUM_SUPPORTED_VERSION) {
          throw new UnsupportedFormatException("Unsupported version : " + version);
        }
        // TODO: Remove this field.
        HeaderReader.readOptionFlags(headerBuffer);
        final int headerSize = HeaderReader.readHeaderSize(headerBuffer);
        if (headerSize < 0) {
            throw new UnsupportedFormatException("header size can't be negative.");
        }

        final HashMap<String, String> attributes = HeaderReader.readAttributes(headerBuffer,
                headerSize);

        final DictionaryHeader header = new DictionaryHeader(headerSize,
                new FusionDictionary.DictionaryOptions(attributes),
                new FormatOptions(version, DictionaryHeader.ATTRIBUTE_VALUE_TRUE.equals(
                        attributes.get(DictionaryHeader.HAS_HISTORICAL_INFO_KEY))));
        return header;
    }

    @Override @UsedForTesting
    public int getTerminalPosition(final String word)
            throws IOException, UnsupportedFormatException {
@@ -83,38 +51,6 @@ public abstract class AbstractDictDecoder implements DictDecoder {
        BinaryDictIOUtils.readUnigramsAndBigramsBinary(this, words, frequencies, bigrams);
    }

    /**
     * A utility class for reading a file header.
     */
    protected static class HeaderReader {
        protected static int readVersion(final DictBuffer dictBuffer)
                throws IOException, UnsupportedFormatException {
            return BinaryDictDecoderUtils.checkFormatVersion(dictBuffer);
        }

        protected static int readOptionFlags(final DictBuffer dictBuffer) {
            return dictBuffer.readUnsignedShort();
        }

        protected static int readHeaderSize(final DictBuffer dictBuffer) {
            return dictBuffer.readInt();
        }

        protected static HashMap<String, String> readAttributes(final DictBuffer dictBuffer,
                final int headerSize) {
            final HashMap<String, String> attributes = new HashMap<String, String>();
            while (dictBuffer.position() < headerSize) {
                // We can avoid an infinite loop here since dictBuffer.position() is always
                // increased by calling CharEncoding.readString.
                final String key = CharEncoding.readString(dictBuffer);
                final String value = CharEncoding.readString(dictBuffer);
                attributes.put(key, value);
            }
            dictBuffer.position(headerSize);
            return attributes;
        }
    }

    /**
     * Check whether the header contains the expected information. This is a no-error method,
     * that will return an error code and never throw a checked exception.
@@ -148,7 +84,7 @@ public abstract class AbstractDictDecoder implements DictDecoder {
    }

    @Override
    public PtNodeInfo readPtNode(final int ptNodePos, final FormatOptions options) {
    public PtNodeInfo readPtNode(final int ptNodePos) {
        return null;
    }

@@ -165,14 +101,4 @@ public abstract class AbstractDictDecoder implements DictDecoder {
    public int readPtNodeCount() {
        return 0;
    }

    @Override
    public boolean readAndFollowForwardLink() {
        return false;
    }

    @Override
    public boolean hasNextPtNodeArray() {
        return false;
    }
}
+5 −181
Original line number Diff line number Diff line
@@ -17,18 +17,12 @@
package com.android.inputmethod.latin.makedict;

import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;

/**
 * Decodes binary files for a FusionDictionary.
@@ -47,8 +41,6 @@ public final class BinaryDictDecoderUtils {
        // This utility class is not publicly instantiable.
    }

    private static final int MAX_JUMPS = 12;

    @UsedForTesting
    public interface DictBuffer {
        public int readUnsignedByte();
@@ -296,60 +288,21 @@ public final class BinaryDictDecoderUtils {
     * @param dictDecoder the dict decoder.
     * @param headerSize the size of the header.
     * @param pos the position to seek.
     * @param formatOptions file format options.
     * @return the word with its frequency, as a weighted string.
     */
    @UsedForTesting
    /* package for tests */ static WeightedString getWordAtPosition(final DictDecoder dictDecoder,
            final int headerSize, final int pos, final FormatOptions formatOptions) {
            final int headerSize, final int pos) {
        final WeightedString result;
        final int originalPos = dictDecoder.getPosition();
        dictDecoder.setPosition(pos);

        if (BinaryDictIOUtils.supportsDynamicUpdate(formatOptions)) {
            result = getWordAtPositionWithParentAddress(dictDecoder, pos, formatOptions);
        } else {
            result = getWordAtPositionWithoutParentAddress(dictDecoder, headerSize, pos,
                    formatOptions);
        }

        result = getWordAtPositionWithoutParentAddress(dictDecoder, headerSize, pos);
        dictDecoder.setPosition(originalPos);
        return result;
    }

    @SuppressWarnings("unused")
    private static WeightedString getWordAtPositionWithParentAddress(final DictDecoder dictDecoder,
            final int pos, final FormatOptions options) {
        int currentPos = pos;
        ProbabilityInfo probabilityInfo = null;
        final StringBuilder builder = new StringBuilder();
        // the length of the path from the root to the leaf is limited by MAX_WORD_LENGTH
        for (int count = 0; count < FormatSpec.MAX_WORD_LENGTH; ++count) {
            PtNodeInfo currentInfo;
            int loopCounter = 0;
            do {
                dictDecoder.setPosition(currentPos);
                currentInfo = dictDecoder.readPtNode(currentPos, options);
                if (BinaryDictIOUtils.isMovedPtNode(currentInfo.mFlags, options)) {
                    currentPos = currentInfo.mParentAddress + currentInfo.mOriginalAddress;
                }
                if (DBG && loopCounter++ > MAX_JUMPS) {
                    MakedictLog.d("Too many jumps - probably a bug");
                }
            } while (BinaryDictIOUtils.isMovedPtNode(currentInfo.mFlags, options));
            if (probabilityInfo == null) {
                probabilityInfo = currentInfo.mProbabilityInfo;
            }
            builder.insert(0,
                    new String(currentInfo.mCharacters, 0, currentInfo.mCharacters.length));
            if (currentInfo.mParentAddress == FormatSpec.NO_PARENT_ADDRESS) break;
            currentPos = currentInfo.mParentAddress + currentInfo.mOriginalAddress;
        }
        return new WeightedString(builder.toString(), probabilityInfo);
    }

    private static WeightedString getWordAtPositionWithoutParentAddress(
            final DictDecoder dictDecoder, final int headerSize, final int pos,
            final FormatOptions options) {
            final DictDecoder dictDecoder, final int headerSize, final int pos) {
        dictDecoder.setPosition(headerSize);
        final int count = dictDecoder.readPtNodeCount();
        int groupPos = dictDecoder.getPosition();
@@ -358,7 +311,7 @@ public final class BinaryDictDecoderUtils {

        PtNodeInfo last = null;
        for (int i = count - 1; i >= 0; --i) {
            PtNodeInfo info = dictDecoder.readPtNode(groupPos, options);
            PtNodeInfo info = dictDecoder.readPtNode(groupPos);
            groupPos = info.mEndAddress;
            if (info.mOriginalAddress == pos) {
                builder.append(new String(info.mCharacters, 0, info.mCharacters.length));
@@ -389,135 +342,6 @@ public final class BinaryDictDecoderUtils {
        return result;
    }

    /**
     * Reads a single node array from a buffer.
     *
     * This methods reads the file at the current position. A node array is fully expected to start
     * at the current position.
     * This will recursively read other node arrays into the structure, populating the reverse
     * maps on the fly and using them to keep track of already read nodes.
     *
     * @param dictDecoder the dict decoder, correctly positioned at the start of a node array.
     * @param headerSize the size, in bytes, of the file header.
     * @param reverseNodeArrayMap a mapping from addresses to already read node arrays.
     * @param reversePtNodeMap a mapping from addresses to already read PtNodes.
     * @param options file format options.
     * @return the read node array with all his children already read.
     */
    private static PtNodeArray readNodeArray(final DictDecoder dictDecoder,
            final int headerSize, final Map<Integer, PtNodeArray> reverseNodeArrayMap,
            final Map<Integer, PtNode> reversePtNodeMap, final FormatOptions options)
            throws IOException {
        final ArrayList<PtNode> nodeArrayContents = new ArrayList<PtNode>();
        final int nodeArrayOriginPos = dictDecoder.getPosition();

        do { // Scan the linked-list node.
            final int count = dictDecoder.readPtNodeCount();
            int groupPos = dictDecoder.getPosition();
            for (int i = count; i > 0; --i) { // Scan the array of PtNode.
                PtNodeInfo info = dictDecoder.readPtNode(groupPos, options);
                if (BinaryDictIOUtils.isMovedPtNode(info.mFlags, options)) continue;
                ArrayList<WeightedString> shortcutTargets = info.mShortcutTargets;
                ArrayList<WeightedString> bigrams = null;
                if (null != info.mBigrams) {
                    bigrams = new ArrayList<WeightedString>();
                    for (PendingAttribute bigram : info.mBigrams) {
                        final WeightedString word = getWordAtPosition(dictDecoder, headerSize,
                                bigram.mAddress, options);
                        final int reconstructedFrequency =
                                BinaryDictIOUtils.reconstructBigramFrequency(word.getProbability(),
                                        bigram.mFrequency);
                        bigrams.add(new WeightedString(word.mWord, reconstructedFrequency));
                    }
                }
                if (BinaryDictIOUtils.hasChildrenAddress(info.mChildrenAddress)) {
                    PtNodeArray children = reverseNodeArrayMap.get(info.mChildrenAddress);
                    if (null == children) {
                        final int currentPosition = dictDecoder.getPosition();
                        dictDecoder.setPosition(info.mChildrenAddress);
                        children = readNodeArray(dictDecoder, headerSize, reverseNodeArrayMap,
                                reversePtNodeMap, options);
                        dictDecoder.setPosition(currentPosition);
                    }
                    nodeArrayContents.add(
                            new PtNode(info.mCharacters, shortcutTargets, bigrams,
                                    info.mProbabilityInfo,
                                    0 != (info.mFlags & FormatSpec.FLAG_IS_NOT_A_WORD),
                                    0 != (info.mFlags & FormatSpec.FLAG_IS_BLACKLISTED), children));
                } else {
                    nodeArrayContents.add(
                            new PtNode(info.mCharacters, shortcutTargets, bigrams,
                                    info.mProbabilityInfo,
                                    0 != (info.mFlags & FormatSpec.FLAG_IS_NOT_A_WORD),
                                    0 != (info.mFlags & FormatSpec.FLAG_IS_BLACKLISTED)));
                }
                groupPos = info.mEndAddress;
            }

            // reach the end of the array.
            if (options.supportsDynamicUpdate()) {
                final boolean hasValidForwardLink = dictDecoder.readAndFollowForwardLink();
                if (!hasValidForwardLink) break;
            }
        } while (options.supportsDynamicUpdate() && dictDecoder.hasNextPtNodeArray());

        final PtNodeArray nodeArray = new PtNodeArray(nodeArrayContents);
        nodeArray.mCachedAddressBeforeUpdate = nodeArrayOriginPos;
        nodeArray.mCachedAddressAfterUpdate = nodeArrayOriginPos;
        reverseNodeArrayMap.put(nodeArray.mCachedAddressAfterUpdate, nodeArray);
        return nodeArray;
    }

    /**
     * Helper function to get the binary format version from the header.
     * @throws IOException
     */
    private static int getFormatVersion(final DictBuffer dictBuffer)
            throws IOException {
        final int magic = dictBuffer.readInt();
        if (FormatSpec.MAGIC_NUMBER == magic) return dictBuffer.readUnsignedShort();
        return FormatSpec.NOT_A_VERSION_NUMBER;
    }

    /**
     * Helper function to get and validate the binary format version.
     * @throws UnsupportedFormatException
     * @throws IOException
     */
    static int checkFormatVersion(final DictBuffer dictBuffer)
            throws IOException, UnsupportedFormatException {
        final int version = getFormatVersion(dictBuffer);
        if (version < FormatSpec.MINIMUM_SUPPORTED_VERSION
                || version > FormatSpec.MAXIMUM_SUPPORTED_VERSION) {
            throw new UnsupportedFormatException("This file has version " + version
                    + ", but this implementation does not support versions above "
                    + FormatSpec.MAXIMUM_SUPPORTED_VERSION);
        }
        return version;
    }

    /**
     * Reads a buffer and returns the memory representation of the dictionary.
     *
     * This high-level method takes a buffer and reads its contents, populating a
     * FusionDictionary structure.
     *
     * @param dictDecoder the dict decoder.
     * @return the created dictionary.
     */
    @UsedForTesting
    /* package */ static FusionDictionary readDictionaryBinary(final DictDecoder dictDecoder)
            throws IOException, UnsupportedFormatException {
        // Read header
        final DictionaryHeader fileHeader = dictDecoder.readHeader();

        Map<Integer, PtNodeArray> reverseNodeArrayMapping = new TreeMap<Integer, PtNodeArray>();
        Map<Integer, PtNode> reversePtNodeMapping = new TreeMap<Integer, PtNode>();
        final PtNodeArray root = readNodeArray(dictDecoder, fileHeader.mBodyOffset,
                reverseNodeArrayMapping, reversePtNodeMapping, fileHeader.mFormatOptions);
        return new FusionDictionary(root, fileHeader.mDictionaryOptions);
    }

    /**
     * Helper method to pass a file name instead of a File object to isBinaryDictionary.
     */
+52 −141

File changed.

Preview size limit exceeded, changes collapsed.

+13 −115
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.inputmethod.latin.makedict;

import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.CharEncoding;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.utils.ByteArrayDictBuffer;
@@ -60,8 +59,7 @@ public final class BinaryDictIOUtils {
    private static void readUnigramsAndBigramsBinaryInner(final DictDecoder dictDecoder,
            final int bodyOffset, final Map<Integer, String> words,
            final Map<Integer, Integer> frequencies,
            final Map<Integer, ArrayList<PendingAttribute>> bigrams,
            final FormatOptions formatOptions) {
            final Map<Integer, ArrayList<PendingAttribute>> bigrams) {
        int[] pushedChars = new int[FormatSpec.MAX_WORD_LENGTH + 1];

        Stack<Position> stack = new Stack<Position>();
@@ -90,17 +88,12 @@ public final class BinaryDictIOUtils {
                stack.pop();
                continue;
            }
            final PtNodeInfo ptNodeInfo = dictDecoder.readPtNode(p.mAddress, formatOptions);
            final PtNodeInfo ptNodeInfo = dictDecoder.readPtNode(p.mAddress);
            for (int i = 0; i < ptNodeInfo.mCharacters.length; ++i) {
                pushedChars[index++] = ptNodeInfo.mCharacters[i];
            }
            p.mPosition++;

            final boolean isMovedPtNode = isMovedPtNode(ptNodeInfo.mFlags,
                    formatOptions);
            final boolean isDeletedPtNode = isDeletedPtNode(ptNodeInfo.mFlags,
                    formatOptions);
            if (!isMovedPtNode && !isDeletedPtNode && ptNodeInfo.isTerminal()) {// found word
            if (ptNodeInfo.isTerminal()) {// found word
                words.put(ptNodeInfo.mOriginalAddress, new String(pushedChars, 0, index));
                frequencies.put(
                        ptNodeInfo.mOriginalAddress, ptNodeInfo.mProbabilityInfo.mProbability);
@@ -110,25 +103,13 @@ public final class BinaryDictIOUtils {
            }

            if (p.mPosition == p.mNumOfPtNode) {
                if (formatOptions.supportsDynamicUpdate()) {
                    final boolean hasValidForwardLinkAddress =
                            dictDecoder.readAndFollowForwardLink();
                    if (hasValidForwardLinkAddress && dictDecoder.hasNextPtNodeArray()) {
                        // The node array has a forward link.
                        p.mNumOfPtNode = Position.NOT_READ_PTNODE_COUNT;
                        p.mAddress = dictDecoder.getPosition();
                    } else {
                        stack.pop();
                    }
                } else {
                stack.pop();
                }
            } else {
                // The Ptnode array has more PtNodes.
                // The PtNode array has more PtNodes.
                p.mAddress = dictDecoder.getPosition();
            }

            if (!isMovedPtNode && hasChildrenAddress(ptNodeInfo.mChildrenAddress)) {
            if (hasChildrenAddress(ptNodeInfo.mChildrenAddress)) {
                final Position childrenPos = new Position(ptNodeInfo.mChildrenAddress, index);
                stack.push(childrenPos);
            }
@@ -153,7 +134,7 @@ public final class BinaryDictIOUtils {
        // Read header
        final DictionaryHeader header = dictDecoder.readHeader();
        readUnigramsAndBigramsBinaryInner(dictDecoder, header.mBodyOffset, words,
                frequencies, bigrams, header.mFormatOptions);
            frequencies, bigrams);
    }

    /**
@@ -171,8 +152,7 @@ public final class BinaryDictIOUtils {
            final String word) throws IOException, UnsupportedFormatException {
        if (word == null) return FormatSpec.NOT_VALID_WORD;
        dictDecoder.setPosition(0);

        final DictionaryHeader header = dictDecoder.readHeader();
        dictDecoder.readHeader();
        int wordPos = 0;
        final int wordLen = word.codePointCount(0, word.length());
        for (int depth = 0; depth < Constants.DICTIONARY_MAX_WORD_LENGTH; ++depth) {
@@ -183,13 +163,7 @@ public final class BinaryDictIOUtils {
                boolean foundNextPtNode = false;
                for (int i = 0; i < ptNodeCount; ++i) {
                    final int ptNodePos = dictDecoder.getPosition();
                    final PtNodeInfo currentInfo = dictDecoder.readPtNode(ptNodePos,
                            header.mFormatOptions);
                    final boolean isMovedNode = isMovedPtNode(currentInfo.mFlags,
                            header.mFormatOptions);
                    final boolean isDeletedNode = isDeletedPtNode(currentInfo.mFlags,
                            header.mFormatOptions);
                    if (isMovedNode) continue;
                    final PtNodeInfo currentInfo = dictDecoder.readPtNode(ptNodePos);
                    boolean same = true;
                    for (int p = 0, j = word.offsetByCodePoints(0, wordPos);
                            p < currentInfo.mCharacters.length;
@@ -204,7 +178,7 @@ public final class BinaryDictIOUtils {
                    if (same) {
                        // found the PtNode matches the word.
                        if (wordPos + currentInfo.mCharacters.length == wordLen) {
                            if (!currentInfo.isTerminal() || isDeletedNode) {
                            if (!currentInfo.isTerminal()) {
                                return FormatSpec.NOT_VALID_WORD;
                            } else {
                                return ptNodePos;
@@ -219,64 +193,13 @@ public final class BinaryDictIOUtils {
                        break;
                    }
                }

                // If we found the next PtNode, it is under the file pointer.
                // But if not, we are at the end of this node array so we expect to have
                // a forward link address that we need to consult and possibly resume
                // search on the next node array in the linked list.
                if (foundNextPtNode) break;
                if (!header.mFormatOptions.supportsDynamicUpdate()) {
                return FormatSpec.NOT_VALID_WORD;
                }

                final boolean hasValidForwardLinkAddress =
                        dictDecoder.readAndFollowForwardLink();
                if (!hasValidForwardLinkAddress || !dictDecoder.hasNextPtNodeArray()) {
                    return FormatSpec.NOT_VALID_WORD;
                }
            } while(true);
        }
        return FormatSpec.NOT_VALID_WORD;
    }

    /**
     * @return the size written, in bytes. Always 3 bytes.
     */
    @UsedForTesting
    static int writeSInt24ToBuffer(final DictBuffer dictBuffer, final int value) {
        final int absValue = Math.abs(value);
        dictBuffer.put((byte)(((value < 0 ? 0x80 : 0) | (absValue >> 16)) & 0xFF));
        dictBuffer.put((byte)((absValue >> 8) & 0xFF));
        dictBuffer.put((byte)(absValue & 0xFF));
        return 3;
    }

    /**
     * @return the size written, in bytes. Always 3 bytes.
     */
    @UsedForTesting
    static int writeSInt24ToStream(final OutputStream destination, final int value)
            throws IOException {
        final int absValue = Math.abs(value);
        destination.write((byte)(((value < 0 ? 0x80 : 0) | (absValue >> 16)) & 0xFF));
        destination.write((byte)((absValue >> 8) & 0xFF));
        destination.write((byte)(absValue & 0xFF));
        return 3;
    }

    @UsedForTesting
    static void skipString(final DictBuffer dictBuffer,
            final boolean hasMultipleChars) {
        if (hasMultipleChars) {
            int character = CharEncoding.readChar(dictBuffer);
            while (character != FormatSpec.INVALID_CHARACTER) {
                character = CharEncoding.readChar(dictBuffer);
            }
        } else {
            CharEncoding.readChar(dictBuffer);
        }
    }

    /**
     * Writes a PtNodeCount to the stream.
     *
@@ -355,30 +278,6 @@ public final class BinaryDictIOUtils {
        return FormatSpec.NO_CHILDREN_ADDRESS != address;
    }

    /**
     * Helper method to check whether the node is moved.
     */
    public static boolean isMovedPtNode(final int flags, final FormatOptions options) {
        return options.supportsDynamicUpdate()
                && ((flags & FormatSpec.MASK_CHILDREN_ADDRESS_TYPE) == FormatSpec.FLAG_IS_MOVED);
    }

    /**
     * Helper method to check whether the dictionary can be updated dynamically.
     */
    public static boolean supportsDynamicUpdate(final FormatOptions options) {
        return options.mVersion >= FormatSpec.FIRST_VERSION_WITH_DYNAMIC_UPDATE
                && options.supportsDynamicUpdate();
    }

    /**
     * Helper method to check whether the node is deleted.
     */
    public static boolean isDeletedPtNode(final int flags, final FormatOptions formatOptions) {
        return formatOptions.supportsDynamicUpdate()
                && ((flags & FormatSpec.MASK_CHILDREN_ADDRESS_TYPE) == FormatSpec.FLAG_IS_DELETED);
    }

    /**
     * Compute the binary size of the node count
     * @param count the node count
@@ -396,9 +295,7 @@ public final class BinaryDictIOUtils {
        }
    }

    static int getChildrenAddressSize(final int optionFlags,
            final FormatOptions formatOptions) {
        if (formatOptions.supportsDynamicUpdate()) return FormatSpec.SIGNED_CHILDREN_ADDRESS_SIZE;
    static int getChildrenAddressSize(final int optionFlags) {
        switch (optionFlags & FormatSpec.MASK_CHILDREN_ADDRESS_TYPE) {
            case FormatSpec.FLAG_CHILDREN_ADDRESS_TYPE_ONEBYTE:
                return 1;
@@ -419,6 +316,7 @@ public final class BinaryDictIOUtils {
     * @param bigramFrequency compressed frequency
     * @return approximate bigram frequency
     */
    @UsedForTesting
    public static int reconstructBigramFrequency(final int unigramFrequency,
            final int bigramFrequency) {
        final float stepSize = (FormatSpec.MAX_TERMINAL_FREQUENCY - unigramFrequency)
+1 −11
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.inputmethod.latin.makedict;

import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.utils.ByteArrayDictBuffer;

import java.io.File;
@@ -45,10 +44,9 @@ public interface DictDecoder {
    /**
     * Reads PtNode from ptNodePos.
     * @param ptNodePos the position of PtNode.
     * @param formatOptions the format options.
     * @return PtNodeInfo.
     */
    public PtNodeInfo readPtNode(final int ptNodePos, final FormatOptions formatOptions);
    public PtNodeInfo readPtNode(final int ptNodePos);

    /**
     * Reads a buffer and returns the memory representation of the dictionary.
@@ -112,14 +110,6 @@ public interface DictDecoder {
     */
    public int readPtNodeCount();

    /**
     * Reads the forward link and advances the position.
     *
     * @return true if this method moves the file pointer, false otherwise.
     */
    public boolean readAndFollowForwardLink();
    public boolean hasNextPtNodeArray();

    /**
     * Opens the dictionary file and makes DictBuffer.
     */
Loading