Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
4fcbd09e
Unverified
提交
4fcbd09e
authored
5月 12, 2018
作者:
Evgenij Ryazanov
提交者:
GitHub
5月 12, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1133 from katzyn/misc
Implement Comparable<Value> in CompareMode and optimize ValueHashMap.keys()
上级
871d372b
09fa2a0d
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
42 行增加
和
56 行删除
+42
-56
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+1
-6
QueryStatisticsData.java
h2/src/main/org/h2/engine/QueryStatisticsData.java
+1
-1
Aggregate.java
h2/src/main/org/h2/expression/Aggregate.java
+1
-8
AggregateDataMedian.java
h2/src/main/org/h2/expression/AggregateDataMedian.java
+1
-7
ConditionInConstantSet.java
h2/src/main/org/h2/expression/ConditionInConstantSet.java
+1
-7
IndexCondition.java
h2/src/main/org/h2/index/IndexCondition.java
+1
-9
ValueHashMap.java
h2/src/main/org/h2/util/ValueHashMap.java
+25
-16
CompareMode.java
h2/src/main/org/h2/value/CompareMode.java
+7
-1
TestValueHashMap.java
h2/src/test/org/h2/test/unit/TestValueHashMap.java
+4
-1
没有找到文件。
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
4fcbd09e
...
...
@@ -318,12 +318,7 @@ public class ScriptCommand extends ScriptBase {
// Generate CREATE CONSTRAINT ...
final
ArrayList
<
SchemaObject
>
constraints
=
db
.
getAllSchemaObjects
(
DbObject
.
CONSTRAINT
);
Collections
.
sort
(
constraints
,
new
Comparator
<
SchemaObject
>()
{
@Override
public
int
compare
(
SchemaObject
c1
,
SchemaObject
c2
)
{
return
((
Constraint
)
c1
).
compareTo
((
Constraint
)
c2
);
}
});
Collections
.
sort
(
constraints
,
null
);
for
(
SchemaObject
obj
:
constraints
)
{
if
(
excludeSchema
(
obj
.
getSchema
()))
{
continue
;
...
...
h2/src/main/org/h2/engine/QueryStatisticsData.java
浏览文件 @
4fcbd09e
...
...
@@ -23,7 +23,7 @@ public class QueryStatisticsData {
new
Comparator
<
QueryEntry
>()
{
@Override
public
int
compare
(
QueryEntry
o1
,
QueryEntry
o2
)
{
return
(
int
)
Math
.
signum
(
o1
.
lastUpdateTime
-
o2
.
lastUpdateTime
);
return
Long
.
signum
(
o1
.
lastUpdateTime
-
o2
.
lastUpdateTime
);
}
};
...
...
h2/src/main/org/h2/expression/Aggregate.java
浏览文件 @
4fcbd09e
...
...
@@ -12,7 +12,6 @@ import java.util.HashMap;
import
org.h2.api.ErrorCode
;
import
org.h2.command.dml.Select
;
import
org.h2.command.dml.SelectOrderBy
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.index.Cursor
;
import
org.h2.index.Index
;
...
...
@@ -267,13 +266,7 @@ public class Aggregate extends Expression {
}
});
}
else
{
final
Database
database
=
select
.
getSession
().
getDatabase
();
Arrays
.
sort
(
array
,
new
Comparator
<
Value
>
()
{
@Override
public
int
compare
(
Value
v1
,
Value
v2
)
{
return
database
.
compare
(
v1
,
v2
);
}
});
Arrays
.
sort
(
array
,
select
.
getSession
().
getDatabase
().
getCompareMode
());
}
}
...
...
h2/src/main/org/h2/expression/AggregateDataMedian.java
浏览文件 @
4fcbd09e
...
...
@@ -8,7 +8,6 @@ package org.h2.expression;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
...
...
@@ -173,12 +172,7 @@ class AggregateDataMedian extends AggregateDataCollecting {
return
ValueNull
.
INSTANCE
;
}
final
CompareMode
mode
=
database
.
getCompareMode
();
Arrays
.
sort
(
a
,
new
Comparator
<
Value
>()
{
@Override
public
int
compare
(
Value
o1
,
Value
o2
)
{
return
o1
.
compareTo
(
o2
,
mode
);
}
});
Arrays
.
sort
(
a
,
mode
);
int
len
=
a
.
length
;
int
idx
=
len
/
2
;
Value
v1
=
a
[
idx
];
...
...
h2/src/main/org/h2/expression/ConditionInConstantSet.java
浏览文件 @
4fcbd09e
...
...
@@ -6,7 +6,6 @@
package
org
.
h2
.
expression
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.TreeSet
;
import
org.h2.engine.Session
;
import
org.h2.index.IndexCondition
;
...
...
@@ -43,12 +42,7 @@ public class ConditionInConstantSet extends Condition {
ArrayList
<
Expression
>
valueList
)
{
this
.
left
=
left
;
this
.
valueList
=
valueList
;
this
.
valueSet
=
new
TreeSet
<>(
new
Comparator
<
Value
>()
{
@Override
public
int
compare
(
Value
o1
,
Value
o2
)
{
return
session
.
getDatabase
().
compare
(
o1
,
o2
);
}
});
this
.
valueSet
=
new
TreeSet
<>(
session
.
getDatabase
().
getCompareMode
());
int
type
=
left
.
getType
();
for
(
Expression
expression
:
valueList
)
{
valueSet
.
add
(
expression
.
getValue
(
session
).
convertTo
(
type
));
...
...
h2/src/main/org/h2/index/IndexCondition.java
浏览文件 @
4fcbd09e
...
...
@@ -7,7 +7,6 @@ package org.h2.index;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.HashSet
;
import
java.util.List
;
import
org.h2.command.dml.Query
;
...
...
@@ -21,7 +20,6 @@ import org.h2.result.ResultInterface;
import
org.h2.table.Column
;
import
org.h2.table.TableType
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.CompareMode
;
import
org.h2.value.Value
;
/**
...
...
@@ -156,13 +154,7 @@ public class IndexCondition {
valueSet
.
add
(
v
);
}
Value
[]
array
=
valueSet
.
toArray
(
new
Value
[
valueSet
.
size
()]);
final
CompareMode
mode
=
session
.
getDatabase
().
getCompareMode
();
Arrays
.
sort
(
array
,
new
Comparator
<
Value
>()
{
@Override
public
int
compare
(
Value
o1
,
Value
o2
)
{
return
o1
.
compareTo
(
o2
,
mode
);
}
});
Arrays
.
sort
(
array
,
session
.
getDatabase
().
getCompareMode
());
return
array
;
}
...
...
h2/src/main/org/h2/util/ValueHashMap.java
浏览文件 @
4fcbd09e
...
...
@@ -179,18 +179,22 @@ public class ValueHashMap<V> extends HashBase {
}
/**
* Get the
list of
keys.
* Get the keys.
*
* @return all keys
*/
public
ArrayList
<
Value
>
keys
()
{
ArrayList
<
Value
>
list
=
new
ArrayList
<>(
size
);
for
(
Value
k
:
keys
)
{
if
(
k
!=
null
&&
k
!=
ValueNull
.
DELETED
)
{
list
.
add
(
k
);
}
public
Iterable
<
Value
>
keys
()
{
return
new
KeyIterable
();
}
private
final
class
KeyIterable
implements
Iterable
<
Value
>
{
KeyIterable
()
{
}
@Override
public
Iterator
<
Value
>
iterator
()
{
return
new
UnifiedIterator
<>(
false
);
}
return
list
;
}
public
Iterable
<
Map
.
Entry
<
Value
,
V
>>
entries
()
{
...
...
@@ -203,15 +207,18 @@ public class ValueHashMap<V> extends HashBase {
@Override
public
Iterator
<
Map
.
Entry
<
Value
,
V
>>
iterator
()
{
return
new
EntryIterator
(
);
return
new
UnifiedIterator
<>(
true
);
}
}
private
final
class
EntryIterator
implements
Iterator
<
Map
.
Entry
<
Value
,
V
>
>
{
private
int
keysIndex
=
-
1
;
private
int
left
=
size
;
final
class
UnifiedIterator
<
T
>
implements
Iterator
<
T
>
{
int
keysIndex
=
-
1
;
int
left
=
size
;
EntryIterator
()
{
private
final
boolean
forEntries
;
UnifiedIterator
(
boolean
forEntries
)
{
this
.
forEntries
=
forEntries
;
}
@Override
...
...
@@ -219,16 +226,18 @@ public class ValueHashMap<V> extends HashBase {
return
left
>
0
;
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
Map
.
Entry
<
Value
,
V
>
next
()
{
public
T
next
()
{
if
(
left
<=
0
)
throw
new
NoSuchElementException
();
left
--;
for
(;;)
{
keysIndex
++;
Value
key
=
keys
[
keysIndex
];
if
(
key
!=
null
&&
key
!=
ValueNull
.
DELETED
)
return
new
AbstractMap
.
SimpleImmutableEntry
<>(
key
,
values
[
keysIndex
]);
if
(
key
!=
null
&&
key
!=
ValueNull
.
DELETED
)
{
return
(
T
)
(
forEntries
?
new
AbstractMap
.
SimpleImmutableEntry
<>(
key
,
values
[
keysIndex
])
:
key
);
}
}
}
...
...
h2/src/main/org/h2/value/CompareMode.java
浏览文件 @
4fcbd09e
...
...
@@ -7,6 +7,7 @@ package org.h2.value;
import
java.nio.charset.Charset
;
import
java.text.Collator
;
import
java.util.Comparator
;
import
java.util.Locale
;
import
java.util.Objects
;
...
...
@@ -17,7 +18,7 @@ import org.h2.util.StringUtils;
* Instances of this class can compare strings. Case sensitive and case
* insensitive comparison is supported, and comparison using a collator.
*/
public
class
CompareMode
{
public
class
CompareMode
implements
Comparator
<
Value
>
{
/**
* This constant means there is no collator set, and the default string
...
...
@@ -286,4 +287,9 @@ public class CompareMode {
return
getName
().
hashCode
()
^
strength
^
(
binaryUnsigned
?
-
1
:
0
);
}
@Override
public
int
compare
(
Value
o1
,
Value
o2
)
{
return
o1
.
compareTo
(
o2
,
this
);
}
}
h2/src/test/org/h2/test/unit/TestValueHashMap.java
浏览文件 @
4fcbd09e
...
...
@@ -85,7 +85,10 @@ public class TestValueHashMap extends TestBase implements DataHandler {
assertTrue
(
v1
==
null
?
v2
==
null
:
v1
.
equals
(
v2
));
break
;
case
3
:
{
ArrayList
<
Value
>
a1
=
map
.
keys
();
ArrayList
<
Value
>
a1
=
new
ArrayList
<>();
for
(
Value
v
:
map
.
keys
())
{
a1
.
add
(
v
);
}
ArrayList
<
Value
>
a2
=
new
ArrayList
<>(
hash
.
keySet
());
assertEquals
(
a1
.
size
(),
a2
.
size
());
Collections
.
sort
(
a1
,
vc
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论