parent
7223cc2ef1
commit
a853356b82
|
@ -95,7 +95,9 @@ public final class BinaryDictIOUtils {
|
||||||
|
|
||||||
final boolean isMovedGroup = BinaryDictInputOutput.isMovedGroup(info.mFlags,
|
final boolean isMovedGroup = BinaryDictInputOutput.isMovedGroup(info.mFlags,
|
||||||
formatOptions);
|
formatOptions);
|
||||||
if (!isMovedGroup
|
final boolean isDeletedGroup = BinaryDictInputOutput.isDeletedGroup(info.mFlags,
|
||||||
|
formatOptions);
|
||||||
|
if (!isMovedGroup && !isDeletedGroup
|
||||||
&& info.mFrequency != FusionDictionary.CharGroup.NOT_A_TERMINAL) {// found word
|
&& info.mFrequency != FusionDictionary.CharGroup.NOT_A_TERMINAL) {// found word
|
||||||
words.put(info.mOriginalAddress, new String(pushedChars, 0, index));
|
words.put(info.mOriginalAddress, new String(pushedChars, 0, index));
|
||||||
frequencies.put(info.mOriginalAddress, info.mFrequency);
|
frequencies.put(info.mOriginalAddress, info.mFrequency);
|
||||||
|
@ -179,10 +181,13 @@ public final class BinaryDictIOUtils {
|
||||||
final int charGroupPos = buffer.position();
|
final int charGroupPos = buffer.position();
|
||||||
final CharGroupInfo currentInfo = BinaryDictInputOutput.readCharGroup(buffer,
|
final CharGroupInfo currentInfo = BinaryDictInputOutput.readCharGroup(buffer,
|
||||||
buffer.position(), header.mFormatOptions);
|
buffer.position(), header.mFormatOptions);
|
||||||
if (BinaryDictInputOutput.isMovedGroup(currentInfo.mFlags,
|
final boolean isMovedGroup =
|
||||||
header.mFormatOptions)) {
|
BinaryDictInputOutput.isMovedGroup(currentInfo.mFlags,
|
||||||
continue;
|
header.mFormatOptions);
|
||||||
}
|
final boolean isDeletedGroup =
|
||||||
|
BinaryDictInputOutput.isDeletedGroup(currentInfo.mFlags,
|
||||||
|
header.mFormatOptions);
|
||||||
|
if (isMovedGroup) continue;
|
||||||
boolean same = true;
|
boolean same = true;
|
||||||
for (int p = 0, j = word.offsetByCodePoints(0, wordPos);
|
for (int p = 0, j = word.offsetByCodePoints(0, wordPos);
|
||||||
p < currentInfo.mCharacters.length;
|
p < currentInfo.mCharacters.length;
|
||||||
|
@ -197,7 +202,8 @@ public final class BinaryDictIOUtils {
|
||||||
if (same) {
|
if (same) {
|
||||||
// found the group matches the word.
|
// 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
|
||||||
|
|| isDeletedGroup) {
|
||||||
return FormatSpec.NOT_VALID_WORD;
|
return FormatSpec.NOT_VALID_WORD;
|
||||||
} else {
|
} else {
|
||||||
return charGroupPos;
|
return charGroupPos;
|
||||||
|
@ -233,6 +239,10 @@ public final class BinaryDictIOUtils {
|
||||||
return FormatSpec.NOT_VALID_WORD;
|
return FormatSpec.NOT_VALID_WORD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int markAsDeleted(final int flags) {
|
||||||
|
return (flags & (~FormatSpec.MASK_GROUP_ADDRESS_TYPE)) | FormatSpec.FLAG_IS_DELETED;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the word from the binary file.
|
* Delete the word from the binary file.
|
||||||
*
|
*
|
||||||
|
@ -250,9 +260,8 @@ public final class BinaryDictIOUtils {
|
||||||
|
|
||||||
buffer.position(wordPosition);
|
buffer.position(wordPosition);
|
||||||
final int flags = buffer.readUnsignedByte();
|
final int flags = buffer.readUnsignedByte();
|
||||||
final int newFlags = flags ^ FormatSpec.FLAG_IS_TERMINAL;
|
|
||||||
buffer.position(wordPosition);
|
buffer.position(wordPosition);
|
||||||
buffer.put((byte)newFlags);
|
buffer.put((byte)markAsDeleted(flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -302,7 +311,7 @@ public final class BinaryDictIOUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a parent address in a CharGroup that is addressed by groupOriginAddress.
|
* Update a parent address in a CharGroup that is referred to by groupOriginAddress.
|
||||||
*
|
*
|
||||||
* @param buffer the buffer to write.
|
* @param buffer the buffer to write.
|
||||||
* @param groupOriginAddress the address of the group.
|
* @param groupOriginAddress the address of the group.
|
||||||
|
@ -380,7 +389,7 @@ public final class BinaryDictIOUtils {
|
||||||
final int flags = buffer.readUnsignedByte();
|
final int flags = buffer.readUnsignedByte();
|
||||||
final int parentAddress = BinaryDictInputOutput.readParentAddress(buffer, formatOptions);
|
final int parentAddress = BinaryDictInputOutput.readParentAddress(buffer, formatOptions);
|
||||||
skipString(buffer, (flags & FormatSpec.FLAG_HAS_MULTIPLE_CHARS) != 0);
|
skipString(buffer, (flags & FormatSpec.FLAG_HAS_MULTIPLE_CHARS) != 0);
|
||||||
if ((FormatSpec.FLAG_IS_TERMINAL) != 0) buffer.readUnsignedByte();
|
if ((flags & FormatSpec.FLAG_IS_TERMINAL) != 0) buffer.readUnsignedByte();
|
||||||
final int childrenOffset = newChildrenAddress == FormatSpec.NO_CHILDREN_ADDRESS
|
final int childrenOffset = newChildrenAddress == FormatSpec.NO_CHILDREN_ADDRESS
|
||||||
? FormatSpec.NO_CHILDREN_ADDRESS : newChildrenAddress - buffer.position();
|
? FormatSpec.NO_CHILDREN_ADDRESS : newChildrenAddress - buffer.position();
|
||||||
writeSInt24ToBuffer(buffer, childrenOffset);
|
writeSInt24ToBuffer(buffer, childrenOffset);
|
||||||
|
|
|
@ -401,6 +401,14 @@ public final class BinaryDictInputOutput {
|
||||||
return options.mSupportsDynamicUpdate && ((flags & FormatSpec.FLAG_IS_MOVED) == 1);
|
return options.mSupportsDynamicUpdate && ((flags & FormatSpec.FLAG_IS_MOVED) == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to check whether the group is deleted.
|
||||||
|
*/
|
||||||
|
public static boolean isDeletedGroup(final int flags, final FormatOptions formatOptions) {
|
||||||
|
return formatOptions.mSupportsDynamicUpdate
|
||||||
|
&& ((flags & FormatSpec.MASK_GROUP_ADDRESS_TYPE) == FormatSpec.FLAG_IS_DELETED);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to check whether the dictionary can be updated dynamically.
|
* Helper method to check whether the dictionary can be updated dynamically.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -63,6 +63,7 @@ public final class FormatSpec {
|
||||||
* | This must be the same as FLAG_GROUP_ADDRESS_TYPE_THREEBYTES
|
* | This must be the same as FLAG_GROUP_ADDRESS_TYPE_THREEBYTES
|
||||||
* | 01 = yes : FLAG_IS_MOVED
|
* | 01 = yes : FLAG_IS_MOVED
|
||||||
* | the new address is stored in the same place as the parent address
|
* | the new address is stored in the same place as the parent address
|
||||||
|
* | is deleted? 10 = yes : FLAG_IS_DELETED
|
||||||
* | has several chars ? 1 bit, 1 = yes, 0 = no : FLAG_HAS_MULTIPLE_CHARS
|
* | has several chars ? 1 bit, 1 = yes, 0 = no : FLAG_HAS_MULTIPLE_CHARS
|
||||||
* | has a terminal ? 1 bit, 1 = yes, 0 = no : FLAG_IS_TERMINAL
|
* | has a terminal ? 1 bit, 1 = yes, 0 = no : FLAG_IS_TERMINAL
|
||||||
* | has shortcut targets ? 1 bit, 1 = yes, 0 = no : FLAG_HAS_SHORTCUT_TARGETS
|
* | has shortcut targets ? 1 bit, 1 = yes, 0 = no : FLAG_HAS_SHORTCUT_TARGETS
|
||||||
|
@ -190,6 +191,7 @@ public final class FormatSpec {
|
||||||
static final int FIXED_BIT_OF_DYNAMIC_UPDATE_MOVE = 0x40;
|
static final int FIXED_BIT_OF_DYNAMIC_UPDATE_MOVE = 0x40;
|
||||||
static final int FLAG_IS_MOVED = 0x00 | FIXED_BIT_OF_DYNAMIC_UPDATE_MOVE;
|
static final int FLAG_IS_MOVED = 0x00 | FIXED_BIT_OF_DYNAMIC_UPDATE_MOVE;
|
||||||
static final int FLAG_IS_NOT_MOVED = 0x80 | FIXED_BIT_OF_DYNAMIC_UPDATE_MOVE;
|
static final int FLAG_IS_NOT_MOVED = 0x80 | FIXED_BIT_OF_DYNAMIC_UPDATE_MOVE;
|
||||||
|
static final int FLAG_IS_DELETED = 0x80;
|
||||||
|
|
||||||
static final int FLAG_ATTRIBUTE_HAS_NEXT = 0x80;
|
static final int FLAG_ATTRIBUTE_HAS_NEXT = 0x80;
|
||||||
static final int FLAG_ATTRIBUTE_OFFSET_NEGATIVE = 0x40;
|
static final int FLAG_ATTRIBUTE_OFFSET_NEGATIVE = 0x40;
|
||||||
|
|
Loading…
Reference in New Issue