Merge "Move some constants in BinaryDictInputOutput to FormatSpec."
commit
0766f13391
|
@ -39,8 +39,6 @@ import java.util.Stack;
|
||||||
|
|
||||||
public final class BinaryDictIOUtils {
|
public final class BinaryDictIOUtils {
|
||||||
private static final boolean DBG = false;
|
private static final boolean DBG = false;
|
||||||
private static final int MSB24 = 0x800000;
|
|
||||||
private static final int SINT24_MAX = 0x7FFFFF;
|
|
||||||
private static final int MAX_JUMPS = 10000;
|
private static final int MAX_JUMPS = 10000;
|
||||||
|
|
||||||
private BinaryDictIOUtils() {
|
private BinaryDictIOUtils() {
|
||||||
|
@ -921,8 +919,8 @@ public final class BinaryDictIOUtils {
|
||||||
// reached the end of the array.
|
// reached the end of the array.
|
||||||
final int linkAddressPosition = buffer.position();
|
final int linkAddressPosition = buffer.position();
|
||||||
int nextLink = buffer.readUnsignedInt24();
|
int nextLink = buffer.readUnsignedInt24();
|
||||||
if ((nextLink & MSB24) != 0) {
|
if ((nextLink & FormatSpec.MSB24) != 0) {
|
||||||
nextLink = -(nextLink & SINT24_MAX);
|
nextLink = -(nextLink & FormatSpec.SINT24_MAX);
|
||||||
}
|
}
|
||||||
if (nextLink == FormatSpec.NO_FORWARD_LINK_ADDRESS) {
|
if (nextLink == FormatSpec.NO_FORWARD_LINK_ADDRESS) {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -449,10 +449,6 @@ public final class BinaryDictInputOutput {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int UINT8_MAX = 0xFF;
|
|
||||||
private static final int UINT16_MAX = 0xFFFF;
|
|
||||||
private static final int UINT24_MAX = 0xFFFFFF;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute the size, in bytes, that an address will occupy.
|
* Compute the size, in bytes, that an address will occupy.
|
||||||
*
|
*
|
||||||
|
@ -464,22 +460,18 @@ public final class BinaryDictInputOutput {
|
||||||
* @return the byte size.
|
* @return the byte size.
|
||||||
*/
|
*/
|
||||||
static int getByteSize(final int address) {
|
static int getByteSize(final int address) {
|
||||||
assert(address <= UINT24_MAX);
|
assert(address <= FormatSpec.UINT24_MAX);
|
||||||
if (!hasChildrenAddress(address)) {
|
if (!hasChildrenAddress(address)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (Math.abs(address) <= UINT8_MAX) {
|
} else if (Math.abs(address) <= FormatSpec.UINT8_MAX) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (Math.abs(address) <= UINT16_MAX) {
|
} else if (Math.abs(address) <= FormatSpec.UINT16_MAX) {
|
||||||
return 2;
|
return 2;
|
||||||
} else {
|
} else {
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int SINT24_MAX = 0x7FFFFF;
|
|
||||||
private static final int MSB8 = 0x80;
|
|
||||||
private static final int MSB24 = 0x800000;
|
|
||||||
|
|
||||||
// End utility methods.
|
// End utility methods.
|
||||||
|
|
||||||
// This method is responsible for finding a nice ordering of the nodes that favors run-time
|
// This method is responsible for finding a nice ordering of the nodes that favors run-time
|
||||||
|
@ -814,7 +806,8 @@ public final class BinaryDictInputOutput {
|
||||||
buffer[index] = buffer[index + 1] = buffer[index + 2] = 0;
|
buffer[index] = buffer[index + 1] = buffer[index + 2] = 0;
|
||||||
} else {
|
} else {
|
||||||
final int absAddress = Math.abs(address);
|
final int absAddress = Math.abs(address);
|
||||||
buffer[index++] = (byte)((address < 0 ? MSB8 : 0) | (0xFF & (absAddress >> 16)));
|
buffer[index++] =
|
||||||
|
(byte)((address < 0 ? FormatSpec.MSB8 : 0) | (0xFF & (absAddress >> 16)));
|
||||||
buffer[index++] = (byte)(0xFF & (absAddress >> 8));
|
buffer[index++] = (byte)(0xFF & (absAddress >> 8));
|
||||||
buffer[index++] = (byte)(0xFF & absAddress);
|
buffer[index++] = (byte)(0xFF & absAddress);
|
||||||
}
|
}
|
||||||
|
@ -978,8 +971,8 @@ public final class BinaryDictInputOutput {
|
||||||
buffer[index] = buffer[index + 1] = buffer[index + 2] = 0;
|
buffer[index] = buffer[index + 1] = buffer[index + 2] = 0;
|
||||||
} else {
|
} else {
|
||||||
final int absAddress = Math.abs(address);
|
final int absAddress = Math.abs(address);
|
||||||
assert(absAddress <= SINT24_MAX);
|
assert(absAddress <= FormatSpec.SINT24_MAX);
|
||||||
buffer[index] = (byte)((address < 0 ? MSB8 : 0)
|
buffer[index] = (byte)((address < 0 ? FormatSpec.MSB8 : 0)
|
||||||
| ((absAddress >> 16) & 0xFF));
|
| ((absAddress >> 16) & 0xFF));
|
||||||
buffer[index + 1] = (byte)((absAddress >> 8) & 0xFF);
|
buffer[index + 1] = (byte)((absAddress >> 8) & 0xFF);
|
||||||
buffer[index + 2] = (byte)(absAddress & 0xFF);
|
buffer[index + 2] = (byte)(absAddress & 0xFF);
|
||||||
|
@ -1300,8 +1293,8 @@ public final class BinaryDictInputOutput {
|
||||||
if (options.mSupportsDynamicUpdate) {
|
if (options.mSupportsDynamicUpdate) {
|
||||||
final int address = buffer.readUnsignedInt24();
|
final int address = buffer.readUnsignedInt24();
|
||||||
if (address == 0) return FormatSpec.NO_CHILDREN_ADDRESS;
|
if (address == 0) return FormatSpec.NO_CHILDREN_ADDRESS;
|
||||||
if ((address & MSB24) != 0) {
|
if ((address & FormatSpec.MSB24) != 0) {
|
||||||
return -(address & SINT24_MAX);
|
return -(address & FormatSpec.SINT24_MAX);
|
||||||
} else {
|
} else {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
@ -1324,8 +1317,8 @@ public final class BinaryDictInputOutput {
|
||||||
final FormatOptions formatOptions) {
|
final FormatOptions formatOptions) {
|
||||||
if (supportsDynamicUpdate(formatOptions)) {
|
if (supportsDynamicUpdate(formatOptions)) {
|
||||||
final int parentAddress = buffer.readUnsignedInt24();
|
final int parentAddress = buffer.readUnsignedInt24();
|
||||||
final int sign = ((parentAddress & MSB24) != 0) ? -1 : 1;
|
final int sign = ((parentAddress & FormatSpec.MSB24) != 0) ? -1 : 1;
|
||||||
return sign * (parentAddress & SINT24_MAX);
|
return sign * (parentAddress & FormatSpec.SINT24_MAX);
|
||||||
} else {
|
} else {
|
||||||
return FormatSpec.NO_PARENT_ADDRESS;
|
return FormatSpec.NO_PARENT_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,6 +263,13 @@ public final class FormatSpec {
|
||||||
static final int NOT_VALID_WORD = -99;
|
static final int NOT_VALID_WORD = -99;
|
||||||
static final int SIGNED_CHILDREN_ADDRESS_SIZE = 3;
|
static final int SIGNED_CHILDREN_ADDRESS_SIZE = 3;
|
||||||
|
|
||||||
|
static final int UINT8_MAX = 0xFF;
|
||||||
|
static final int UINT16_MAX = 0xFFFF;
|
||||||
|
static final int UINT24_MAX = 0xFFFFFF;
|
||||||
|
static final int SINT24_MAX = 0x7FFFFF;
|
||||||
|
static final int MSB8 = 0x80;
|
||||||
|
static final int MSB24 = 0x800000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options about file format.
|
* Options about file format.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue