[concurrency-interest] ParallelArray.binarySearch

Hanson Char hanson.char at gmail.com
Sun Feb 3 01:26:46 EST 2008


1) Why the implementation of the 2
AbstractParallelAnyArray.binarySearch methods don't just simply invoke
the corresponding static methods in Arrays.binarySearch, which
essentially executes the same code, except with a seemingly
inconsistent behavior of returning different value when the target
element is not found ?

AbstractParallelAnyArray.binarySearch returns -1 if the target element
is not present, whereas Arrays.binarySearch returns (-(insertion
point) - 1).

In other words, why not:

          // Inside AbstractParallelAnyArray
          public int binarySearch(T target) {
            return Arrays.binarySearch(array, origin, fence-1, target);

        public int binarySearch(T target, Comparator<? super T> comparator) {
            return Arrays.binarySearch(array, origin, fence-1, comparator);

2) Why the 2 binarySearch methods need to be redefined in
ParallelArray, when they are already defined in the base class
AbstractParallelAnyArray, and all ParrallelArray does is simply invoke
the super.binarySearch ?


More information about the Concurrency-interest mailing list