|
|
> A stand astounded. I can't *begin* to imagine what they were thinking.
> The only explanation I can come up with is that the document is
> incorrect and the actual implementation does something sane. Just... wow.
>
Did you know Java is open-source nowadays?
(this is from Collections.java)
public static <T extends Comparable<? super T>> void sort(List<T> list) {
Object[] a = list.toArray();
Arrays.sort(a);
ListIterator<T> i = list.listIterator();
for (int j=0; j<a.length; j++) {
i.next();
i.set((T)a[j]);
}
}
That's the magic inside. Note it's converted into an array without first
checking what kind of list it is (even an ArrayList would suffer this
unneeded copying!).
Arrays.sort then uses clone() on the array, making yet another copy.
Apparently that's needed for the actual implementation.
(Arrays.java)
public static void sort(Object[] a) {
Object[] aux = (Object[])a.clone();
mergeSort(aux, a, 0, a.length, 0);
}
mergeSort signature is:
private static void mergeSort(Object[] src, Object[] dest,
int low, int high, int off)
Post a reply to this message
|
|