POV-Ray : Newsgroups : povray.off-topic : Ratatouille : Re: Ratatouille Server Time
11 Oct 2024 01:24:35 EDT (-0400)
  Re: Ratatouille  
From: Nicolas Alvarez
Date: 27 Mar 2008 12:01:11
Message: <47ebd2d7$1@news.povray.org>

> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.