Merge "Consolidate forwardTouchEvent with dispatchTouchEvent"
diff --git a/java/res/drawable-hdpi/ic_emoji_dark.png b/java/res/drawable-hdpi/ic_emoji_dark.png
new file mode 100644
index 0000000..a9f18cd
--- /dev/null
+++ b/java/res/drawable-hdpi/ic_emoji_dark.png
Binary files differ
diff --git a/java/res/drawable-hdpi/ic_emoji_light.png b/java/res/drawable-hdpi/ic_emoji_light.png
new file mode 100644
index 0000000..2e3638b
--- /dev/null
+++ b/java/res/drawable-hdpi/ic_emoji_light.png
Binary files differ
diff --git a/java/res/drawable-mdpi/ic_emoji_dark.png b/java/res/drawable-mdpi/ic_emoji_dark.png
new file mode 100644
index 0000000..d0047a4
--- /dev/null
+++ b/java/res/drawable-mdpi/ic_emoji_dark.png
Binary files differ
diff --git a/java/res/drawable-mdpi/ic_emoji_light.png b/java/res/drawable-mdpi/ic_emoji_light.png
new file mode 100644
index 0000000..a319504
--- /dev/null
+++ b/java/res/drawable-mdpi/ic_emoji_light.png
Binary files differ
diff --git a/java/res/drawable-xhdpi/ic_emoji_dark.png b/java/res/drawable-xhdpi/ic_emoji_dark.png
new file mode 100644
index 0000000..22daec2
--- /dev/null
+++ b/java/res/drawable-xhdpi/ic_emoji_dark.png
Binary files differ
diff --git a/java/res/drawable-xhdpi/ic_emoji_light.png b/java/res/drawable-xhdpi/ic_emoji_light.png
new file mode 100644
index 0000000..21bc909
--- /dev/null
+++ b/java/res/drawable-xhdpi/ic_emoji_light.png
Binary files differ
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index b054e03..eef9116 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -216,6 +216,7 @@
         <attr name="iconLanguageSwitchKey" format="reference" />
         <attr name="iconZwnjKey" format="reference" />
         <attr name="iconZwjKey" format="reference" />
+        <attr name="iconEmojiKey" format="reference" />
     </declare-styleable>
 
     <declare-styleable name="Keyboard_Key">
diff --git a/java/res/values/keyboard-icons-black.xml b/java/res/values/keyboard-icons-black.xml
index e9c5733..c1b1b65 100644
--- a/java/res/values/keyboard-icons-black.xml
+++ b/java/res/values/keyboard-icons-black.xml
@@ -39,5 +39,6 @@
         <!-- TODO: Needs dedicated black theme ZWNJ and ZWJ icons -->
         <item name="iconZwnjKey">@drawable/sym_keyboard_zwnj_holo</item>
         <item name="iconZwjKey">@drawable/sym_keyboard_zwj_holo</item>
+        <item name="iconEmojiKey">@drawable/ic_emoji_light</item>
     </style>
 </resources>
diff --git a/java/res/values/keyboard-icons-ics.xml b/java/res/values/keyboard-icons-ics.xml
index 8eba196..5ada27a 100644
--- a/java/res/values/keyboard-icons-ics.xml
+++ b/java/res/values/keyboard-icons-ics.xml
@@ -36,5 +36,6 @@
         <item name="iconLanguageSwitchKey">@drawable/sym_keyboard_language_switch</item>
         <item name="iconZwnjKey">@drawable/sym_keyboard_zwnj_holo</item>
         <item name="iconZwjKey">@drawable/sym_keyboard_zwj_holo</item>
+        <item name="iconEmojiKey">@drawable/ic_emoji_light</item>
     </style>
 </resources>
