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 |
|
} |
153 |
|
++sum; |
154 |
|
} |
155 |
|
timer.finish(); |
156 |
< |
reallyAssert (sum == expect); |
156 |
> |
reallyAssert(sum == expect); |
157 |
|
checkSum += sum; |
158 |
|
} |
159 |
|
|
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); |
170 |
> |
reallyAssert(sum == expect); |
171 |
|
} |
172 |
|
|
173 |
|
static void remTest(String nm, int n, Map s, Object[] key, int expect) { |
177 |
|
if (s.remove(key[i]) != null) ++sum; |
178 |
|
} |
179 |
|
timer.finish(); |
180 |
< |
reallyAssert (sum == expect); |
180 |
> |
reallyAssert(sum == expect); |
181 |
|
checkSum += sum; |
182 |
|
} |
183 |
|
|
186 |
|
timer.start(nm, n); |
187 |
|
s.clear(); |
188 |
|
timer.finish(); |
189 |
< |
reallyAssert (s.isEmpty()); |
189 |
> |
reallyAssert(s.isEmpty()); |
190 |
|
} |
191 |
|
|
192 |
|
static void putTest(String nm, int n, Map s, Object[] key, int expect) { |
198 |
|
if (v == null) ++sum; |
199 |
|
} |
200 |
|
timer.finish(); |
201 |
< |
reallyAssert (sum == expect); |
201 |
> |
reallyAssert(sum == expect); |
202 |
|
checkSum += sum; |
203 |
|
} |
204 |
|
|
209 |
|
if (s.containsKey(key[i])) ++sum; |
210 |
|
} |
211 |
|
timer.finish(); |
212 |
< |
reallyAssert (sum == expect); |
212 |
> |
reallyAssert(sum == expect); |
213 |
|
checkSum += sum; |
214 |
|
} |
215 |
|
|
219 |
|
for (int i = 0; i < n; i++) { |
220 |
|
if (s.containsKey(key[i])) ++sum; |
221 |
|
} |
222 |
< |
reallyAssert (sum == expect); |
222 |
> |
reallyAssert(sum == expect); |
223 |
|
checkSum += sum; |
224 |
|
} |
225 |
|
|
230 |
|
if (s.remove(key[i]) != null) ++sum; |
231 |
|
} |
232 |
|
timer.finish(); |
233 |
< |
reallyAssert (sum == expect); |
233 |
> |
reallyAssert(sum == expect); |
234 |
|
checkSum += sum; |
235 |
|
} |
236 |
|
|
240 |
|
timer.start("Traverse key or value ", size); |
241 |
|
if (s.containsValue(MISSING)) ++sum; |
242 |
|
timer.finish(); |
243 |
< |
reallyAssert (sum == 0); |
243 |
> |
reallyAssert(sum == 0); |
244 |
|
checkSum += sum; |
245 |
|
} |
246 |
|
|
256 |
|
last = x; |
257 |
|
} |
258 |
|
timer.finish(); |
259 |
< |
reallyAssert (sum == size); |
259 |
> |
reallyAssert(sum == size); |
260 |
|
checkSum += sum; |
261 |
|
return last; |
262 |
|
} |
272 |
|
last = x; |
273 |
|
} |
274 |
|
timer.finish(); |
275 |
< |
reallyAssert (sum == size); |
275 |
> |
reallyAssert(sum == size); |
276 |
|
checkSum += sum; |
277 |
|
return last; |
278 |
|
} |
289 |
|
++sum; |
290 |
|
} |
291 |
|
timer.finish(); |
292 |
< |
reallyAssert (sum == size); |
292 |
> |
reallyAssert(sum == size); |
293 |
|
checkSum += sum; |
294 |
|
} |
295 |
|
|
296 |
|
static void itRemTest(Map s, int size) { |
297 |
|
int sz = s.size(); |
298 |
< |
reallyAssert (sz == size); |
298 |
> |
reallyAssert(sz == size); |
299 |
|
timer.start("Remove Present ", size); |
300 |
|
int sum = 0; |
301 |
|
for (Iterator it = s.keySet().iterator(); it.hasNext(); ) { |
304 |
|
++sum; |
305 |
|
} |
306 |
|
timer.finish(); |
307 |
< |
reallyAssert (sum == sz); |
307 |
> |
reallyAssert(sum == sz); |
308 |
|
checkSum += sum; |
309 |
|
} |
310 |
|
|
311 |
|
static void itHalfRemTest(Map s, int size) { |
312 |
|
int sz = s.size(); |
313 |
< |
reallyAssert (sz == size); |
313 |
> |
reallyAssert(sz == size); |
314 |
|
timer.start("Remove Present ", size); |
315 |
|
int sum = 0; |
316 |
|
for (Iterator it = s.keySet().iterator(); it.hasNext(); ) { |
321 |
|
++sum; |
322 |
|
} |
323 |
|
timer.finish(); |
324 |
< |
reallyAssert (sum == sz / 2); |
324 |
> |
reallyAssert(sum == sz / 2); |
325 |
|
checkSum += sum; |
326 |
|
} |
327 |
|
|
329 |
|
timer.start(nm, n); |
330 |
|
dst.putAll(src); |
331 |
|
timer.finish(); |
332 |
< |
reallyAssert (src.size() == dst.size()); |
332 |
> |
reallyAssert(src.size() == dst.size()); |
333 |
|
} |
334 |
|
|
335 |
|
static void serTest(Map s, int size) throws Exception { |
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; |
358 |
|
System.out.print(time + "ms"); |
359 |
|
|
360 |
|
if (s instanceof IdentityHashMap) return; |
361 |
< |
reallyAssert (s.equals(m)); |
361 |
> |
reallyAssert(s.equals(m)); |
362 |
|
} |
363 |
|
|
364 |
|
static void mainTest(Map s, Object[] key, Object[] absent) { |
426 |
|
timer.start("Traverse entry ", size * 12); // 12 until finish |
427 |
|
|
428 |
|
int sh1 = s.hashCode() - s2.hashCode(); |
429 |
< |
reallyAssert (sh1 == 0); |
429 |
> |
reallyAssert(sh1 == 0); |
430 |
|
|
431 |
|
boolean eq1 = s2.equals(s); |
432 |
|
boolean eq2 = s.equals(s2); |
433 |
< |
reallyAssert (eq1 && eq2); |
433 |
> |
reallyAssert(eq1 && eq2); |
434 |
|
|
435 |
|
Set es2 = s2.entrySet(); |
436 |
|
for (Iterator it = s.entrySet().iterator(); it.hasNext(); ) { |
437 |
|
Object entry = it.next(); |
438 |
|
if (es2.contains(entry)) ++sum; |
439 |
|
} |
440 |
< |
reallyAssert (sum == size); |
440 |
> |
reallyAssert(sum == size); |
441 |
|
|
442 |
|
s2.put(lastkey, MISSING); |
443 |
|
|
444 |
|
int sh2 = s.hashCode() - s2.hashCode(); |
445 |
< |
reallyAssert (sh2 != 0); |
445 |
> |
reallyAssert(sh2 != 0); |
446 |
|
|
447 |
|
eq1 = s2.equals(s); |
448 |
|
eq2 = s.equals(s2); |
449 |
< |
reallyAssert (!eq1 && !eq2); |
449 |
> |
reallyAssert(!eq1 && !eq2); |
450 |
|
|
451 |
|
sum = 0; |
452 |
|
for (Iterator it = s.entrySet().iterator(); it.hasNext(); ) { |
453 |
|
Map.Entry e = (Map.Entry)it.next(); |
454 |
|
e.setValue(absent[sum++]); |
455 |
|
} |
456 |
< |
reallyAssert (sum == size); |
456 |
> |
reallyAssert(sum == size); |
457 |
|
for (Iterator it = s2.entrySet().iterator(); it.hasNext(); ) { |
458 |
|
Map.Entry e = (Map.Entry)it.next(); |
459 |
|
e.setValue(s.get(e.getKey())); |
473 |
|
reallyAssert(rmiss == 0); |
474 |
|
|
475 |
|
clrTest(size, s2); |
476 |
< |
reallyAssert (s2.isEmpty() && s.isEmpty()); |
476 |
> |
reallyAssert(s2.isEmpty() && s.isEmpty()); |
477 |
|
} |
478 |
|
|
479 |
|
static void itTest4(Map s, int size, int pos) { |
480 |
|
IdentityHashMap seen = new IdentityHashMap(size); |
481 |
< |
reallyAssert (s.size() == size); |
481 |
> |
reallyAssert(s.size() == size); |
482 |
|
int sum = 0; |
483 |
|
timer.start("Iter XEntry ", size); |
484 |
|
Iterator it = s.entrySet().iterator(); |
492 |
|
if (x != MISSING) |
493 |
|
++sum; |
494 |
|
} |
495 |
< |
reallyAssert (s.containsKey(k)); |
495 |
> |
reallyAssert(s.containsKey(k)); |
496 |
|
it.remove(); |
497 |
< |
reallyAssert (!s.containsKey(k)); |
497 |
> |
reallyAssert(!s.containsKey(k)); |
498 |
|
while (it.hasNext()) { |
499 |
|
Map.Entry x = (Map.Entry)(it.next()); |
500 |
|
Object k2 = x.getKey(); |
503 |
|
++sum; |
504 |
|
} |
505 |
|
|
506 |
< |
reallyAssert (s.size() == size-1); |
506 |
> |
reallyAssert(s.size() == size-1); |
507 |
|
s.put(k, v); |
508 |
< |
reallyAssert (seen.size() == size); |
508 |
> |
reallyAssert(seen.size() == size); |
509 |
|
timer.finish(); |
510 |
< |
reallyAssert (sum == size); |
511 |
< |
reallyAssert (s.size() == size); |
510 |
> |
reallyAssert(sum == size); |
511 |
> |
reallyAssert(s.size() == size); |
512 |
|
} |
513 |
|
|
514 |
|
|
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 |
|
} |