我正在查看 TimSort java 代码: 原始来源
特别是 mergeLo 函数的第 676 至 739 行。它(大致)具有以下布局:
outer:
while (true) {
//Code here
break outer; //Code within a few if tests in the loop.
}
//Code here executes somehow.
我很困惑这个函数如何停止运行,因为唯一的break语句转到外部块(然后应该回落到while(true)中,并且没有返回 [注意] :
我的问题是,当我尝试对 184 个或更多元素进行排序时,第 747 行正在执行并抛出异常,并且我想弄清楚如何修复它,任何帮助将不胜感激
这是该函数 。被 Collections.sort 调用在 Android 手机上部署 Java 的方法。
I was looking through the TimSort java code: Original Source
in particular lines 676 to 739 of the mergeLo function. It has (roughly) the following layout:
outer:
while (true) {
//Code here
break outer; //Code within a few if tests in the loop.
}
//Code here executes somehow.
I am confused as to how this function could ever stop running, because the only break statements go to the outer block (which should then fall back into the while(true), and there are no return statements.
My problem is that line 747 is executing and throwing an exception when I try and sort 184 or more elements, and I want to figure out how to fix it, any help would be greatly appreciated.
[Note]: This is the function being called by the collections.sort method for Java deployed on an android phone.
发布评论
评论(4)
标签“outer”只是 while 循环的别名。也就是说,break 语句中断循环,控制流在循环后继续。
相反,Continue Outer 将返回到 while 循环的顶部。
The label 'outer' is just an alias for the while loop. That is, the break statement breaks the loop and the control flow continues after the loop.
In contrast, continue outer would return to the top of the while loop.
outer
实际上标记的是while
循环,而不是它之前的行,因此它在中断后不会重新进入...它不是goto. =)
outer
is actually labeling thewhile
loop, not the line before it, so it won't reenter after breaking... it isn't agoto
. =)break outer;
使您离开while(true)
循环。它不会再回到循环中。您是否将break
与continue
混淆了?break outer;
causes you to leave thewhile(true)
loop. It won't fall back into the loop. Are you confusingbreak
withcontinue
?您应该查看
break
语句的语法< /a>.我认为您正在将
break
语句视为goto
语句。它们是两个不同的东西。带有包含标签的break语句会中断该标签所指向的语句。该链接应该有用。
you should look at the syntax of
break
statements.I think you are thinking of the
break
statement as agoto
statement. They are two different things. The break statement with an included label breaks out of the statement that the label points to.The link should be useful.