diff --git a/java/res/values/keyboard-icons-white.xml b/java/res/values/keyboard-icons-white.xml
index e520998..7c6de42 100644
--- a/java/res/values/keyboard-icons-white.xml
+++ b/java/res/values/keyboard-icons-white.xml
@@ -35,5 +35,6 @@
         <!-- TODO: Needs dedicated black theme ZWNJ and ZWJ icons -->
         <item name="iconZwnjKey">@drawable/sym_keyboard_zwnj_holo</item>
         <item name="iconZwjKey">@drawable/sym_keyboard_zwj_holo</item>
+        <item name="iconEmojiKey">@drawable/ic_emoji_dark</item>
     </style>
 </resources>
diff --git a/java/res/xml-sw600dp/key_styles_common.xml b/java/res/xml-sw600dp/key_styles_common.xml
index a2d2fd8..f407ba3 100644
--- a/java/res/xml-sw600dp/key_styles_common.xml
+++ b/java/res/xml-sw600dp/key_styles_common.xml
@@ -120,6 +120,11 @@
         latin:keyActionFlags="noKeyPreview|altCodeWhileTyping|enableLongPress"
         latin:altCode="!code/key_space" />
     <key-style
+        latin:styleName="emojiKeyStyle"
+        latin:code="!code/key_emoji"
+        latin:keyIcon="!icon/emoji_key"
+        latin:keyActionFlags="noKeyPreview" />
+    <key-style
         latin:styleName="settingsKeyStyle"
         latin:code="!code/key_settings"
         latin:keyIcon="!icon/settings_key"
diff --git a/java/res/xml-sw600dp/rows_10_10_7_symbols.xml b/java/res/xml-sw600dp/rows_10_10_7_symbols.xml
index 44c967c..0e4710c 100644
--- a/java/res/xml-sw600dp/rows_10_10_7_symbols.xml
+++ b/java/res/xml-sw600dp/rows_10_10_7_symbols.xml
@@ -43,7 +43,7 @@
             latin:keyStyle="enterKeyStyle"
             latin:keyWidth="fillRight" />
     </Row>
-        <Row
+    <Row
         latin:keyWidth="9.0%p"
     >
         <Key
diff --git a/java/res/xml-sw768dp/key_styles_common.xml b/java/res/xml-sw768dp/key_styles_common.xml
index e69bc30..7c0a82a 100644
--- a/java/res/xml-sw768dp/key_styles_common.xml
+++ b/java/res/xml-sw768dp/key_styles_common.xml
@@ -110,6 +110,11 @@
         latin:keyActionFlags="noKeyPreview|altCodeWhileTyping|enableLongPress"
         latin:altCode="!code/key_space" />
     <key-style
+        latin:styleName="emojiKeyStyle"
+        latin:code="!code/key_emoji"
+        latin:keyIcon="!icon/emoji_key"
+        latin:keyActionFlags="noKeyPreview" />
+    <key-style
         latin:styleName="settingsKeyStyle"
         latin:code="!code/key_settings"
         latin:keyIcon="!icon/settings_key"
diff --git a/java/res/xml/key_styles_common.xml b/java/res/xml/key_styles_common.xml
index 6590d0a..355455e 100644
--- a/java/res/xml/key_styles_common.xml
+++ b/java/res/xml/key_styles_common.xml
@@ -126,6 +126,11 @@
         latin:keyActionFlags="noKeyPreview|altCodeWhileTyping|enableLongPress"
         latin:altCode="!code/key_space" />
     <key-style
+        latin:styleName="emojiKeyStyle"
+        latin:code="!code/key_emoji"
+        latin:keyIcon="!icon/emoji_key"
+        latin:keyActionFlags="noKeyPreview" />
+    <key-style
         latin:styleName="tabKeyStyle"
         latin:code="!code/key_tab"
         latin:keyIcon="!icon/tab_key"
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java
index 69ffb4c..dc815e5 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java
@@ -53,6 +53,7 @@
         "key_action_previous",
         "key_shift_enter",
         "key_language_switch",
+        "key_emoji",
         "key_unspecified",
         "key_left_parenthesis",
         "key_right_parenthesis",
@@ -89,6 +90,7 @@
         Constants.CODE_ACTION_PREVIOUS,
         Constants.CODE_SHIFT_ENTER,
         Constants.CODE_LANGUAGE_SWITCH,
