Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
cc743041
提交
cc743041
authored
8月 10, 2012
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A persistent tree map (work in progress).
上级
6b4ced6d
全部展开
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
190 行增加
和
128 行删除
+190
-128
Chunk.java
h2/src/tools/org/h2/dev/store/btree/Chunk.java
+21
-4
DataUtils.java
h2/src/tools/org/h2/dev/store/btree/DataUtils.java
+86
-5
Page.java
h2/src/tools/org/h2/dev/store/btree/Page.java
+83
-119
没有找到文件。
h2/src/tools/org/h2/dev/store/btree/Chunk.java
浏览文件 @
cc743041
...
...
@@ -11,7 +11,17 @@ import java.io.IOException;
import
java.util.Properties
;
/**
* A chunk of data, containing one or multiple pages
* A chunk of data, containing one or multiple pages.
* <p>
* Chunks are page aligned (each page is usually 4096 bytes).
* There are at most 67 million (2^26) chunks,
* each chunk is at most 2 GB large.
* File format:
* 1 byte: 'c'
* 4 bytes: length
* 4 bytes: chunk id (an incrementing number)
* 8 bytes: metaRootPos
* [ Page ] *
*/
class
Chunk
{
...
...
@@ -50,6 +60,11 @@ class Chunk {
*/
long
metaRootPos
;
/**
* The version stored in this chunk.
*/
long
version
;
Chunk
(
int
id
)
{
this
.
id
=
id
;
}
...
...
@@ -61,16 +76,17 @@ class Chunk {
* @return the block
*/
static
Chunk
fromString
(
String
s
)
{
Chunk
c
=
new
Chunk
(
0
);
Properties
prop
=
new
Properties
();
try
{
prop
.
load
(
new
ByteArrayInputStream
(
s
.
getBytes
(
"UTF-8"
)));
c
.
id
=
Integer
.
parseInt
(
prop
.
get
(
"id"
).
toString
());
int
id
=
Integer
.
parseInt
(
prop
.
get
(
"id"
).
toString
());
Chunk
c
=
new
Chunk
(
id
);
c
.
start
=
Long
.
parseLong
(
prop
.
get
(
"start"
).
toString
());
c
.
length
=
Long
.
parseLong
(
prop
.
get
(
"length"
).
toString
());
c
.
entryCount
=
Integer
.
parseInt
(
prop
.
get
(
"entryCount"
).
toString
());
c
.
liveCount
=
Integer
.
parseInt
(
prop
.
get
(
"liveCount"
).
toString
());
c
.
metaRootPos
=
Long
.
parseLong
(
prop
.
get
(
"metaRoot"
).
toString
());
c
.
version
=
Long
.
parseLong
(
prop
.
get
(
"version"
).
toString
());
return
c
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
...
...
@@ -96,7 +112,8 @@ class Chunk {
"length:"
+
length
+
"\n"
+
"entryCount:"
+
entryCount
+
"\n"
+
"liveCount:"
+
liveCount
+
"\n"
+
"metaRoot:"
+
metaRootPos
+
"\n"
;
"metaRoot:"
+
metaRootPos
+
"\n"
+
"version:"
+
version
+
"\n"
;
}
}
...
...
h2/src/tools/org/h2/dev/store/btree/DataUtils.java
浏览文件 @
cc743041
...
...
@@ -45,7 +45,7 @@ public class DataUtils {
* @param x the value
* @return the length in bytes
*/
static
int
getVarLongLen
(
long
x
)
{
public
static
int
getVarLongLen
(
long
x
)
{
int
i
=
1
;
while
(
true
)
{
x
>>>=
7
;
...
...
@@ -97,7 +97,7 @@ public class DataUtils {
* @param buff the source buffer
* @return the value
*/
static
long
readVarLong
(
ByteBuffer
buff
)
{
public
static
long
readVarLong
(
ByteBuffer
buff
)
{
long
x
=
buff
.
get
();
if
(
x
>=
0
)
{
return
x
;
...
...
@@ -132,7 +132,7 @@ public class DataUtils {
* @param buff the target buffer
* @param x the value
*/
static
void
writeVarLong
(
ByteBuffer
buff
,
long
x
)
{
public
static
void
writeVarLong
(
ByteBuffer
buff
,
long
x
)
{
while
((
x
&
~
0x7f
)
!=
0
)
{
buff
.
put
((
byte
)
(
0x80
|
(
x
&
0x7f
)));
x
>>>=
7
;
...
...
@@ -148,7 +148,7 @@ public class DataUtils {
* @param oldSize the size of the old array
* @param gapIndex the index of the gap
*/
static
void
copyWithGap
(
Object
src
,
Object
dst
,
int
oldSize
,
int
gapIndex
)
{
public
static
void
copyWithGap
(
Object
src
,
Object
dst
,
int
oldSize
,
int
gapIndex
)
{
if
(
gapIndex
>
0
)
{
System
.
arraycopy
(
src
,
0
,
dst
,
0
,
gapIndex
);
}
...
...
@@ -165,7 +165,7 @@ public class DataUtils {
* @param oldSize the size of the old array
* @param removeIndex the index of the entry to remove
*/
static
void
copyExcept
(
Object
src
,
Object
dst
,
int
oldSize
,
int
removeIndex
)
{
public
static
void
copyExcept
(
Object
src
,
Object
dst
,
int
oldSize
,
int
removeIndex
)
{
if
(
removeIndex
>
0
&&
oldSize
>
0
)
{
System
.
arraycopy
(
src
,
0
,
dst
,
0
,
removeIndex
);
}
...
...
@@ -184,4 +184,85 @@ public class DataUtils {
buff
.
rewind
();
}
/**
* Convert the length to a length code 0..31. 31 means more than 1 MB.
*
* @param len the length
* @return the length code
*/
public
static
int
encodeLength
(
int
len
)
{
if
(
len
<=
32
)
{
return
0
;
}
int
x
=
len
;
int
shift
=
0
;
while
(
x
>
3
)
{
shift
++;
x
=
(
x
>>
1
)
+
(
x
&
1
);
}
shift
=
Math
.
max
(
0
,
shift
-
4
);
int
code
=
(
shift
<<
1
)
+
(
x
&
1
);
return
Math
.
min
(
31
,
code
);
}
/**
* Get the chunk id from the position.
*
* @param pos the position
* @return the chunk id
*/
public
static
int
getChunkId
(
long
pos
)
{
return
(
int
)
(
pos
>>>
37
);
}
/**
* Get the maximum length for the given code.
* For the code 31, Integer.MAX_VALUE is returned.
*
* @param pos the position
* @return the maximum length
*/
public
static
int
getMaxLength
(
long
pos
)
{
int
code
=
(
int
)
(
pos
&
31
);
if
(
code
==
31
)
{
return
Integer
.
MAX_VALUE
;
}
return
(
2
+
(
code
&
1
))
<<
((
code
>>
1
)
+
4
);
}
/**
* Get the offset from the position.
*
* @param pos the position
* @return the offset
*/
public
static
int
getOffset
(
long
pos
)
{
return
(
int
)
(
pos
>>
5
);
}
/**
* Get the position of this page. The following information is encoded in
* the position: the chunk id, the offset, and the maximum length.
*
* @param chunkId the chunk id
* @param offset the offset
* @param length the length
* @return the position
*/
public
static
long
getPos
(
int
chunkId
,
int
offset
,
int
length
)
{
return
((
long
)
chunkId
<<
37
)
|
((
long
)
offset
<<
5
)
|
encodeLength
(
length
);
}
/**
* Calculate a check value for the given integer. A check value is mean to
* verify the data is consistent with a high probability, but not meant to
* protect against media failure or deliberate changes.
*
* @param x the value
* @return the check value
*/
public
static
short
getCheckValue
(
int
x
)
{
return
(
short
)
((
x
>>
16
)
^
x
);
}
}
h2/src/tools/org/h2/dev/store/btree/Page.java
浏览文件 @
cc743041
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论