9 |
|
* |
10 |
|
* When run with "s" second arg, this requires file "testwords", which |
11 |
|
* is best used with real words. We can't check in this file, but you |
12 |
< |
* can create one from a real dictonary (1 line per word) and then run |
12 |
> |
* can create one from a real dictionary (1 line per word) and then run |
13 |
|
* linux "shuf" to randomize entries. |
14 |
|
*/ |
15 |
|
import java.util.*; |
40 |
|
if (args.length > 0) { |
41 |
|
try { |
42 |
|
mapClass = Class.forName(args[0]); |
43 |
< |
} catch(ClassNotFoundException e) { |
43 |
> |
} catch (ClassNotFoundException e) { |
44 |
|
throw new RuntimeException("Class " + args[0] + " not found."); |
45 |
|
} |
46 |
|
} |
99 |
|
|
100 |
|
static Map newMap() { |
101 |
|
try { |
102 |
< |
return (Map)mapClass.newInstance(); |
103 |
< |
} catch(Exception e) { |
102 |
> |
return (Map) mapClass.newInstance(); |
103 |
> |
} catch (Exception e) { |
104 |
|
throw new RuntimeException("Can't instantiate " + mapClass + ": " + e); |
105 |
|
} |
106 |
|
} |
134 |
|
try { |
135 |
|
m.put(null, x); |
136 |
|
v = m.get(null); |
137 |
< |
} catch(NullPointerException npe) { |
137 |
> |
} catch (NullPointerException npe) { |
138 |
|
System.out.println("Map does not allow null keys"); |
139 |
|
return; |
140 |
|
} |
164 |
|
Map<Integer,Integer> intMap = (Map<Integer,Integer>)s; |
165 |
|
timer.start(nm, n); |
166 |
|
for (int i = 0; i < n; i++) { |
167 |
< |
if ((Integer)(intMap.get(i)) != i) ++sum; |
167 |
> |
if (intMap.get(i) != i) ++sum; |
168 |
|
} |
169 |
|
timer.finish(); |
170 |
|
reallyAssert (sum == expect); |
350 |
|
|
351 |
|
FileInputStream is = new FileInputStream("MapCheck.dat"); |
352 |
|
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(is)); |
353 |
< |
Map m = (Map)in.readObject(); |
353 |
> |
Map m = (Map) in.readObject(); |
354 |
|
|
355 |
|
long endTime = System.currentTimeMillis(); |
356 |
|
long time = endTime - startTime; |
610 |
|
abs[ai++] = s; |
611 |
|
break; |
612 |
|
} |
613 |
< |
sb.append((char)c); |
613 |
> |
sb.append((char) c); |
614 |
|
} |
615 |
|
} |
616 |
|
in.close(); |
629 |
|
char[] c = new char[len * 4 + 1]; |
630 |
|
for (int j = 1; j < len; ++j) { |
631 |
|
int r = srng.next(); |
632 |
< |
c[k++] = (char)(' ' + (r & 0x7f)); |
632 |
> |
c[k++] = (char) (' ' + (r & 0x7f)); |
633 |
|
r >>>= 8; |
634 |
< |
c[k++] = (char)(' ' + (r & 0x7f)); |
634 |
> |
c[k++] = (char) (' ' + (r & 0x7f)); |
635 |
|
r >>>= 8; |
636 |
< |
c[k++] = (char)(' ' + (r & 0x7f)); |
636 |
> |
c[k++] = (char) (' ' + (r & 0x7f)); |
637 |
|
r >>>= 8; |
638 |
< |
c[k++] = (char)(' ' + (r & 0x7f)); |
638 |
> |
c[k++] = (char) (' ' + (r & 0x7f)); |
639 |
|
} |
640 |
< |
c[k++] = (char)((i & 31) | 1); // never == to any testword |
640 |
> |
c[k++] = (char) ((i & 31) | 1); // never == to any testword |
641 |
|
ws[i] = new String(c); |
642 |
|
} |
643 |
|
} |
651 |
|
|
652 |
|
static void printStats() { |
653 |
|
for (Iterator it = accum.entrySet().iterator(); it.hasNext(); ) { |
654 |
< |
Map.Entry e = (Map.Entry)(it.next()); |
655 |
< |
Stats stats = ((Stats)(e.getValue())); |
654 |
> |
Map.Entry e = (Map.Entry) it.next(); |
655 |
> |
Stats stats = (Stats) e.getValue(); |
656 |
|
System.out.print(e.getKey() + ": "); |
657 |
|
long s; |
658 |
|
long n = stats.number; |
663 |
|
else |
664 |
|
s = stats.sum; |
665 |
|
|
666 |
< |
double t = ((double)s) / n; |
666 |
> |
double t = ((double) s) / n; |
667 |
|
long nano = Math.round(t); |
668 |
|
System.out.printf("%6d", + nano); |
669 |
|
System.out.println(); |
682 |
|
if (st == null) |
683 |
|
accum.put(name, new Stats(elapsed, numOps)); |
684 |
|
else |
685 |
< |
((Stats)st).addTime(elapsed, numOps); |
685 |
> |
((Stats) st).addTime(elapsed, numOps); |
686 |
|
} |
687 |
|
|
688 |
|
} |