+        Constants.CODE_EMOJI,
         Constants.CODE_UNSPECIFIED,
         CODE_LEFT_PARENTHESIS,
         CODE_RIGHT_PARENTHESIS,
@@ -116,6 +118,7 @@
         DEFAULT[12],
         DEFAULT[13],
         DEFAULT[14],
+        DEFAULT[15],
         CODE_RIGHT_PARENTHESIS,
         CODE_LEFT_PARENTHESIS,
         CODE_GREATER_THAN_SIGN,
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java
index 4e3f761..336db18 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java
@@ -56,6 +56,7 @@
         "language_switch_key",          R.styleable.Keyboard_iconLanguageSwitchKey,
         "zwnj_key",                     R.styleable.Keyboard_iconZwnjKey,
         "zwj_key",                      R.styleable.Keyboard_iconZwjKey,
+        "emoji_key",                    R.styleable.Keyboard_iconEmojiKey,
     };
 
     private static int NUM_ICONS = NAMES_AND_ATTR_IDS.length / 2;
diff --git a/java/src/com/android/inputmethod/latin/Constants.java b/java/src/com/android/inputmethod/latin/Constants.java
index f91a21c..8aec03f 100644
--- a/java/src/com/android/inputmethod/latin/Constants.java
+++ b/java/src/com/android/inputmethod/latin/Constants.java
@@ -187,6 +187,7 @@
     public static final int CODE_ACTION_NEXT = -8;
     public static final int CODE_ACTION_PREVIOUS = -9;
     public static final int CODE_LANGUAGE_SWITCH = -10;
+    public static final int CODE_EMOJI = -11;
     public static final int CODE_SHIFT_ENTER = -12;
     // Code value representing the code is not specified.
     public static final int CODE_UNSPECIFIED = -13;
@@ -207,6 +208,7 @@
         case CODE_ACTION_NEXT: return "actionNext";
         case CODE_ACTION_PREVIOUS: return "actionPrevious";
         case CODE_LANGUAGE_SWITCH: return "languageSwitch";
+        case CODE_EMOJI: return "emoji";
         case CODE_SHIFT_ENTER: return "shiftEnter";
         case CODE_UNSPECIFIED: return "unspec";
         case CODE_TAB: return "tab";
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index e1906c5..d970bca 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1510,6 +1510,9 @@
         case Constants.CODE_LANGUAGE_SWITCH:
             handleLanguageSwitchKey();
             break;
+        case Constants.CODE_EMOJI:
+            // TODO: Implement emoji keyboard switch.
+            break;
         case Constants.CODE_ENTER:
             final EditorInfo editorInfo = getCurrentInputEditorInfo();
             final int imeOptionsActionId =
diff --git a/native/jni/Android.mk b/native/jni/Android.mk
index acd230f..e14cf5a 100644
--- a/native/jni/Android.mk
+++ b/native/jni/Android.mk
@@ -71,7 +71,9 @@
     suggest/core/policy/weighting.cpp \
     suggest/core/session/dic_traverse_session.cpp \
     $(addprefix suggest/policyimpl/dictionary/, \
+        dynamic_patricia_trie_node_reader.cpp \
         dynamic_patricia_trie_policy.cpp \
+        dynamic_patricia_trie_reading_utils.cpp \
         patricia_trie_policy.cpp \
         patricia_trie_reading_utils.cpp) \
     suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp \
