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

Commit e607e072 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android (Google) Code Review
Browse files

Merge "Remove TerminalAttributes."

parents b40d1422 6abdafc6
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
@@ -14,30 +14,24 @@
 * limitations under the License.
 */

#ifndef LATINIME_TERMINAL_ATTRIBUTES_H
#define LATINIME_TERMINAL_ATTRIBUTES_H

#include <stdint.h>
#ifndef LATINIME_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H
#define LATINIME_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H

#include "defines.h"
#include "suggest/core/policy/dictionary_shortcuts_structure_policy.h"

namespace latinime {

/**
 * This class encapsulates information about a terminal that allows to
 * retrieve local node attributes like the list of shortcuts without
 * exposing the format structure to the client.
 */
class TerminalAttributes {
class BinaryDictionaryShortcutIterator {
 public:
    class ShortcutIterator {
     public:
        ShortcutIterator(const DictionaryShortcutsStructurePolicy *const shortcutStructurePolicy,
                const int shortcutPos, const bool hasShortcutList)
                : mShortcutStructurePolicy(shortcutStructurePolicy), mPos(shortcutPos),
                  mHasNextShortcutTarget(hasShortcutList) {}
    BinaryDictionaryShortcutIterator(
            const DictionaryShortcutsStructurePolicy *const shortcutStructurePolicy,
            const int shortcutPos)
            : mShortcutStructurePolicy(shortcutStructurePolicy),
              mPos(shortcutStructurePolicy->getStartPos(shortcutPos)),
              mHasNextShortcutTarget(shortcutPos != NOT_A_DICT_POS) {}

        inline bool hasNextShortcutTarget() const {
    AK_FORCE_INLINE bool hasNextShortcutTarget() const {
        return mHasNextShortcutTarget;
    }

@@ -51,30 +45,11 @@ class TerminalAttributes {
    }

 private:
    DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryDictionaryShortcutIterator);

    const DictionaryShortcutsStructurePolicy *const mShortcutStructurePolicy;
    int mPos;
    bool mHasNextShortcutTarget;
};

    TerminalAttributes(const DictionaryShortcutsStructurePolicy *const shortcutStructurePolicy,
            const int shortcutPos)
            : mShortcutStructurePolicy(shortcutStructurePolicy),
              mShortcutListSizePos(shortcutPos) {}

    inline ShortcutIterator getShortcutIterator() const {
        int shortcutPos = mShortcutListSizePos;
        const bool hasShortcutList = shortcutPos != NOT_A_DICT_POS;
        if (hasShortcutList) {
            shortcutPos = mShortcutStructurePolicy->getStartPos(shortcutPos);
        }
        // shortcutPos is never used if hasShortcutList is false.
        return ShortcutIterator(mShortcutStructurePolicy, shortcutPos, hasShortcutList);
    }

 private:
    DISALLOW_IMPLICIT_CONSTRUCTORS(TerminalAttributes);
    const DictionaryShortcutsStructurePolicy *const mShortcutStructurePolicy;
    const int mShortcutListSizePos;
};
} // namespace latinime
#endif // LATINIME_TERMINAL_ATTRIBUTES_H
#endif // LATINIME_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H
+4 −5
Original line number Diff line number Diff line
@@ -19,21 +19,20 @@

#include "defines.h"
#include "suggest/core/dicnode/dic_node_utils.h"
#include "suggest/core/dictionary/terminal_attributes.h"
#include "suggest/core/dictionary/binary_dictionary_shortcut_iterator.h"

namespace latinime {

class ShortcutUtils {
 public:
    static int outputShortcuts(const TerminalAttributes *const terminalAttributes,
    static int outputShortcuts(BinaryDictionaryShortcutIterator *const shortcutIt,
            int outputWordIndex, const int finalScore, int *const outputCodePoints,
            int *const frequencies, int *const outputTypes, const bool sameAsTyped) {
        TerminalAttributes::ShortcutIterator iterator = terminalAttributes->getShortcutIterator();
        int shortcutTarget[MAX_WORD_LENGTH];
        while (iterator.hasNextShortcutTarget() && outputWordIndex < MAX_RESULTS) {
        while (shortcutIt->hasNextShortcutTarget() && outputWordIndex < MAX_RESULTS) {
            bool isWhilelist;
            int shortcutTargetStringLength;
            iterator.nextShortcutTarget(MAX_WORD_LENGTH, shortcutTarget,
            shortcutIt->nextShortcutTarget(MAX_WORD_LENGTH, shortcutTarget,
                    &shortcutTargetStringLength, &isWhilelist);
            int shortcutScore;
            int kind;
+3 −3
Original line number Diff line number Diff line
@@ -21,10 +21,10 @@
#include "suggest/core/dicnode/dic_node_vector.h"
// TODO: Use DictionaryStructurePolicy instead of BinaryDictionaryInfo.
#include "suggest/core/dictionary/binary_dictionary_info.h"
#include "suggest/core/dictionary/binary_dictionary_shortcut_iterator.h"
#include "suggest/core/dictionary/dictionary.h"
#include "suggest/core/dictionary/digraph_utils.h"
#include "suggest/core/dictionary/shortcut_utils.h"
#include "suggest/core/dictionary/terminal_attributes.h"
#include "suggest/core/layout/proximity_info.h"
#include "suggest/core/policy/scoring.h"
#include "suggest/core/policy/traversal.h"
@@ -214,13 +214,13 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
        if (!terminalDicNode->hasMultipleWords()) {
            const DictionaryStructureWithBufferPolicy *const structurePolicy =
                    traverseSession->getBinaryDictionaryInfo()->getStructurePolicy();
            const TerminalAttributes terminalAttributes(
            BinaryDictionaryShortcutIterator shortcutIt(
                    structurePolicy->getShortcutsStructurePolicy(),
                    structurePolicy->getShortcutPositionOfNode(terminalDicNode->getPos()));
            // Shortcut is not supported for multiple words suggestions.
            // TODO: Check shortcuts during traversal for multiple words suggestions.
            const bool sameAsTyped = TRAVERSAL->sameAsTyped(traverseSession, terminalDicNode);
            outputWordIndex = ShortcutUtils::outputShortcuts(&terminalAttributes, outputWordIndex,
            outputWordIndex = ShortcutUtils::outputShortcuts(&shortcutIt, outputWordIndex,
                    finalScore, outputCodePoints, frequencies, outputTypes, sameAsTyped);
        }
        DicNode::managedDelete(terminalDicNode);