TimSortメソッド内でどのような方法を呼び出しますか?
質問
TimSortは、ソートにJava 7でデフォルトで使用されるアルゴリズムです。
私はこのソースを見つけましたが、それらのすべてがプライベートであるため、どの方法を呼び出すかわかりません。誰かが理解できますか?ありがとうございました。
解決
あなたは何も呼びません。
プライベートでパッケージのソートメソッドがあります java.util
. 。あなたが電話するときにそれを呼び起こさせます Arrays.sort()
機能かそのようなもの。
これはコメントによって明らかにされています:
/*
* The next two methods (which are package private and static) constitute
* the entire API of this class. Each of these methods obeys the contract
* of the public method with the same signature in java.util.Arrays.
*/
static <T> void sort(T[] a, Comparator<? super T> c) {
sort(a, 0, a.length, c);
}
static <T> void sort(T[] a, int lo, int hi, Comparator<? super T> c) {
...
}
私の最後のコメントの時代から判断すると、これには15分もかかりませんでした。
- http://pastebin.com/vnyuutid -SORTTEST.java
- http://pastebin.com/degafwzj -timsort.java
そして結果:
C:\Documents and Settings\glowcoder\My Documents>java SortTest
Time for default: 4094ms
Time for timsort: 3813ms
C:\Documents and Settings\glowcoder\My Documents>
所属していません StackOverflow