TimSort 方法内部调用什么方法?

发布于 2024-11-04 07:47:33 字数 356 浏览 4 评论 0原文

TimSort 是 Java 7 中默认使用的排序算法。

我找到了这个来源,但我不明白要调用哪个方法,因为它们都是私有的。 有人能明白吗?谢谢。

http://cr.openjdk.java.net/~martin/webrevs/openjdk7/timsort/raw_files/new/src/share/classes/java/util/TimSort.java

TimSort is an algorithm that will be used by default in Java 7 for sorting.

I found this source, but I don't understand which method to call since all of them are private.
Can anybody understand? Thank you.

http://cr.openjdk.java.net/~martin/webrevs/openjdk7/timsort/raw_files/new/src/share/classes/java/util/TimSort.java

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Spring初心 2024-11-11 07:47:33

你什么也不叫。

它具有 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 分钟的时间:

结果:

C:\Documents and Settings\glowcoder\My Documents>java SortTest
Time for default: 4094ms
Time for timsort: 3813ms

C:\Documents and Settings\glowcoder\My Documents>

You don't call anything.

It has sort methods that are package private to java.util. You let it call them when you call the Arrays.sort() function or something like it.

This is made clear by the comment:

/*
 * 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) {
    ...
}

Judging by the time of my last comment, this took less than 15 minutes to do:

And the result:

C:\Documents and Settings\glowcoder\My Documents>java SortTest
Time for default: 4094ms
Time for timsort: 3813ms

C:\Documents and Settings\glowcoder\My Documents>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文