diff --git a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cpp b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cpp
new file mode 100644
index 0000000..20cda91
--- /dev/null
+++ b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2013, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.h"
+
+#include "suggest/core/dictionary/binary_dictionary_info.h"
+#include "suggest/core/dictionary/binary_dictionary_terminal_attributes_reading_utils.h"
+#include "suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.h"
+
+namespace latinime {
+
+void DynamicPatriciaTrieNodeReader::fetchNodeInfoFromBufferAndProcessMovedNode(const int nodePos,
+        const int maxCodePointCount, int *const outCodePoints) {
+    const uint8_t *const dictRoot = mBinaryDictionaryInfo->getDictRoot();
+    int pos = nodePos;
+    mFlags = PatriciaTrieReadingUtils::getFlagsAndAdvancePosition(dictRoot, &pos);
+    mParentPos = DynamicPatriciaTrieReadingUtils::getParentPosAndAdvancePosition(dictRoot, &pos);
+    if (outCodePoints != 0) {
+        mCodePointCount = PatriciaTrieReadingUtils::getCharsAndAdvancePosition(
+                dictRoot, mFlags, maxCodePointCount, outCodePoints, &pos);
+    } else {
+        mCodePointCount = PatriciaTrieReadingUtils::skipCharacters(
+                dictRoot, mFlags, MAX_WORD_LENGTH, &pos);
+    }
+    if (isTerminal()) {
+        mProbability = PatriciaTrieReadingUtils::readProbabilityAndAdvancePosition(dictRoot, &pos);
+    } else {
+        mProbability = NOT_A_PROBABILITY;
+    }
+    if (hasChildren()) {
+        mChildrenPos = DynamicPatriciaTrieReadingUtils::readChildrenPositionAndAdvancePosition(
+                dictRoot, mFlags, &pos);
+    } else {
+        mChildrenPos = NOT_A_DICT_POS;
+    }
+    if (PatriciaTrieReadingUtils::hasShortcutTargets(mFlags)) {
+        mShortcutPos = pos;
+        BinaryDictionaryTerminalAttributesReadingUtils::skipShortcuts(mBinaryDictionaryInfo, &pos);
+    } else {
+        mShortcutPos = NOT_A_DICT_POS;
+    }
+    if (PatriciaTrieReadingUtils::hasBigrams(mFlags)) {
+        mBigramPos = pos;
+        BinaryDictionaryTerminalAttributesReadingUtils::skipExistingBigrams(
+                mBinaryDictionaryInfo, &pos);
+    } else {
+        mBigramPos = NOT_A_DICT_POS;
+    }
+    // Update siblingPos if needed.
+    if (mSiblingPos == NOT_A_VALID_WORD_POS) {
+        // Sibling position is the tail position of current node.
+        mSiblingPos = pos;
+    }
+    // Read destination node if the read node is a moved node.
+    if (DynamicPatriciaTrieReadingUtils::isMoved(mFlags)) {
+        // The destination position is stored at the same place as the parent position.
+        fetchNodeInfoFromBufferAndProcessMovedNode(mParentPos, maxCodePointCount, outCodePoints);
+    }
+}
+
+}
diff --git a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.h b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.h
new file mode 100644
index 0000000..b668aab
--- /dev/null
+++ b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.h
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2013, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LATINIME_DYNAMIC_PATRICIA_TRIE_NODE_READER_H
+#define LATINIME_DYNAMIC_PATRICIA_TRIE_NODE_READER_H
+
+#include "defines.h"
+#include "suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.h"
+#include "suggest/policyimpl/dictionary/patricia_trie_reading_utils.h"
+
+namespace latinime {
+
+class BinaryDictionaryInfo;
+
+/*
+ * This class is used for helping to read nodes of dynamic patricia trie. This class handles moved
+ * node and reads node attributes.
+ */
+class DynamicPatriciaTrieNodeReader {
+ public:
+    explicit DynamicPatriciaTrieNodeReader(const BinaryDictionaryInfo *const binaryDictionaryInfo)
+            : mBinaryDictionaryInfo(binaryDictionaryInfo), mNodePos(NOT_A_VALID_WORD_POS),
+              mFlags(0), mParentPos(NOT_A_DICT_POS), mCodePointCount(0),
+              mProbability(NOT_A_PROBABILITY), mChildrenPos(NOT_A_DICT_POS),
+              mShortcutPos(NOT_A_DICT_POS), mBigramPos(NOT_A_DICT_POS),
+              mSiblingPos(NOT_A_VALID_WORD_POS) {}
+
+    ~DynamicPatriciaTrieNodeReader() {}
+
+    // Reads node information from dictionary buffer and updates members with the information.
+    AK_FORCE_INLINE void fetchNodeInfoFromBuffer(const int nodePos) {
+        fetchNodeInfoFromBufferAndGetNodeCodePoints(mNodePos , 0 /* maxCodePointCount */,
+                0 /* outCodePoints */);
+    }
+
+    AK_FORCE_INLINE void fetchNodeInfoFromBufferAndGetNodeCodePoints(const int nodePos,
+            const int maxCodePointCount, int *const outCodePoints) {
+        mNodePos = nodePos;
+        mSiblingPos = NOT_A_VALID_WORD_POS;
+        fetchNodeInfoFromBufferAndProcessMovedNode(mNodePos, maxCodePointCount, outCodePoints);
+    }
+
+    AK_FORCE_INLINE int getNodePos() const {
+        return mNodePos;
+    }
+
+    // Flags
+    AK_FORCE_INLINE bool isDeleted() const {
+        return DynamicPatriciaTrieReadingUtils::isDeleted(mFlags);
+    }
+
+    AK_FORCE_INLINE bool hasChildren() const {
+        return PatriciaTrieReadingUtils::hasChildrenInFlags(mFlags);
+    }
+
+    AK_FORCE_INLINE bool isTerminal() const {
+        return PatriciaTrieReadingUtils::isTerminal(mFlags);
+    }
+
+    AK_FORCE_INLINE bool isBlacklisted() const {
+        return PatriciaTrieReadingUtils::isBlacklisted(mFlags);
+    }
+
+    AK_FORCE_INLINE bool isNotAWord() const {
+        return PatriciaTrieReadingUtils::isNotAWord(mFlags);
+    }
+
+    // Parent node position
+    AK_FORCE_INLINE int getParentPos() const {
+        return mParentPos;
+    }
+
+    // Number of code points
+    AK_FORCE_INLINE uint8_t getCodePointCount() const {
+        return mCodePointCount;
+    }
+
+    // Probability
+    AK_FORCE_INLINE int getProbability() const {
+        return mProbability;
+    }
+
+    // Children node group position
+    AK_FORCE_INLINE int getChildrenPos() const {
+        return mChildrenPos;
+    }
+
+    // Shortcutlist position
+    AK_FORCE_INLINE int getShortcutPos() const {
+        return mShortcutPos;
+    }
+
+    // Bigrams position
+    AK_FORCE_INLINE int getBigramsPos() const {
+        return mBigramPos;
+    }
+
+    // Sibling node position
+    AK_FORCE_INLINE int getSiblingNodePos() const {
+        return mSiblingPos;
+    }
+
+ private:
+    DISALLOW_COPY_AND_ASSIGN(DynamicPatriciaTrieNodeReader);
+
+    const BinaryDictionaryInfo *const mBinaryDictionaryInfo;
+    int mNodePos;
+    DynamicPatriciaTrieReadingUtils::NodeFlags mFlags;
+    int mParentPos;
+    uint8_t mCodePointCount;
+    int mProbability;
+    int mChildrenPos;
+    int mShortcutPos;
+    int mBigramPos;
+    int mSiblingPos;
+
+    void fetchNodeInfoFromBufferAndProcessMovedNode(const int nodePos, const int maxCodePointCount,
+            int *const outCodePoints);
+};
+} // namespace latinime
+#endif /* LATINIME_DYNAMIC_PATRICIA_TRIE_NODE_READER_H */
diff --git a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp
index c7314ec..17cbdde 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp
@@ -20,6 +20,9 @@
 #include "suggest/core/dicnode/dic_node.h"
 #include "suggest/core/dicnode/dic_node_vector.h"
 #include "suggest/core/dictionary/binary_dictionary_info.h"
