Make readNode read linked list nodes.
Change-Id: Ia5eaae0653179b2eb74c53b0823beaf80377a389
This commit is contained in:
parent
a149c53c8e
commit
c2fdf0dfbf
1 changed files with 52 additions and 34 deletions
|
@ -1347,11 +1347,14 @@ public class BinaryDictInputOutput {
|
||||||
final Map<Integer, Node> reverseNodeMap, final Map<Integer, CharGroup> reverseGroupMap,
|
final Map<Integer, Node> reverseNodeMap, final Map<Integer, CharGroup> reverseGroupMap,
|
||||||
final FormatOptions options)
|
final FormatOptions options)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final int nodeOrigin = buffer.position() - headerSize;
|
|
||||||
final int count = readCharGroupCount(buffer);
|
|
||||||
final ArrayList<CharGroup> nodeContents = new ArrayList<CharGroup>();
|
final ArrayList<CharGroup> nodeContents = new ArrayList<CharGroup>();
|
||||||
int groupOffset = nodeOrigin + getGroupCountSize(count);
|
final int nodeOrigin = buffer.position() - headerSize;
|
||||||
for (int i = count; i > 0; --i) {
|
|
||||||
|
do { // Scan the linked-list node.
|
||||||
|
final int nodeHeadPosition = buffer.position() - headerSize;
|
||||||
|
final int count = readCharGroupCount(buffer);
|
||||||
|
int groupOffset = nodeHeadPosition + getGroupCountSize(count);
|
||||||
|
for (int i = count; i > 0; --i) { // Scan the array of CharGroup.
|
||||||
CharGroupInfo info = readCharGroup(buffer, groupOffset, options);
|
CharGroupInfo info = readCharGroup(buffer, groupOffset, options);
|
||||||
ArrayList<WeightedString> shortcutTargets = info.mShortcutTargets;
|
ArrayList<WeightedString> shortcutTargets = info.mShortcutTargets;
|
||||||
ArrayList<WeightedString> bigrams = null;
|
ArrayList<WeightedString> bigrams = null;
|
||||||
|
@ -1373,17 +1376,32 @@ public class BinaryDictInputOutput {
|
||||||
buffer.position(currentPosition);
|
buffer.position(currentPosition);
|
||||||
}
|
}
|
||||||
nodeContents.add(
|
nodeContents.add(
|
||||||
new CharGroup(info.mCharacters, shortcutTargets, bigrams, info.mFrequency,
|
new CharGroup(info.mCharacters, shortcutTargets, bigrams,
|
||||||
|
info.mFrequency,
|
||||||
0 != (info.mFlags & FormatSpec.FLAG_IS_NOT_A_WORD),
|
0 != (info.mFlags & FormatSpec.FLAG_IS_NOT_A_WORD),
|
||||||
0 != (info.mFlags & FormatSpec.FLAG_IS_BLACKLISTED), children));
|
0 != (info.mFlags & FormatSpec.FLAG_IS_BLACKLISTED), children));
|
||||||
} else {
|
} else {
|
||||||
nodeContents.add(
|
nodeContents.add(
|
||||||
new CharGroup(info.mCharacters, shortcutTargets, bigrams, info.mFrequency,
|
new CharGroup(info.mCharacters, shortcutTargets, bigrams,
|
||||||
|
info.mFrequency,
|
||||||
0 != (info.mFlags & FormatSpec.FLAG_IS_NOT_A_WORD),
|
0 != (info.mFlags & FormatSpec.FLAG_IS_NOT_A_WORD),
|
||||||
0 != (info.mFlags & FormatSpec.FLAG_IS_BLACKLISTED)));
|
0 != (info.mFlags & FormatSpec.FLAG_IS_BLACKLISTED)));
|
||||||
}
|
}
|
||||||
groupOffset = info.mEndAddress;
|
groupOffset = info.mEndAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reach the end of the array.
|
||||||
|
if (options.mHasLinkedListNode) {
|
||||||
|
final int nextAddress = buffer.readUnsignedInt24();
|
||||||
|
if (nextAddress >= 0 && nextAddress < buffer.limit()) {
|
||||||
|
buffer.position(nextAddress);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (options.mHasLinkedListNode &&
|
||||||
|
buffer.position() != FormatSpec.NO_FORWARD_LINK_ADDRESS);
|
||||||
|
|
||||||
final Node node = new Node(nodeContents);
|
final Node node = new Node(nodeContents);
|
||||||
node.mCachedAddress = nodeOrigin;
|
node.mCachedAddress = nodeOrigin;
|
||||||
reverseNodeMap.put(node.mCachedAddress, node);
|
reverseNodeMap.put(node.mCachedAddress, node);
|
||||||
|
|
Loading…
Reference in a new issue