68 |
|
map.computeIfAbsent(six, (x) -> null); |
69 |
|
assertFalse(map.containsKey(six)); |
70 |
|
} |
71 |
< |
|
71 |
> |
|
72 |
|
/** |
73 |
|
* computeIfPresent does not replace if the key is already present |
74 |
|
*/ |
380 |
|
elements[i] = i; |
381 |
|
Collections.shuffle(Arrays.asList(elements)); |
382 |
|
Collection<Integer> full = populatedSet(elements); |
383 |
< |
|
383 |
> |
|
384 |
|
assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray()))); |
385 |
|
assertTrue(full.containsAll(Arrays.asList(full.toArray()))); |
386 |
|
assertSame(Object[].class, full.toArray().getClass()); |
431 |
|
Set x = populatedSet(size); |
432 |
|
Set y = serialClone(x); |
433 |
|
|
434 |
< |
assertTrue(x != y); |
434 |
> |
assertNotSame(x, y); |
435 |
|
assertEquals(x.size(), y.size()); |
436 |
|
assertEquals(x.toString(), y.toString()); |
437 |
|
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
439 |
|
assertEquals(y, x); |
440 |
|
} |
441 |
|
|
442 |
– |
|
442 |
|
static final int SIZE = 10000; |
443 |
|
static ConcurrentHashMap<Long, Long> longMap; |
444 |
< |
|
444 |
> |
|
445 |
|
static ConcurrentHashMap<Long, Long> longMap() { |
446 |
|
if (longMap == null) { |
447 |
|
longMap = new ConcurrentHashMap<Long, Long>(SIZE); |
455 |
|
static class AddKeys implements BiFunction<Map.Entry<Long,Long>, Map.Entry<Long,Long>, Map.Entry<Long,Long>> { |
456 |
|
public Map.Entry<Long,Long> apply(Map.Entry<Long,Long> x, Map.Entry<Long,Long> y) { |
457 |
|
return new AbstractMap.SimpleEntry<Long,Long> |
458 |
< |
(Long.valueOf(x.getKey().longValue() + y.getKey().longValue()), |
458 |
> |
(Long.valueOf(x.getKey().longValue() + y.getKey().longValue()), |
459 |
|
Long.valueOf(1L)); |
460 |
|
} |
461 |
|
} |
466 |
|
public void testForEachKeySequentially() { |
467 |
|
LongAdder adder = new LongAdder(); |
468 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
469 |
< |
m.forEachKeySequentially((Long x) -> adder.add(x.longValue())); |
469 |
> |
m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue())); |
470 |
|
assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2); |
471 |
|
} |
472 |
|
|
476 |
|
public void testForEachValueSequentially() { |
477 |
|
LongAdder adder = new LongAdder(); |
478 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
479 |
< |
m.forEachValueSequentially((Long x) -> adder.add(x.longValue())); |
479 |
> |
m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue())); |
480 |
|
assertEquals(adder.sum(), SIZE * (SIZE - 1)); |
481 |
|
} |
482 |
|
|
486 |
|
public void testForEachSequentially() { |
487 |
|
LongAdder adder = new LongAdder(); |
488 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
489 |
< |
m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue())); |
489 |
> |
m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())); |
490 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
491 |
|
} |
492 |
|
|
496 |
|
public void testForEachEntrySequentially() { |
497 |
|
LongAdder adder = new LongAdder(); |
498 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
499 |
< |
m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())); |
499 |
> |
m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())); |
500 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
501 |
|
} |
502 |
|
|
506 |
|
public void testForEachKeyInParallel() { |
507 |
|
LongAdder adder = new LongAdder(); |
508 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
509 |
< |
m.forEachKeyInParallel((Long x) -> adder.add(x.longValue())); |
509 |
> |
m.forEachKey(1L, (Long x) -> adder.add(x.longValue())); |
510 |
|
assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2); |
511 |
|
} |
512 |
|
|
516 |
|
public void testForEachValueInParallel() { |
517 |
|
LongAdder adder = new LongAdder(); |
518 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
519 |
< |
m.forEachValueInParallel((Long x) -> adder.add(x.longValue())); |
519 |
> |
m.forEachValue(1L, (Long x) -> adder.add(x.longValue())); |
520 |
|
assertEquals(adder.sum(), SIZE * (SIZE - 1)); |
521 |
|
} |
522 |
|
|
526 |
|
public void testForEachInParallel() { |
527 |
|
LongAdder adder = new LongAdder(); |
528 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
529 |
< |
m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue())); |
529 |
> |
m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())); |
530 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
531 |
|
} |
532 |
|
|
536 |
|
public void testForEachEntryInParallel() { |
537 |
|
LongAdder adder = new LongAdder(); |
538 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
539 |
< |
m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())); |
539 |
> |
m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())); |
540 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
541 |
|
} |
542 |
|
|
547 |
|
public void testMappedForEachKeySequentially() { |
548 |
|
LongAdder adder = new LongAdder(); |
549 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
550 |
< |
m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()), |
550 |
> |
m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()), |
551 |
|
(Long x) -> adder.add(x.longValue())); |
552 |
|
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2); |
553 |
|
} |
559 |
|
public void testMappedForEachValueSequentially() { |
560 |
|
LongAdder adder = new LongAdder(); |
561 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
562 |
< |
m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()), |
562 |
> |
m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()), |
563 |
|
(Long x) -> adder.add(x.longValue())); |
564 |
|
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1)); |
565 |
|
} |
571 |
|
public void testMappedForEachSequentially() { |
572 |
|
LongAdder adder = new LongAdder(); |
573 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
574 |
< |
m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
574 |
> |
m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
575 |
|
(Long x) -> adder.add(x.longValue())); |
576 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
577 |
|
} |
583 |
|
public void testMappedForEachEntrySequentially() { |
584 |
|
LongAdder adder = new LongAdder(); |
585 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
586 |
< |
m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
586 |
> |
m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
587 |
|
(Long x) -> adder.add(x.longValue())); |
588 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
589 |
|
} |
595 |
|
public void testMappedForEachKeyInParallel() { |
596 |
|
LongAdder adder = new LongAdder(); |
597 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
598 |
< |
m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()), |
598 |
> |
m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()), |
599 |
|
(Long x) -> adder.add(x.longValue())); |
600 |
|
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2); |
601 |
|
} |
607 |
|
public void testMappedForEachValueInParallel() { |
608 |
|
LongAdder adder = new LongAdder(); |
609 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
610 |
< |
m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()), |
610 |
> |
m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()), |
611 |
|
(Long x) -> adder.add(x.longValue())); |
612 |
|
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1)); |
613 |
|
} |
619 |
|
public void testMappedForEachInParallel() { |
620 |
|
LongAdder adder = new LongAdder(); |
621 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
622 |
< |
m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
622 |
> |
m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
623 |
|
(Long x) -> adder.add(x.longValue())); |
624 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
625 |
|
} |
631 |
|
public void testMappedForEachEntryInParallel() { |
632 |
|
LongAdder adder = new LongAdder(); |
633 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
634 |
< |
m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
634 |
> |
m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
635 |
|
(Long x) -> adder.add(x.longValue())); |
636 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
637 |
|
} |
638 |
|
|
640 |
– |
|
639 |
|
/** |
640 |
|
* reduceKeysSequentially accumulates across all keys, |
641 |
|
*/ |
642 |
|
public void testReduceKeysSequentially() { |
643 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
644 |
|
Long r; |
645 |
< |
r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
645 |
> |
r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
646 |
|
assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2); |
647 |
|
} |
648 |
|
|
652 |
|
public void testReduceValuesSequentially() { |
653 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
654 |
|
Long r; |
655 |
< |
r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
655 |
> |
r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
656 |
|
assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2); |
657 |
|
} |
658 |
|
|
661 |
– |
|
659 |
|
/** |
660 |
|
* reduceEntriesSequentially accumulates across all entries |
661 |
|
*/ |
662 |
|
public void testReduceEntriesSequentially() { |
663 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
664 |
|
Map.Entry<Long,Long> r; |
665 |
< |
r = m.reduceEntriesSequentially(new AddKeys()); |
665 |
> |
r = m.reduceEntries(Long.MAX_VALUE, new AddKeys()); |
666 |
|
assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2); |
667 |
|
} |
668 |
|
|
672 |
|
public void testReduceKeysInParallel() { |
673 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
674 |
|
Long r; |
675 |
< |
r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
675 |
> |
r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
676 |
|
assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2); |
677 |
|
} |
678 |
|
|
682 |
|
public void testReduceValuesInParallel() { |
683 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
684 |
|
Long r; |
685 |
< |
r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
685 |
> |
r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
686 |
|
assertEquals((long)r, (long)SIZE * (SIZE - 1)); |
687 |
|
} |
688 |
|
|
692 |
|
public void testReduceEntriesInParallel() { |
693 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
694 |
|
Map.Entry<Long,Long> r; |
695 |
< |
r = m.reduceEntriesInParallel(new AddKeys()); |
695 |
> |
r = m.reduceEntries(1L, new AddKeys()); |
696 |
|
assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2); |
697 |
|
} |
698 |
|
|
699 |
< |
/* |
699 |
> |
/** |
700 |
|
* Mapped reduceKeysSequentially accumulates mapped keys |
701 |
|
*/ |
702 |
|
public void testMapReduceKeysSequentially() { |
703 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
704 |
< |
Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()), |
704 |
> |
Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()), |
705 |
|
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
706 |
|
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2); |
707 |
|
} |
708 |
|
|
709 |
< |
/* |
709 |
> |
/** |
710 |
|
* Mapped reduceValuesSequentially accumulates mapped values |
711 |
|
*/ |
712 |
|
public void testMapReduceValuesSequentially() { |
713 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
714 |
< |
Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()), |
714 |
> |
Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()), |
715 |
|
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
716 |
|
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1)); |
717 |
|
} |
721 |
|
*/ |
722 |
|
public void testMappedReduceSequentially() { |
723 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
724 |
< |
Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
724 |
> |
Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
725 |
|
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
726 |
< |
|
726 |
> |
|
727 |
|
assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2); |
728 |
|
} |
729 |
|
|
730 |
< |
/* |
730 |
> |
/** |
731 |
|
* Mapped reduceKeysInParallel, accumulates mapped keys |
732 |
|
*/ |
733 |
|
public void testMapReduceKeysInParallel() { |
734 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
735 |
< |
Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()), |
735 |
> |
Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()), |
736 |
|
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
737 |
|
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2); |
738 |
|
} |
739 |
|
|
740 |
< |
/* |
740 |
> |
/** |
741 |
|
* Mapped reduceValuesInParallel accumulates mapped values |
742 |
|
*/ |
743 |
|
public void testMapReduceValuesInParallel() { |
744 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
745 |
< |
Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()), |
745 |
> |
Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()), |
746 |
|
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
747 |
|
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1)); |
748 |
|
} |
753 |
|
public void testMappedReduceInParallel() { |
754 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
755 |
|
Long r; |
756 |
< |
r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
756 |
> |
r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
757 |
|
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
758 |
|
assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2); |
759 |
|
} |
760 |
|
|
761 |
< |
|
765 |
< |
/* |
761 |
> |
/** |
762 |
|
* reduceKeysToLongSequentially accumulates mapped keys |
763 |
|
*/ |
764 |
|
public void testReduceKeysToLongSequentially() { |
765 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
766 |
< |
long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum); |
766 |
> |
long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum); |
767 |
|
assertEquals(lr, (long)SIZE * (SIZE - 1) / 2); |
768 |
|
} |
769 |
|
|
770 |
< |
/* |
770 |
> |
/** |
771 |
|
* reduceKeysToIntSequentially accumulates mapped keys |
772 |
|
*/ |
773 |
|
public void testReduceKeysToIntSequentially() { |
774 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
775 |
< |
int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum); |
776 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1) / 2); |
775 |
> |
int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum); |
776 |
> |
assertEquals(ir, SIZE * (SIZE - 1) / 2); |
777 |
|
} |
778 |
|
|
779 |
< |
/* |
779 |
> |
/** |
780 |
|
* reduceKeysToDoubleSequentially accumulates mapped keys |
781 |
|
*/ |
782 |
|
public void testReduceKeysToDoubleSequentially() { |
783 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
784 |
< |
double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum); |
784 |
> |
double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum); |
785 |
|
assertEquals(dr, (double)SIZE * (SIZE - 1) / 2); |
786 |
|
} |
787 |
|
|
788 |
< |
/* |
788 |
> |
/** |
789 |
|
* reduceValuesToLongSequentially accumulates mapped values |
790 |
|
*/ |
791 |
|
public void testReduceValuesToLongSequentially() { |
792 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
793 |
< |
long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum); |
793 |
> |
long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum); |
794 |
|
assertEquals(lr, (long)SIZE * (SIZE - 1)); |
795 |
|
} |
796 |
|
|
797 |
< |
/* |
797 |
> |
/** |
798 |
|
* reduceValuesToIntSequentially accumulates mapped values |
799 |
|
*/ |
800 |
|
public void testReduceValuesToIntSequentially() { |
801 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
802 |
< |
int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum); |
803 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1)); |
802 |
> |
int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum); |
803 |
> |
assertEquals(ir, SIZE * (SIZE - 1)); |
804 |
|
} |
805 |
|
|
806 |
< |
/* |
806 |
> |
/** |
807 |
|
* reduceValuesToDoubleSequentially accumulates mapped values |
808 |
|
*/ |
809 |
|
public void testReduceValuesToDoubleSequentially() { |
810 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
811 |
< |
double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum); |
811 |
> |
double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum); |
812 |
|
assertEquals(dr, (double)SIZE * (SIZE - 1)); |
813 |
|
} |
814 |
|
|
815 |
< |
/* |
815 |
> |
/** |
816 |
|
* reduceKeysToLongInParallel accumulates mapped keys |
817 |
|
*/ |
818 |
|
public void testReduceKeysToLongInParallel() { |
819 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
820 |
< |
long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum); |
820 |
> |
long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum); |
821 |
|
assertEquals(lr, (long)SIZE * (SIZE - 1) / 2); |
822 |
|
} |
823 |
|
|
824 |
< |
/* |
824 |
> |
/** |
825 |
|
* reduceKeysToIntInParallel accumulates mapped keys |
826 |
|
*/ |
827 |
|
public void testReduceKeysToIntInParallel() { |
828 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
829 |
< |
int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum); |
830 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1) / 2); |
829 |
> |
int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum); |
830 |
> |
assertEquals(ir, SIZE * (SIZE - 1) / 2); |
831 |
|
} |
832 |
|
|
833 |
< |
/* |
833 |
> |
/** |
834 |
|
* reduceKeysToDoubleInParallel accumulates mapped values |
835 |
|
*/ |
836 |
|
public void testReduceKeysToDoubleInParallel() { |
837 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
838 |
< |
double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum); |
838 |
> |
double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum); |
839 |
|
assertEquals(dr, (double)SIZE * (SIZE - 1) / 2); |
840 |
|
} |
841 |
|
|
842 |
< |
/* |
842 |
> |
/** |
843 |
|
* reduceValuesToLongInParallel accumulates mapped values |
844 |
|
*/ |
845 |
|
public void testReduceValuesToLongInParallel() { |
846 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
847 |
< |
long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum); |
847 |
> |
long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum); |
848 |
|
assertEquals(lr, (long)SIZE * (SIZE - 1)); |
849 |
|
} |
850 |
|
|
851 |
< |
/* |
851 |
> |
/** |
852 |
|
* reduceValuesToIntInParallel accumulates mapped values |
853 |
|
*/ |
854 |
|
public void testReduceValuesToIntInParallel() { |
855 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
856 |
< |
int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum); |
857 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1)); |
856 |
> |
int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum); |
857 |
> |
assertEquals(ir, SIZE * (SIZE - 1)); |
858 |
|
} |
859 |
|
|
860 |
< |
/* |
860 |
> |
/** |
861 |
|
* reduceValuesToDoubleInParallel accumulates mapped values |
862 |
|
*/ |
863 |
|
public void testReduceValuesToDoubleInParallel() { |
864 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
865 |
< |
double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum); |
865 |
> |
double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum); |
866 |
|
assertEquals(dr, (double)SIZE * (SIZE - 1)); |
867 |
|
} |
868 |
|
|
873 |
|
public void testSearchKeysSequentially() { |
874 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
875 |
|
Long r; |
876 |
< |
r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null); |
876 |
> |
r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null); |
877 |
|
assertEquals((long)r, (long)(SIZE/2)); |
878 |
< |
r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L? x : null); |
878 |
> |
r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null); |
879 |
|
assertNull(r); |
880 |
|
} |
881 |
|
|
886 |
|
public void testSearchValuesSequentially() { |
887 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
888 |
|
Long r; |
889 |
< |
r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null); |
889 |
> |
r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null); |
890 |
|
assertEquals((long)r, (long)(SIZE/2)); |
891 |
< |
r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L? x : null); |
891 |
> |
r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null); |
892 |
|
assertNull(r); |
893 |
|
} |
894 |
|
|
899 |
|
public void testSearchSequentially() { |
900 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
901 |
|
Long r; |
902 |
< |
r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null); |
902 |
> |
r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null); |
903 |
|
assertEquals((long)r, (long)(SIZE/2)); |
904 |
< |
r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L? x : null); |
904 |
> |
r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null); |
905 |
|
assertNull(r); |
906 |
|
} |
907 |
|
|
912 |
|
public void testSearchEntriesSequentially() { |
913 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
914 |
|
Long r; |
915 |
< |
r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null); |
915 |
> |
r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null); |
916 |
|
assertEquals((long)r, (long)(SIZE/2)); |
917 |
< |
r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L? e.getKey() : null); |
917 |
> |
r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null); |
918 |
|
assertNull(r); |
919 |
|
} |
920 |
|
|
925 |
|
public void testSearchKeysInParallel() { |
926 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
927 |
|
Long r; |
928 |
< |
r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2)? x : null); |
928 |
> |
r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null); |
929 |
|
assertEquals((long)r, (long)(SIZE/2)); |
930 |
< |
r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L? x : null); |
930 |
> |
r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null); |
931 |
|
assertNull(r); |
932 |
|
} |
933 |
|
|
938 |
|
public void testSearchValuesInParallel() { |
939 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
940 |
|
Long r; |
941 |
< |
r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2)? x : null); |
941 |
> |
r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null); |
942 |
|
assertEquals((long)r, (long)(SIZE/2)); |
943 |
< |
r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L? x : null); |
943 |
> |
r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null); |
944 |
|
assertNull(r); |
945 |
|
} |
946 |
|
|
951 |
|
public void testSearchInParallel() { |
952 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
953 |
|
Long r; |
954 |
< |
r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null); |
954 |
> |
r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null); |
955 |
|
assertEquals((long)r, (long)(SIZE/2)); |
956 |
< |
r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L? x : null); |
956 |
> |
r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null); |
957 |
|
assertNull(r); |
958 |
|
} |
959 |
|
|
964 |
|
public void testSearchEntriesInParallel() { |
965 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
966 |
|
Long r; |
967 |
< |
r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null); |
967 |
> |
r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null); |
968 |
|
assertEquals((long)r, (long)(SIZE/2)); |
969 |
< |
r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L? e.getKey() : null); |
969 |
> |
r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null); |
970 |
|
assertNull(r); |
971 |
|
} |
972 |
|
|
977 |
– |
/** |
978 |
– |
* Invoking task versions of bulk methods has same effect as |
979 |
– |
* parallel methods |
980 |
– |
*/ |
981 |
– |
public void testForkJoinTasks() { |
982 |
– |
LongAdder adder = new LongAdder(); |
983 |
– |
ConcurrentHashMap<Long, Long> m = longMap(); |
984 |
– |
ConcurrentHashMap.ForkJoinTasks.forEachKey |
985 |
– |
(m, (Long x) -> adder.add(x.longValue())).invoke(); |
986 |
– |
assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2); |
987 |
– |
adder.reset(); |
988 |
– |
ConcurrentHashMap.ForkJoinTasks.forEachValue |
989 |
– |
(m, (Long x) -> adder.add(x.longValue())).invoke(); |
990 |
– |
assertEquals(adder.sum(), SIZE * (SIZE - 1)); |
991 |
– |
adder.reset(); |
992 |
– |
ConcurrentHashMap.ForkJoinTasks.forEach |
993 |
– |
(m, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())).invoke(); |
994 |
– |
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
995 |
– |
adder.reset(); |
996 |
– |
ConcurrentHashMap.ForkJoinTasks.forEachEntry |
997 |
– |
(m, |
998 |
– |
(Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())).invoke(); |
999 |
– |
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
1000 |
– |
adder.reset(); |
1001 |
– |
ConcurrentHashMap.ForkJoinTasks.forEachKey |
1002 |
– |
(m, (Long x) -> Long.valueOf(4 * x.longValue()), |
1003 |
– |
(Long x) -> adder.add(x.longValue())).invoke(); |
1004 |
– |
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2); |
1005 |
– |
adder.reset(); |
1006 |
– |
ConcurrentHashMap.ForkJoinTasks.forEachValue |
1007 |
– |
(m, (Long x) -> Long.valueOf(4 * x.longValue()), |
1008 |
– |
(Long x) -> adder.add(x.longValue())).invoke(); |
1009 |
– |
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1)); |
1010 |
– |
adder.reset(); |
1011 |
– |
ConcurrentHashMap.ForkJoinTasks.forEach |
1012 |
– |
(m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
1013 |
– |
(Long x) -> adder.add(x.longValue())).invoke(); |
1014 |
– |
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
1015 |
– |
adder.reset(); |
1016 |
– |
ConcurrentHashMap.ForkJoinTasks.forEachEntry |
1017 |
– |
(m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
1018 |
– |
(Long x) -> adder.add(x.longValue())).invoke(); |
1019 |
– |
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
1020 |
– |
adder.reset(); |
1021 |
– |
|
1022 |
– |
Long r; long lr; int ir; double dr; |
1023 |
– |
r = ConcurrentHashMap.ForkJoinTasks.reduceKeys |
1024 |
– |
(m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
1025 |
– |
assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2); |
1026 |
– |
r = ConcurrentHashMap.ForkJoinTasks.reduceValues |
1027 |
– |
(m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
1028 |
– |
assertEquals((long)r, (long)SIZE * (SIZE - 1)); |
1029 |
– |
r = ConcurrentHashMap.ForkJoinTasks.reduce |
1030 |
– |
(m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
1031 |
– |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
1032 |
– |
assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2); |
1033 |
– |
r = ConcurrentHashMap.ForkJoinTasks.reduceEntries |
1034 |
– |
(m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
1035 |
– |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
1036 |
– |
assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2); |
1037 |
– |
r = ConcurrentHashMap.ForkJoinTasks.reduceKeys |
1038 |
– |
(m, (Long x) -> Long.valueOf(4 * x.longValue()), |
1039 |
– |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
1040 |
– |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2); |
1041 |
– |
lr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToLong |
1042 |
– |
(m, (Long x) -> x.longValue(), 0L, Long::sum).invoke(); |
1043 |
– |
assertEquals(lr, (long)SIZE * (SIZE - 1) / 2); |
1044 |
– |
ir = ConcurrentHashMap.ForkJoinTasks.reduceKeysToInt |
1045 |
– |
(m, (Long x) -> x.intValue(), 0, Integer::sum).invoke(); |
1046 |
– |
assertEquals(ir, (int)SIZE * (SIZE - 1) / 2); |
1047 |
– |
dr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToDouble |
1048 |
– |
(m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke(); |
1049 |
– |
assertEquals(dr, (double)SIZE * (SIZE - 1) / 2); |
1050 |
– |
r = ConcurrentHashMap.ForkJoinTasks.reduceValues |
1051 |
– |
(m, (Long x) -> Long.valueOf(4 * x.longValue()), |
1052 |
– |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
1053 |
– |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1)); |
1054 |
– |
lr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToLong |
1055 |
– |
(m, (Long x) -> x.longValue(), 0L, Long::sum).invoke(); |
1056 |
– |
assertEquals(lr, (long)SIZE * (SIZE - 1)); |
1057 |
– |
ir = ConcurrentHashMap.ForkJoinTasks.reduceValuesToInt |
1058 |
– |
(m, (Long x) -> x.intValue(), 0, Integer::sum).invoke(); |
1059 |
– |
assertEquals(ir, (int)SIZE * (SIZE - 1)); |
1060 |
– |
dr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToDouble |
1061 |
– |
(m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke(); |
1062 |
– |
assertEquals(dr, (double)SIZE * (SIZE - 1)); |
1063 |
– |
r = ConcurrentHashMap.ForkJoinTasks.searchKeys |
1064 |
– |
(m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke(); |
1065 |
– |
assertEquals((long)r, (long)(SIZE/2)); |
1066 |
– |
r = ConcurrentHashMap.ForkJoinTasks.searchValues |
1067 |
– |
(m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke(); |
1068 |
– |
assertEquals((long)r, (long)(SIZE/2)); |
1069 |
– |
r = ConcurrentHashMap.ForkJoinTasks.search |
1070 |
– |
(m, (Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null).invoke(); |
1071 |
– |
assertEquals((long)r, (long)(SIZE/2)); |
1072 |
– |
r = ConcurrentHashMap.ForkJoinTasks.searchEntries |
1073 |
– |
(m, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null).invoke(); |
1074 |
– |
assertEquals((long)r, (long)(SIZE/2)); |
1075 |
– |
} |
973 |
|
} |