ICU-8167 check exhaustive mode

X-SVN-Rev: 29340
This commit is contained in:
Mark Davis 2011-01-20 01:55:51 +00:00
parent 4a71f08a6f
commit 5bbf7c685b
2 changed files with 53 additions and 59 deletions

View file

@ -31,7 +31,7 @@ import com.ibm.icu.impl.Utility;
public abstract class TrieMap<V> implements Iterable<Entry<CharSequence,V>>{
public enum Style {BYTES, CHARS}
private static final boolean DEBUG = true;
@ -48,7 +48,7 @@ public abstract class TrieMap<V> implements Iterable<Entry<CharSequence,V>>{
public int keyByteSize() {
return size;
}
public static abstract class Builder<V> {
protected List<V> intToValueTemp = new ArrayList<V>();
protected Map<V, Integer> valueToIntegerTemp = new HashMap<V, Integer>();
@ -114,25 +114,25 @@ public abstract class TrieMap<V> implements Iterable<Entry<CharSequence,V>>{
result = limit == 1 ? bytesTrie.next(bytes[0]) : bytesTrie.next(bytes, 0, limit);
}
return result.hasValue() ? intToValue[bytesTrie.getValue()] : null;
// int length = test.length();
// if (length == 0) {
// return null;
// }
// bytesTrie.reset();
// Result result = null;
// byte[] bytes = new byte[3];
// for (int i = 0; i < length; ++i) {
// char c = test.charAt(i);
// int limit = ByteConverter.getBytes(c, bytes, 0);
// for (int j = 0; j < limit; ++j) {
// result = bytesTrie.next(bytes[j]&0xFF);
// if (!result.matches()) {
// return null;
// }
// }
// }
// return result.hasValue() ? intToValue[bytesTrie.getValue()] : null;
// int length = test.length();
// if (length == 0) {
// return null;
// }
// bytesTrie.reset();
// Result result = null;
// byte[] bytes = new byte[3];
// for (int i = 0; i < length; ++i) {
// char c = test.charAt(i);
// int limit = ByteConverter.getBytes(c, bytes, 0);
// for (int j = 0; j < limit; ++j) {
// result = bytesTrie.next(bytes[j]&0xFF);
// if (!result.matches()) {
// return null;
// }
// }
// }
// return result.hasValue() ? intToValue[bytesTrie.getValue()] : null;
}
public String toString() {
@ -307,7 +307,7 @@ public abstract class TrieMap<V> implements Iterable<Entry<CharSequence,V>>{
return new BytesTrieMap<V>(bytesTrie, intToValueArray, size);
}
}
private static class CharsTrieMap<V> extends TrieMap<V> {
private final CharsTrie charsTrie;
@ -315,26 +315,10 @@ public abstract class TrieMap<V> implements Iterable<Entry<CharSequence,V>>{
super(intToValue, size);
this.charsTrie = charsTrie;
}
public V get(CharSequence test) {
Result result = charsTrie.reset().next(test, 0, test.length());
return result.hasValue() ? intToValue[charsTrie.getValue()] : null;
// int length = test.length();
// if (length == 0) {
// return null;
// }
// charsTrie.reset();
// Result result = null;
// byte[] bytes = new byte[3];
// for (int i = 0; i < length; ++i) {
// char c = test.charAt(i);
// result = charsTrie.next(c);
// if (!result.matches()) {
// return null;
// }
// }
// return result.hasValue() ? intToValue[charsTrie.getValue()] : null;
Result result = charsTrie.reset().next(test, 0, test.length());
return result.hasValue() ? intToValue[charsTrie.getValue()] : null;
}
public String toString() {
@ -415,13 +399,13 @@ public abstract class TrieMap<V> implements Iterable<Entry<CharSequence,V>>{
while (current < text.length()) {
char c = text.charAt(current++);
Result result = charsTrie.next(c);
if (result.hasValue()) {
value = intToValue[charsTrie.getValue()];
return result.hasNext();
} else if (!result.matches()) {
value = null;
return false;
if (result.hasValue()) {
value = intToValue[charsTrie.getValue()];
return result.hasNext();
} else if (!result.matches()) {
value = null;
return false;
}
}
value = null;
@ -485,7 +469,7 @@ public abstract class TrieMap<V> implements Iterable<Entry<CharSequence,V>>{
return new CharsTrieMap<V>(charsTrie, intToValueArray, size);
}
}
/**
* Supports the following format for encoding chars (Unicode 16-bit code units). The format is slightly simpler and more compact than UTF8, but also maintains ordering. It is not, however
@ -589,7 +573,7 @@ public abstract class TrieMap<V> implements Iterable<Entry<CharSequence,V>>{
}
return buffer.toString();
}
public static String toString(CharsTrie bytesTrie2, String keyValueSeparator, String itemSeparator) {
StringBuilder buffer = new StringBuilder();
CharsTrie.Iterator iterator = bytesTrie2.iterator();

View file

@ -32,15 +32,20 @@ import com.ibm.icu.util.ULocale;
public class TrieMapTest extends TestFmwk {
static final boolean SHORT = false;
static final int REPEAT = SHORT ? 1000000 : 10;
static final boolean HACK_TO_MAKE_TESTS_PASS = false;
static final int MASK = 0x3;
Map<String, Integer> unicodeTestMap = new HashMap<String, Integer>();
boolean useSmallList = true;
int REPEAT = 10;
@Override
protected void init() throws Exception {
super.init();
if (unicodeTestMap.size() == 0) {
useSmallList = getInclusion() < 5;
int i = 0;
UnicodeSet testSet = new UnicodeSet("[[:^C:]-[:sc=han:]]");
for (String s : testSet) {
@ -49,9 +54,9 @@ public class TrieMapTest extends TestFmwk {
if (!unicodeTestMap.containsKey(extendedName)) {
unicodeTestMap.put(extendedName, i++);
}
if (SHORT) break;
if (i > 500 && useSmallList) break;
}
ULocale[] locales = SHORT ? new ULocale[] {new ULocale("zh"), new ULocale("el")} : ULocale.getAvailableLocales();
ULocale[] locales = useSmallList ? new ULocale[] {new ULocale("zh"), new ULocale("el")} : ULocale.getAvailableLocales();
for (ULocale locale : locales) {
if (locale.getDisplayCountry().length() != 0) {
continue;
@ -61,7 +66,7 @@ public class TrieMapTest extends TestFmwk {
localeName = ULocale.getDisplayName(languageCode, locale);
if (!localeName.equals(languageCode)) {
if (!unicodeTestMap.containsKey(localeName)) {
unicodeTestMap.put(localeName, i++);
unicodeTestMap.put(localeName, MASK & i++);
}
if (SHORT) break;
}
@ -70,7 +75,7 @@ public class TrieMapTest extends TestFmwk {
localeName = ULocale.getDisplayCountry("und-" + countryCode, locale);
if (!localeName.equals(countryCode)) {
if (!unicodeTestMap.containsKey(localeName)) {
unicodeTestMap.put(localeName, i++);
unicodeTestMap.put(localeName, MASK & i++);
}
if (SHORT) break;
}
@ -80,6 +85,11 @@ public class TrieMapTest extends TestFmwk {
for (String key : unicodeTestMap.keySet()) {
charCount += key.length();
}
if (useSmallList) {
logln("\tSmall version:\t to get more accurate figures and test for reasonable times, use -e 5 or more");
} else {
REPEAT *= (getInclusion() - 5);
}
logln("\tTest Data Elements:\t\t\t" + nf.format(unicodeTestMap.size()));
logln("\tTotal chars:\t\t\t" + nf.format(charCount));
}
@ -159,7 +169,7 @@ public class TrieMapTest extends TestFmwk {
}
long trieTime = t.getDuration();
logln("\titeration time\t" + style + "\tn/a\t" + t.toString(REPEAT*testMap.size(), comparisonTime));
if (trieTime > ratioToMap * comparisonTime) {
if (!useSmallList && trieTime > ratioToMap * comparisonTime) {
errln(style + "\tTime iteration takes too long. Expected:\t< " + ratioToMap * comparisonTime + ", Actual:\t" + trieTime);
}
return trieTime;
@ -277,7 +287,7 @@ public class TrieMapTest extends TestFmwk {
}
long trieTime = t.getDuration();
logln("\tbuild time\t" + style + "\t" + option + "\t" + t.toString(REPEAT*testmap.size(), comparisonTime));
if (trieTime > ratioToMap * comparisonTime) {
if (!useSmallList && trieTime > ratioToMap * comparisonTime) {
errln(style + "\t" + option + "\tTrie build takes too long. Expected:\t< " + nf.format(ratioToMap * comparisonTime) + ", Actual:\t" + nf.format(trieTime));
}
return trieTime;
@ -313,7 +323,7 @@ public class TrieMapTest extends TestFmwk {
logln("\tkey byte size\t" + style + "\t" + option + "\t" + nf.format(trieKeyByteSize) + "\t\t" + pf.format(trieKeyByteSize/(double)comparisonSize - 1D) + "");
if (trieKeyByteSize > ratioToMap * comparisonSize) {
if (!useSmallList && trieKeyByteSize > ratioToMap * comparisonSize) {
errln(style + "\t" + option + "\ttrieKeyByteSize too large. Expected:\t< " + nf.format(ratioToMap * comparisonSize) + ", Actual:\t" + nf.format(trieKeyByteSize));
}
return trieKeyByteSize;
@ -387,7 +397,7 @@ public class TrieMapTest extends TestFmwk {
}
long trieTime = t.getDuration();
logln("\tget() time\t" + style + "\tn/a\t" + t.toString(REPEAT*testmap.size(), comparisonTime));
if (trieTime > ratioToMap * comparisonTime) {
if (!useSmallList && trieTime > ratioToMap * comparisonTime) {
errln(style + "\tTime iteration takes too long. Expected:\t< " + ratioToMap * comparisonTime + ", Actual:\t" + trieTime);
}
return trieTime;