Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
15b90dfb
提交
15b90dfb
authored
1月 15, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add offset parameter to DataUtils.getFletcher32()
上级
7c92925c
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
20 行增加
和
17 行删除
+20
-17
Chunk.java
h2/src/main/org/h2/mvstore/Chunk.java
+1
-1
DataUtils.java
h2/src/main/org/h2/mvstore/DataUtils.java
+7
-6
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+1
-1
TestDataUtils.java
h2/src/test/org/h2/test/store/TestDataUtils.java
+10
-8
ArchiveToolStore.java
h2/src/tools/org/h2/dev/fs/ArchiveToolStore.java
+1
-1
没有找到文件。
h2/src/main/org/h2/mvstore/Chunk.java
浏览文件 @
15b90dfb
...
...
@@ -259,7 +259,7 @@ public class Chunk {
DataUtils
.
appendMap
(
buff
,
"block"
,
block
);
DataUtils
.
appendMap
(
buff
,
"version"
,
version
);
byte
[]
bytes
=
buff
.
toString
().
getBytes
(
StandardCharsets
.
ISO_8859_1
);
int
checksum
=
DataUtils
.
getFletcher32
(
bytes
,
bytes
.
length
);
int
checksum
=
DataUtils
.
getFletcher32
(
bytes
,
0
,
bytes
.
length
);
DataUtils
.
appendMap
(
buff
,
"fletcher"
,
checksum
);
while
(
buff
.
length
()
<
Chunk
.
FOOTER_LENGTH
-
1
)
{
buff
.
append
(
' '
);
...
...
h2/src/main/org/h2/mvstore/DataUtils.java
浏览文件 @
15b90dfb
...
...
@@ -695,7 +695,7 @@ public final class DataUtils {
DataUtils
.
parseMapValue
(
buff
,
s
,
i
+
1
,
size
);
int
check
=
(
int
)
Long
.
parseLong
(
buff
.
toString
(),
16
);
bytes
=
s
.
getBytes
(
StandardCharsets
.
ISO_8859_1
);
if
(
check
==
DataUtils
.
getFletcher32
(
bytes
,
startKey
-
1
))
{
if
(
check
==
DataUtils
.
getFletcher32
(
bytes
,
0
,
startKey
-
1
))
{
return
map
;
}
// Corrupted map
...
...
@@ -759,22 +759,23 @@ public final class DataUtils {
* Calculate the Fletcher32 checksum.
*
* @param bytes the bytes
* @param offset initial offset
* @param length the message length (if odd, 0 is appended)
* @return the checksum
*/
public
static
int
getFletcher32
(
byte
[]
bytes
,
int
length
)
{
public
static
int
getFletcher32
(
byte
[]
bytes
,
int
offset
,
int
length
)
{
int
s1
=
0xffff
,
s2
=
0xffff
;
int
i
=
0
,
evenLength
=
length
&
~
1
;
while
(
i
<
evenLength
)
{
int
i
=
offset
,
len
=
offset
+
(
length
&
~
1
)
;
while
(
i
<
len
)
{
// reduce after 360 words (each word is two bytes)
for
(
int
end
=
Math
.
min
(
i
+
720
,
evenLength
);
i
<
end
;)
{
for
(
int
end
=
Math
.
min
(
i
+
720
,
len
);
i
<
end
;)
{
int
x
=
((
bytes
[
i
++]
&
0xff
)
<<
8
)
|
(
bytes
[
i
++]
&
0xff
);
s2
+=
s1
+=
x
;
}
s1
=
(
s1
&
0xffff
)
+
(
s1
>>>
16
);
s2
=
(
s2
&
0xffff
)
+
(
s2
>>>
16
);
}
if
(
i
<
length
)
{
if
(
(
length
&
1
)
!=
0
)
{
// odd length: append 0
int
x
=
(
bytes
[
i
]
&
0xff
)
<<
8
;
s2
+=
s1
+=
x
;
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
15b90dfb
...
...
@@ -818,7 +818,7 @@ public final class MVStore {
}
DataUtils
.
appendMap
(
buff
,
storeHeader
);
byte
[]
bytes
=
buff
.
toString
().
getBytes
(
StandardCharsets
.
ISO_8859_1
);
int
checksum
=
DataUtils
.
getFletcher32
(
bytes
,
bytes
.
length
);
int
checksum
=
DataUtils
.
getFletcher32
(
bytes
,
0
,
bytes
.
length
);
DataUtils
.
appendMap
(
buff
,
"fletcher"
,
checksum
);
buff
.
append
(
"\n"
);
bytes
=
buff
.
toString
().
getBytes
(
StandardCharsets
.
ISO_8859_1
);
...
...
h2/src/test/org/h2/test/store/TestDataUtils.java
浏览文件 @
15b90dfb
...
...
@@ -54,24 +54,24 @@ public class TestDataUtils extends TestBase {
private
void
testFletcher
()
{
byte
[]
data
=
new
byte
[
10000
];
for
(
int
i
=
0
;
i
<
10000
;
i
+=
1000
)
{
assertEquals
(-
1
,
DataUtils
.
getFletcher32
(
data
,
i
));
assertEquals
(-
1
,
DataUtils
.
getFletcher32
(
data
,
0
,
i
));
}
Arrays
.
fill
(
data
,
(
byte
)
255
);
for
(
int
i
=
0
;
i
<
10000
;
i
+=
1000
)
{
assertEquals
(-
1
,
DataUtils
.
getFletcher32
(
data
,
i
));
assertEquals
(-
1
,
DataUtils
.
getFletcher32
(
data
,
0
,
i
));
}
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
for
(
int
j
=
0
;
j
<
255
;
j
++)
{
Arrays
.
fill
(
data
,
0
,
i
,
(
byte
)
j
);
data
[
i
]
=
0
;
int
a
=
DataUtils
.
getFletcher32
(
data
,
i
);
int
a
=
DataUtils
.
getFletcher32
(
data
,
0
,
i
);
if
(
i
%
2
==
1
)
{
// add length: same as appending a 0
int
b
=
DataUtils
.
getFletcher32
(
data
,
i
+
1
);
int
b
=
DataUtils
.
getFletcher32
(
data
,
0
,
i
+
1
);
assertEquals
(
a
,
b
);
}
data
[
i
]
=
10
;
int
c
=
DataUtils
.
getFletcher32
(
data
,
i
);
int
c
=
DataUtils
.
getFletcher32
(
data
,
0
,
i
);
assertEquals
(
a
,
c
);
}
}
...
...
@@ -79,16 +79,18 @@ public class TestDataUtils extends TestBase {
for
(
int
i
=
1
;
i
<
255
;
i
++)
{
Arrays
.
fill
(
data
,
(
byte
)
i
);
for
(
int
j
=
0
;
j
<
10
;
j
+=
2
)
{
int
x
=
DataUtils
.
getFletcher32
(
data
,
j
);
int
x
=
DataUtils
.
getFletcher32
(
data
,
0
,
j
);
assertTrue
(
x
!=
last
);
last
=
x
;
}
}
Arrays
.
fill
(
data
,
(
byte
)
10
);
assertEquals
(
0x1e1e1414
,
DataUtils
.
getFletcher32
(
data
,
10000
));
DataUtils
.
getFletcher32
(
data
,
0
,
10000
));
assertEquals
(
0x1e3fa7ed
,
DataUtils
.
getFletcher32
(
"Fletcher32"
.
getBytes
(),
10
));
DataUtils
.
getFletcher32
(
"Fletcher32"
.
getBytes
(),
0
,
10
));
assertEquals
(
0x1e3fa7ed
,
DataUtils
.
getFletcher32
(
"XFletcher32"
.
getBytes
(),
1
,
10
));
}
private
void
testMap
()
{
...
...
h2/src/tools/org/h2/dev/fs/ArchiveToolStore.java
浏览文件 @
15b90dfb
...
...
@@ -525,7 +525,7 @@ public class ArchiveToolStore {
}
key
[
0
]
=
cs
;
key
[
1
]
=
bucket
;
key
[
2
]
=
DataUtils
.
getFletcher32
(
buff
,
buff
.
length
);
key
[
2
]
=
DataUtils
.
getFletcher32
(
buff
,
0
,
buff
.
length
);
return
key
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论