ghedeon
10/11/2018, 2:21 PMIntArray.binarySearch
but that's only for ascending. Arrays.binarySearch
allows you to specify the comparator but only for the Array<T>
, not for the IntArray
. Seems like a dead end.Egor Trutenko
10/11/2018, 2:35 PMIntArray.binarySearch
internally calls Arrays.binarySearch
defined for int[]
anyways. Either you sort your array explicitly, or you box your values and call Arrays.binarySearch
for Array<T>
with comparatorghedeon
10/11/2018, 2:44 PMIntArray
. Can't think of blockers here.Array<T>
copy? That also looks redundant. Idk, it's a first time when I see that Array<Int>
could be a better choice and I'm confused why.Ruckus
10/11/2018, 2:48 PMhudsonb
10/11/2018, 2:50 PMarr.toList().asReversed().binarySearch(...)
avoids the N reversing costghedeon
10/11/2018, 2:53 PMasReversed()
, the nr.2 still apply, thohudsonb
10/11/2018, 2:55 PMghedeon
10/11/2018, 2:56 PMArrays
for other caseshudsonb
10/11/2018, 3:07 PMarr.asList().binarySearch(n, Comparator { o1, o2 -> o2 - o1 })
ghedeon
10/11/2018, 3:11 PMtoTypedArray()
. Thank you!hudsonb
10/11/2018, 3:13 PMfun IntArray.binarySearch(element: Int, comparator: Comparator<Int>)
= asList().binarySearch(8, comparator)
element
not 8
ghedeon
10/11/2018, 3:25 PMComparisons.reverseOrder()
to make it cleaner. 😉hudsonb
10/11/2018, 3:50 PMDico
10/11/2018, 4:07 PMIntComparator
which is Java's comparator for primitive ints.