am 72c870f5: am 596a565a: Merge "Remove some unused variables."

* commit '72c870f5e67c0b332b8bf0b394796c28b53f61a7':
  Remove some unused variables.
main
Ken Wakasa 2013-10-09 17:55:02 -07:00 committed by Android Git Automerger
commit aa3ae615d2
9 changed files with 25 additions and 41 deletions

View File

@ -295,7 +295,6 @@ public final class BinaryDictDecoderUtils {
return address; return address;
} }
} }
int address;
switch (optionFlags & FormatSpec.MASK_CHILDREN_ADDRESS_TYPE) { switch (optionFlags & FormatSpec.MASK_CHILDREN_ADDRESS_TYPE) {
case FormatSpec.FLAG_CHILDREN_ADDRESS_TYPE_ONEBYTE: case FormatSpec.FLAG_CHILDREN_ADDRESS_TYPE_ONEBYTE:
return dictBuffer.readUnsignedByte(); return dictBuffer.readUnsignedByte();

View File

@ -278,7 +278,6 @@ public class BinaryDictEncoderUtils {
// For future reference, the code to remove duplicate is a simple : list.remove(node); // For future reference, the code to remove duplicate is a simple : list.remove(node);
list.add(ptNodeArray); list.add(ptNodeArray);
final ArrayList<PtNode> branches = ptNodeArray.mData; final ArrayList<PtNode> branches = ptNodeArray.mData;
final int nodeSize = branches.size();
for (PtNode ptNode : branches) { for (PtNode ptNode : branches) {
if (null != ptNode.mChildren) flattenTreeInner(list, ptNode.mChildren); if (null != ptNode.mChildren) flattenTreeInner(list, ptNode.mChildren);
} }
@ -427,9 +426,6 @@ public class BinaryDictEncoderUtils {
nodeCountSize + nodeArrayOffset + nodeffset; nodeCountSize + nodeArrayOffset + nodeffset;
nodeffset += ptNode.mCachedSize; nodeffset += ptNode.mCachedSize;
} }
final int nodeSize = nodeCountSize + nodeffset
+ (formatOptions.mSupportsDynamicUpdate
? FormatSpec.FORWARD_LINK_ADDRESS_SIZE : 0);
nodeArrayOffset += nodeArray.mCachedSize; nodeArrayOffset += nodeArray.mCachedSize;
} }
return nodeArrayOffset; return nodeArrayOffset;
@ -653,8 +649,8 @@ public class BinaryDictEncoderUtils {
return flags; return flags;
} }
/* package */ static byte makePtNodeFlags(final PtNode node, final int ptNodeAddress, /* package */ static byte makePtNodeFlags(final PtNode node, final int childrenOffset,
final int childrenOffset, final FormatOptions formatOptions) { final FormatOptions formatOptions) {
return (byte) makePtNodeFlags(node.mChars.length > 1, node.mFrequency >= 0, return (byte) makePtNodeFlags(node.mChars.length > 1, node.mFrequency >= 0,
getByteSize(childrenOffset), getByteSize(childrenOffset),
node.mShortcutTargets != null && !node.mShortcutTargets.isEmpty(), node.mShortcutTargets != null && !node.mShortcutTargets.isEmpty(),

View File

@ -59,7 +59,7 @@ public final class DynamicBinaryDictIOUtils {
throws IOException, UnsupportedFormatException { throws IOException, UnsupportedFormatException {
final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); final DictBuffer dictBuffer = dictDecoder.getDictBuffer();
dictBuffer.position(0); dictBuffer.position(0);
final FileHeader header = dictDecoder.readHeader(); dictDecoder.readHeader();
final int wordPosition = dictDecoder.getTerminalPosition(word); final int wordPosition = dictDecoder.getTerminalPosition(word);
if (wordPosition == FormatSpec.NOT_VALID_WORD) return; if (wordPosition == FormatSpec.NOT_VALID_WORD) return;
@ -142,8 +142,7 @@ public final class DynamicBinaryDictIOUtils {
final int originalPosition = dictBuffer.position(); final int originalPosition = dictBuffer.position();
dictBuffer.position(ptNodeOriginAddress); dictBuffer.position(ptNodeOriginAddress);
final int flags = dictBuffer.readUnsignedByte(); final int flags = dictBuffer.readUnsignedByte();
final int parentAddress = BinaryDictDecoderUtils.readParentAddress(dictBuffer, BinaryDictDecoderUtils.readParentAddress(dictBuffer, formatOptions);
formatOptions);
BinaryDictIOUtils.skipString(dictBuffer, (flags & FormatSpec.FLAG_HAS_MULTIPLE_CHARS) != 0); BinaryDictIOUtils.skipString(dictBuffer, (flags & FormatSpec.FLAG_HAS_MULTIPLE_CHARS) != 0);
if ((flags & FormatSpec.FLAG_IS_TERMINAL) != 0) dictBuffer.readUnsignedByte(); if ((flags & FormatSpec.FLAG_IS_TERMINAL) != 0) dictBuffer.readUnsignedByte();
final int childrenOffset = newChildrenAddress == FormatSpec.NO_CHILDREN_ADDRESS final int childrenOffset = newChildrenAddress == FormatSpec.NO_CHILDREN_ADDRESS

View File

@ -212,7 +212,6 @@ public class SparseTable {
@UsedForTesting @UsedForTesting
public static SparseTable readFromFiles(final File lookupTableFile, final File[] contentFiles, public static SparseTable readFromFiles(final File lookupTableFile, final File[] contentFiles,
final int blockSize) throws IOException { final int blockSize) throws IOException {
final byte[] lookupTable = readFileToByteArray(lookupTableFile);
final ArrayList<ArrayList<Integer>> contentTables = final ArrayList<ArrayList<Integer>> contentTables =
new ArrayList<ArrayList<Integer>>(contentFiles.length); new ArrayList<ArrayList<Integer>>(contentFiles.length);
for (int i = 0; i < contentFiles.length; ++i) { for (int i = 0; i < contentFiles.length; ++i) {

View File

@ -133,12 +133,10 @@ public class Ver3DictEncoder implements DictEncoder {
countSize); countSize);
} }
private void writePtNodeFlags(final PtNode ptNode, final int parentAddress, private void writePtNodeFlags(final PtNode ptNode, final FormatOptions formatOptions) {
final FormatOptions formatOptions) {
final int childrenPos = BinaryDictEncoderUtils.getChildrenPosition(ptNode, formatOptions); final int childrenPos = BinaryDictEncoderUtils.getChildrenPosition(ptNode, formatOptions);
mPosition = BinaryDictEncoderUtils.writeUIntToBuffer(mBuffer, mPosition, mPosition = BinaryDictEncoderUtils.writeUIntToBuffer(mBuffer, mPosition,
BinaryDictEncoderUtils.makePtNodeFlags(ptNode, mPosition, childrenPos, BinaryDictEncoderUtils.makePtNodeFlags(ptNode, childrenPos, formatOptions),
formatOptions),
FormatSpec.PTNODE_FLAGS_SIZE); FormatSpec.PTNODE_FLAGS_SIZE);
} }
@ -244,7 +242,7 @@ public class Ver3DictEncoder implements DictEncoder {
@Override @Override
public void writePtNode(final PtNode ptNode, final int parentPosition, public void writePtNode(final PtNode ptNode, final int parentPosition,
final FormatOptions formatOptions, final FusionDictionary dict) { final FormatOptions formatOptions, final FusionDictionary dict) {
writePtNodeFlags(ptNode, parentPosition, formatOptions); writePtNodeFlags(ptNode, formatOptions);
writeParentPosition(parentPosition, ptNode, formatOptions); writeParentPosition(parentPosition, ptNode, formatOptions);
writeCharacters(ptNode.mChars, ptNode.hasSeveralChars()); writeCharacters(ptNode.mChars, ptNode.hasSeveralChars());
writeFrequency(ptNode.mFrequency); writeFrequency(ptNode.mFrequency);

View File

@ -95,7 +95,6 @@ public class Ver4DictDecoder extends DictDecoder {
@Override @Override
public void openDictBuffer() throws FileNotFoundException, IOException { public void openDictBuffer() throws FileNotFoundException, IOException {
final String filename = mDictDirectory.getName();
mDictBuffer = mBufferFactory.getDictionaryBuffer(getFile(FILETYPE_TRIE)); mDictBuffer = mBufferFactory.getDictionaryBuffer(getFile(FILETYPE_TRIE));
mFrequencyBuffer = mBufferFactory.getDictionaryBuffer(getFile(FILETYPE_FREQUENCY)); mFrequencyBuffer = mBufferFactory.getDictionaryBuffer(getFile(FILETYPE_FREQUENCY));
mTerminalAddressTableBuffer = mBufferFactory.getDictionaryBuffer( mTerminalAddressTableBuffer = mBufferFactory.getDictionaryBuffer(

View File

@ -181,12 +181,10 @@ public class Ver4DictEncoder implements DictEncoder {
countSize); countSize);
} }
private void writePtNodeFlags(final PtNode ptNode, final int parentAddress, private void writePtNodeFlags(final PtNode ptNode, final FormatOptions formatOptions) {
final FormatOptions formatOptions) {
final int childrenPos = BinaryDictEncoderUtils.getChildrenPosition(ptNode, formatOptions); final int childrenPos = BinaryDictEncoderUtils.getChildrenPosition(ptNode, formatOptions);
mTriePos = BinaryDictEncoderUtils.writeUIntToBuffer(mTrieBuf, mTriePos, mTriePos = BinaryDictEncoderUtils.writeUIntToBuffer(mTrieBuf, mTriePos,
BinaryDictEncoderUtils.makePtNodeFlags(ptNode, mTriePos, childrenPos, BinaryDictEncoderUtils.makePtNodeFlags(ptNode, childrenPos, formatOptions),
formatOptions),
FormatSpec.PTNODE_FLAGS_SIZE); FormatSpec.PTNODE_FLAGS_SIZE);
} }
@ -292,7 +290,7 @@ public class Ver4DictEncoder implements DictEncoder {
@Override @Override
public void writePtNode(final PtNode ptNode, final int parentPosition, public void writePtNode(final PtNode ptNode, final int parentPosition,
final FormatOptions formatOptions, final FusionDictionary dict) { final FormatOptions formatOptions, final FusionDictionary dict) {
writePtNodeFlags(ptNode, parentPosition, formatOptions); writePtNodeFlags(ptNode, formatOptions);
writeParentPosition(parentPosition, ptNode, formatOptions); writeParentPosition(parentPosition, ptNode, formatOptions);
writeCharacters(ptNode.mChars, ptNode.hasSeveralChars()); writeCharacters(ptNode.mChars, ptNode.hasSeveralChars());
if (ptNode.isTerminal()) { if (ptNode.isTerminal()) {

View File

@ -546,8 +546,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
} }
private long checkGetTerminalPosition(final DictDecoder dictDecoder, final String word, private long checkGetTerminalPosition(final DictDecoder dictDecoder, final String word,
int index, boolean contained) { final boolean contained) {
final int expectedFrequency = (UNIGRAM_FREQ + index) % 255;
long diff = -1; long diff = -1;
int position = -1; int position = -1;
try { try {
@ -605,7 +604,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
// Test a word that is contained within the dictionary. // Test a word that is contained within the dictionary.
long sum = 0; long sum = 0;
for (int i = 0; i < sWords.size(); ++i) { for (int i = 0; i < sWords.size(); ++i) {
final long time = checkGetTerminalPosition(dictDecoder, sWords.get(i), i, true); final long time = checkGetTerminalPosition(dictDecoder, sWords.get(i), true);
sum += time == -1 ? 0 : time; sum += time == -1 ? 0 : time;
} }
Log.d(TAG, "per search : " + (((double)sum) / sWords.size() / 1000000) + " : " + message Log.d(TAG, "per search : " + (((double)sum) / sWords.size() / 1000000) + " : " + message
@ -618,11 +617,11 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 1000; ++i) {
final String word = CodePointUtils.generateWord(random, codePointSet); final String word = CodePointUtils.generateWord(random, codePointSet);
if (sWords.indexOf(word) != -1) continue; if (sWords.indexOf(word) != -1) continue;
checkGetTerminalPosition(dictDecoder, word, i, false); checkGetTerminalPosition(dictDecoder, word, false);
} }
} }
private void runGetTerminalPositionTests(final ArrayList<String> results, final int bufferType, private void runGetTerminalPositionTests(final int bufferType,
final FormatOptions formatOptions) { final FormatOptions formatOptions) {
runGetTerminalPosition(sWords, sEmptyBigrams, bufferType, formatOptions, "unigram"); runGetTerminalPosition(sWords, sEmptyBigrams, bufferType, formatOptions, "unigram");
} }
@ -630,17 +629,17 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
public void testGetTerminalPosition() { public void testGetTerminalPosition() {
final ArrayList<String> results = CollectionUtils.newArrayList(); final ArrayList<String> results = CollectionUtils.newArrayList();
runGetTerminalPositionTests(results, USE_BYTE_ARRAY, VERSION2); runGetTerminalPositionTests(USE_BYTE_ARRAY, VERSION2);
runGetTerminalPositionTests(results, USE_BYTE_ARRAY, VERSION3_WITHOUT_DYNAMIC_UPDATE); runGetTerminalPositionTests(USE_BYTE_ARRAY, VERSION3_WITHOUT_DYNAMIC_UPDATE);
runGetTerminalPositionTests(results, USE_BYTE_ARRAY, VERSION3_WITH_DYNAMIC_UPDATE); runGetTerminalPositionTests(USE_BYTE_ARRAY, VERSION3_WITH_DYNAMIC_UPDATE);
runGetTerminalPositionTests(results, USE_BYTE_ARRAY, VERSION4_WITHOUT_DYNAMIC_UPDATE); runGetTerminalPositionTests(USE_BYTE_ARRAY, VERSION4_WITHOUT_DYNAMIC_UPDATE);
runGetTerminalPositionTests(results, USE_BYTE_ARRAY, VERSION4_WITH_DYNAMIC_UPDATE); runGetTerminalPositionTests(USE_BYTE_ARRAY, VERSION4_WITH_DYNAMIC_UPDATE);
runGetTerminalPositionTests(results, USE_BYTE_BUFFER, VERSION2); runGetTerminalPositionTests(USE_BYTE_BUFFER, VERSION2);
runGetTerminalPositionTests(results, USE_BYTE_BUFFER, VERSION3_WITHOUT_DYNAMIC_UPDATE); runGetTerminalPositionTests(USE_BYTE_BUFFER, VERSION3_WITHOUT_DYNAMIC_UPDATE);
runGetTerminalPositionTests(results, USE_BYTE_BUFFER, VERSION3_WITH_DYNAMIC_UPDATE); runGetTerminalPositionTests(USE_BYTE_BUFFER, VERSION3_WITH_DYNAMIC_UPDATE);
runGetTerminalPositionTests(results, USE_BYTE_BUFFER, VERSION4_WITHOUT_DYNAMIC_UPDATE); runGetTerminalPositionTests(USE_BYTE_BUFFER, VERSION4_WITHOUT_DYNAMIC_UPDATE);
runGetTerminalPositionTests(results, USE_BYTE_BUFFER, VERSION4_WITH_DYNAMIC_UPDATE); runGetTerminalPositionTests(USE_BYTE_BUFFER, VERSION4_WITH_DYNAMIC_UPDATE);
for (final String result : results) { for (final String result : results) {
Log.d(TAG, result); Log.d(TAG, result);

View File

@ -23,7 +23,6 @@ import android.util.Log;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
@ -69,7 +68,7 @@ public class SparseTableTests extends AndroidTestCase {
} }
private void generateRandomIndex(final int size, final int prop) { private void generateRandomIndex(final int size, final int prop) {
for (int i = 0; i < DEFAULT_SIZE; ++i) { for (int i = 0; i < size; ++i) {
if (mRandom.nextInt(100) < prop) { if (mRandom.nextInt(100) < prop) {
mRandomIndex.set(i, mRandom.nextInt()); mRandomIndex.set(i, mRandom.nextInt());
} else { } else {
@ -98,8 +97,6 @@ public class SparseTableTests extends AndroidTestCase {
// flush and reload // flush and reload
OutputStream lookupOutStream = null; OutputStream lookupOutStream = null;
OutputStream contentOutStream = null; OutputStream contentOutStream = null;
InputStream lookupInStream = null;
InputStream contentInStream = null;
try { try {
final File lookupIndexFile = File.createTempFile("testRandomSet", ".small"); final File lookupIndexFile = File.createTempFile("testRandomSet", ".small");
final File contentFile = File.createTempFile("testRandomSet", ".big"); final File contentFile = File.createTempFile("testRandomSet", ".big");