Merge "Make getTerminalPosition read linked-list nodes." into jb-mr1-dev

main
Jean Chalard 2012-09-25 05:39:23 -07:00 committed by Android (Google) Code Review
commit 35ffb90629
1 changed files with 50 additions and 34 deletions

View File

@ -157,10 +157,13 @@ public class BinaryDictIOUtils {
final int wordLen = word.codePointCount(0, word.length()); final int wordLen = word.codePointCount(0, word.length());
for (int depth = 0; depth < Constants.Dictionary.MAX_WORD_LENGTH; ++depth) { for (int depth = 0; depth < Constants.Dictionary.MAX_WORD_LENGTH; ++depth) {
if (wordPos >= wordLen) return FormatSpec.NOT_VALID_WORD; if (wordPos >= wordLen) return FormatSpec.NOT_VALID_WORD;
do {
int groupOffset = buffer.position() - header.mHeaderSize; int groupOffset = buffer.position() - header.mHeaderSize;
final int charGroupCount = BinaryDictInputOutput.readCharGroupCount(buffer); final int charGroupCount = BinaryDictInputOutput.readCharGroupCount(buffer);
groupOffset += BinaryDictInputOutput.getGroupCountSize(charGroupCount); groupOffset += BinaryDictInputOutput.getGroupCountSize(charGroupCount);
boolean foundNextCharGroup = false;
for (int i = 0; i < charGroupCount; ++i) { for (int i = 0; i < charGroupCount; ++i) {
final int charGroupPos = buffer.position(); final int charGroupPos = buffer.position();
final CharGroupInfo currentInfo = BinaryDictInputOutput.readCharGroup(buffer, final CharGroupInfo currentInfo = BinaryDictInputOutput.readCharGroup(buffer,
@ -177,6 +180,7 @@ public class BinaryDictIOUtils {
} }
if (same) { if (same) {
// found the group matches the word.
if (wordPos + currentInfo.mCharacters.length == wordLen) { if (wordPos + currentInfo.mCharacters.length == wordLen) {
if (currentInfo.mFrequency == CharGroup.NOT_A_TERMINAL) { if (currentInfo.mFrequency == CharGroup.NOT_A_TERMINAL) {
return FormatSpec.NOT_VALID_WORD; return FormatSpec.NOT_VALID_WORD;
@ -188,16 +192,28 @@ public class BinaryDictIOUtils {
if (currentInfo.mChildrenAddress == FormatSpec.NO_CHILDREN_ADDRESS) { if (currentInfo.mChildrenAddress == FormatSpec.NO_CHILDREN_ADDRESS) {
return FormatSpec.NOT_VALID_WORD; return FormatSpec.NOT_VALID_WORD;
} }
foundNextCharGroup = true;
buffer.position(currentInfo.mChildrenAddress); buffer.position(currentInfo.mChildrenAddress);
break; break;
} }
groupOffset = currentInfo.mEndAddress; groupOffset = currentInfo.mEndAddress;
}
// not found // If we found the next char group, it is under the file pointer.
if (i >= charGroupCount - 1) { // But if not, we are at the end of this node so we expect to have
// a forward link address that we need to consult and possibly resume
// search on the next node in the linked list.
if (foundNextCharGroup) break;
if (!header.mFormatOptions.mSupportsDynamicUpdate) {
return FormatSpec.NOT_VALID_WORD; return FormatSpec.NOT_VALID_WORD;
} }
final int forwardLinkAddress = buffer.readUnsignedInt24();
if (forwardLinkAddress == FormatSpec.NO_FORWARD_LINK_ADDRESS) {
return FormatSpec.NOT_VALID_WORD;
} }
buffer.position(forwardLinkAddress);
} while(true);
} }
return FormatSpec.NOT_VALID_WORD; return FormatSpec.NOT_VALID_WORD;
} }