+#include "suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.h"
+#include "suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.h"
+#include "suggest/policyimpl/dictionary/patricia_trie_reading_utils.h"
 
 namespace latinime {
 
@@ -28,7 +31,31 @@
 void DynamicPatriciaTriePolicy::createAndGetAllChildNodes(const DicNode *const dicNode,
         const BinaryDictionaryInfo *const binaryDictionaryInfo,
         const NodeFilter *const nodeFilter, DicNodeVector *const childDicNodes) const {
-    // TODO: Implement.
+    if (!dicNode->hasChildren()) {
+        return;
+    }
+    DynamicPatriciaTrieNodeReader nodeReader(binaryDictionaryInfo);
+    int mergedNodeCodePoints[MAX_WORD_LENGTH];
+    int nextPos = dicNode->getChildrenPos();
+    do {
+        const int childCount = PatriciaTrieReadingUtils::getGroupCountAndAdvancePosition(
+                binaryDictionaryInfo->getDictRoot(), &nextPos);
+        for (int i = 0; i < childCount; i++) {
+            nodeReader.fetchNodeInfoFromBufferAndGetNodeCodePoints(nextPos, MAX_WORD_LENGTH,
+                    mergedNodeCodePoints);
+            if (!nodeReader.isDeleted() && !nodeFilter->isFilteredOut(mergedNodeCodePoints[0])) {
+                // Push child note when the node is not deleted and not filtered out.
+                childDicNodes->pushLeavingChild(dicNode, nodeReader.getNodePos(),
+                        nodeReader.getChildrenPos(), nodeReader.getProbability(),
+                        nodeReader.isTerminal(), nodeReader.hasChildren(),
+                        nodeReader.isBlacklisted() || nodeReader.isNotAWord(),
+                        nodeReader.getCodePointCount(), mergedNodeCodePoints);
+            }
+            nextPos = nodeReader.getSiblingNodePos();
+        }
+        nextPos = DynamicPatriciaTrieReadingUtils::getForwardLinkPosition(
+                binaryDictionaryInfo->getDictRoot(), nextPos);
+    } while(DynamicPatriciaTrieReadingUtils::isValidForwardLinkPosition(nextPos));
 }
 
 int DynamicPatriciaTriePolicy::getCodePointsAndProbabilityAndReturnCodePointCount(
@@ -48,22 +75,34 @@
 
 int DynamicPatriciaTriePolicy::getUnigramProbability(
         const BinaryDictionaryInfo *const binaryDictionaryInfo, const int nodePos) const {
-    // TODO: Implement.
-    return NOT_A_PROBABILITY;
+    DynamicPatriciaTrieNodeReader nodeReader(binaryDictionaryInfo);
+    nodeReader.fetchNodeInfoFromBuffer(nodePos);
+    if (nodeReader.isDeleted() || nodeReader.isBlacklisted() || nodeReader.isNotAWord()) {
+        return NOT_A_PROBABILITY;
+    }
+    return nodeReader.getProbability();
 }
 
 int DynamicPatriciaTriePolicy::getShortcutPositionOfNode(
         const BinaryDictionaryInfo *const binaryDictionaryInfo,
         const int nodePos) const {
-    // TODO: Implement.
-    return NOT_A_DICT_POS;
+    DynamicPatriciaTrieNodeReader nodeReader(binaryDictionaryInfo);
+    nodeReader.fetchNodeInfoFromBuffer(nodePos);
+    if (nodeReader.isDeleted()) {
+        return NOT_A_DICT_POS;
+    }
+    return nodeReader.getShortcutPos();
 }
 
 int DynamicPatriciaTriePolicy::getBigramsPositionOfNode(
         const BinaryDictionaryInfo *const binaryDictionaryInfo,
         const int nodePos) const {
-    // TODO: Implement.
-    return NOT_A_DICT_POS;
+    DynamicPatriciaTrieNodeReader nodeReader(binaryDictionaryInfo);
+    nodeReader.fetchNodeInfoFromBuffer(nodePos);
+    if (nodeReader.isDeleted()) {
+        return NOT_A_DICT_POS;
+    }
+    return nodeReader.getBigramsPos();
 }
 
 } // namespace latinime