Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
79f359f9
提交
79f359f9
authored
12月 22, 2011
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Javadocs.
上级
1e9a21cf
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
34 行增加
和
28 行删除
+34
-28
TestSort.java
h2/src/test/org/h2/test/unit/TestSort.java
+15
-9
InPlaceStableMergeSort.java
h2/src/tools/org/h2/dev/sort/InPlaceStableMergeSort.java
+15
-15
InPlaceStableQuicksort.java
h2/src/tools/org/h2/dev/sort/InPlaceStableQuicksort.java
+4
-4
没有找到文件。
h2/src/test/org/h2/test/unit/TestSort.java
浏览文件 @
79f359f9
...
...
@@ -19,8 +19,14 @@ import org.h2.test.TestBase;
*/
public
class
TestSort
extends
TestBase
{
/**
* The number of times the compare method was called.
*/
AtomicInteger
compareCount
=
new
AtomicInteger
();
/**
* The comparison object used in this test.
*/
Comparator
<
Long
>
comp
=
new
Comparator
<
Long
>()
{
public
int
compare
(
Long
o1
,
Long
o2
)
{
compareCount
.
incrementAndGet
();
...
...
@@ -46,32 +52,32 @@ public class TestSort extends TestBase {
test
(
Arrays
.
class
);
}
void
test
(
Class
<?>
clazz
)
throws
Exception
{
private
void
test
(
Class
<?>
clazz
)
throws
Exception
{
this
.
clazz
=
clazz
;
ordered
(
array
);
shuffle
(
array
);
stab
a
lize
(
array
);
stab
i
lize
(
array
);
test
(
"random"
);
ordered
(
array
);
stab
a
lize
(
array
);
stab
i
lize
(
array
);
test
(
"ordered"
);
ordered
(
array
);
reverse
(
array
);
stab
a
lize
(
array
);
stab
i
lize
(
array
);
test
(
"reverse"
);
ordered
(
array
);
stretch
(
array
);
shuffle
(
array
);
stab
a
lize
(
array
);
stab
i
lize
(
array
);
test
(
"few random"
);
ordered
(
array
);
stretch
(
array
);
stab
a
lize
(
array
);
stab
i
lize
(
array
);
test
(
"few ordered"
);
ordered
(
array
);
reverse
(
array
);
stretch
(
array
);
stab
a
lize
(
array
);
stab
i
lize
(
array
);
test
(
"few reverse"
);
System
.
out
.
println
();
}
...
...
@@ -89,7 +95,7 @@ public class TestSort extends TestBase {
clazz
.
getMethod
(
"sort"
,
Object
[].
class
,
Comparator
.
class
).
invoke
(
null
,
array
,
comp
);
// System.out.printf(
// "%4d ms; %10d comparisons
s
order: %s data: %s\n",
// "%4d ms; %10d comparisons order: %s data: %s\n",
// (System.currentTimeMillis() - t),
// compareCount.get(), clazz, type);
...
...
@@ -149,7 +155,7 @@ public class TestSort extends TestBase {
}
}
private
static
void
stab
a
lize
(
Long
[]
array
)
{
private
static
void
stab
i
lize
(
Long
[]
array
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
array
[
i
]
=
(
array
[
i
]
<<
32
)
+
i
;
}
...
...
h2/src/tools/org/h2/dev/sort/InPlaceStableMergeSort.java
浏览文件 @
79f359f9
...
...
@@ -81,10 +81,10 @@ public class InPlaceStableMergeSort<T> {
binaryInsertionSort
(
from
,
to
);
return
;
}
int
m
iddle
=
(
from
+
to
)
>>>
1
;
mergeSort
(
from
,
m
iddle
);
mergeSort
(
m
iddle
+
1
,
to
);
merge
(
from
,
m
iddle
+
1
,
to
);
int
m
=
(
from
+
to
)
>>>
1
;
mergeSort
(
from
,
m
);
mergeSort
(
m
+
1
,
to
);
merge
(
from
,
m
+
1
,
to
);
}
/**
...
...
@@ -165,21 +165,21 @@ public class InPlaceStableMergeSort<T> {
*/
private
void
mergeBig
(
int
from
,
int
second
,
int
to
)
{
int
len1
=
second
-
from
,
len2
=
to
-
second
+
1
;
int
firstCut
,
secondCut
,
new
Mi
d
;
int
firstCut
,
secondCut
,
new
Secon
d
;
if
(
len1
>
len2
)
{
firstCut
=
from
+
len1
/
2
;
secondCut
=
findLower
(
data
[
firstCut
],
second
,
to
);
int
len
=
secondCut
-
second
;
new
Mi
d
=
firstCut
+
len
;
new
Secon
d
=
firstCut
+
len
;
}
else
{
int
len
=
len2
/
2
;
secondCut
=
second
+
len
;
firstCut
=
findUpper
(
data
[
secondCut
],
from
,
second
-
1
);
new
Mi
d
=
firstCut
+
len
;
new
Secon
d
=
firstCut
+
len
;
}
swapBlocks
(
firstCut
,
second
,
secondCut
-
1
);
merge
(
from
,
firstCut
,
new
Mi
d
-
1
);
merge
(
new
Mi
d
,
secondCut
,
to
);
merge
(
from
,
firstCut
,
new
Secon
d
-
1
);
merge
(
new
Secon
d
,
secondCut
,
to
);
}
/**
...
...
@@ -228,9 +228,9 @@ public class InPlaceStableMergeSort<T> {
int
len
=
to
-
from
+
1
,
half
;
while
(
len
>
0
)
{
half
=
len
/
2
;
int
m
id
=
from
+
half
;
if
(
comp
.
compare
(
data
[
m
id
],
x
)
<
0
)
{
from
=
m
id
+
1
;
int
m
=
from
+
half
;
if
(
comp
.
compare
(
data
[
m
],
x
)
<
0
)
{
from
=
m
+
1
;
len
=
len
-
half
-
1
;
}
else
{
len
=
half
;
...
...
@@ -252,9 +252,9 @@ public class InPlaceStableMergeSort<T> {
int
len
=
to
-
from
+
1
,
half
;
while
(
len
>
0
)
{
half
=
len
/
2
;
int
m
id
=
from
+
half
;
if
(
comp
.
compare
(
data
[
m
id
],
x
)
<=
0
)
{
from
=
m
id
+
1
;
int
m
=
from
+
half
;
if
(
comp
.
compare
(
data
[
m
],
x
)
<=
0
)
{
from
=
m
+
1
;
len
=
len
-
half
-
1
;
}
else
{
len
=
half
;
...
...
h2/src/tools/org/h2/dev/sort/InPlaceStableQuicksort.java
浏览文件 @
79f359f9
...
...
@@ -247,13 +247,13 @@ public class InPlaceStableQuicksort<T> {
}
/**
* Select the
kth smallest
element.
* Select the
specified
element.
*
* @param data the array
* @param from the index of the first element
* @param to the index of the last element
* @param k which element to return
* @return the
kth smallest
element
* @param k which element to return
(1 means the lowest)
* @return the
specified
element
*/
private
T
select
(
T
[]
data
,
int
from
,
int
to
,
int
k
)
{
while
(
true
)
{
...
...
@@ -272,7 +272,7 @@ public class InPlaceStableQuicksort<T> {
}
/**
* Partition the elements to select
the kth
element.
* Partition the elements to select
an
element.
*
* @param data the array
* @param from the index of the first element
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论