Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5f3ca200
提交
5f3ca200
authored
7月 12, 2012
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Documentation
上级
62710f4f
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
616 行增加
和
549 行删除
+616
-549
_text_ko.prop
h2/src/main/org/h2/server/web/res/_text_ko.prop
+153
-155
table.js
h2/src/main/org/h2/server/web/res/table.js
+1
-1
Block.java
h2/src/tools/org/h2/dev/store/btree/Block.java
+96
-0
BtreeMap.java
h2/src/tools/org/h2/dev/store/btree/BtreeMap.java
+5
-287
BtreeMapStore.java
h2/src/tools/org/h2/dev/store/btree/BtreeMapStore.java
+0
-84
Cursor.java
h2/src/tools/org/h2/dev/store/btree/Cursor.java
+46
-0
CursorPos.java
h2/src/tools/org/h2/dev/store/btree/CursorPos.java
+24
-0
DataType.java
h2/src/tools/org/h2/dev/store/btree/DataType.java
+57
-0
DataUtils.java
h2/src/tools/org/h2/dev/store/btree/DataUtils.java
+136
-0
IntegerType.java
h2/src/tools/org/h2/dev/store/btree/IntegerType.java
+37
-0
Page.java
h2/src/tools/org/h2/dev/store/btree/Page.java
+6
-22
StringType.java
h2/src/tools/org/h2/dev/store/btree/StringType.java
+55
-0
没有找到文件。
h2/src/main/org/h2/server/web/res/_text_ko.prop
浏览文件 @
5f3ca200
差异被折叠。
点击展开。
h2/src/main/org/h2/server/web/res/table.js
浏览文件 @
5f3ca200
...
...
@@ -68,7 +68,7 @@ function editRow(row, session, write, undo) {
replace
(
/>/g
,
'>'
);
var
size
;
var
newHTML
;
if
(
text
.
indexOf
(
'
\
n'
)
>=
0
)
{
if
(
text
.
indexOf
(
'
\
n'
)
>=
0
)
{
size
=
40
;
newHTML
=
'<textarea name="$rowName" cols="$size" onkeydown="return editKeyDown($row, this, event)">$t</textarea/>'
;
}
else
{
...
...
h2/src/tools/org/h2/dev/store/btree/Block.java
0 → 100644
浏览文件 @
5f3ca200
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
dev
.
store
.
btree
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.util.Properties
;
/**
* A block of data.
*/
class
Block
{
/**
* The block id.
*/
int
id
;
/**
* The start position within the file.
*/
long
start
;
/**
* The length in bytes.
*/
long
length
;
/**
* The entry count.
*/
int
entryCount
;
/**
* The number of life (non-garbage) objects.
*/
int
liveCount
;
/**
* The garbage collection priority.
*/
int
collectPriority
;
Block
(
int
id
)
{
this
.
id
=
id
;
}
/**
* Build a block from the given string.
*
* @param s the string
* @return the block
*/
static
Block
fromString
(
String
s
)
{
Block
b
=
new
Block
(
0
);
Properties
prop
=
new
Properties
();
try
{
prop
.
load
(
new
ByteArrayInputStream
(
s
.
getBytes
(
"UTF-8"
)));
b
.
id
=
Integer
.
parseInt
(
prop
.
get
(
"id"
).
toString
());
b
.
start
=
Long
.
parseLong
(
prop
.
get
(
"start"
).
toString
());
b
.
length
=
Long
.
parseLong
(
prop
.
get
(
"length"
).
toString
());
b
.
entryCount
=
Integer
.
parseInt
(
prop
.
get
(
"entryCount"
).
toString
());
b
.
liveCount
=
Integer
.
parseInt
(
prop
.
get
(
"liveCount"
).
toString
());
return
b
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
int
getFillRate
()
{
return
entryCount
==
0
?
0
:
100
*
liveCount
/
entryCount
;
}
public
int
hashCode
()
{
return
id
;
}
public
boolean
equals
(
Object
o
)
{
return
o
instanceof
Block
&&
((
Block
)
o
).
id
==
id
;
}
public
String
toString
()
{
return
"id:"
+
id
+
"\n"
+
"start:"
+
start
+
"\n"
+
"length:"
+
length
+
"\n"
+
"entryCount:"
+
entryCount
+
"\n"
+
"liveCount:"
+
liveCount
+
"\n"
;
}
}
h2/src/tools/org/h2/dev/store/btree/BtreeMap.java
浏览文件 @
5f3ca200
...
...
@@ -6,8 +6,6 @@
*/
package
org
.
h2
.
dev
.
store
.
btree
;
import
java.nio.ByteBuffer
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
/**
...
...
@@ -20,8 +18,8 @@ public class BtreeMap<K, V> {
private
final
BtreeMapStore
store
;
private
final
String
name
;
private
final
Key
Type
keyType
;
private
final
Value
Type
valueType
;
private
final
Data
Type
keyType
;
private
final
Data
Type
valueType
;
private
Page
root
;
private
BtreeMap
(
BtreeMapStore
store
,
String
name
,
Class
<
K
>
keyClass
,
Class
<
V
>
valueClass
)
{
...
...
@@ -136,59 +134,6 @@ public class BtreeMap<K, V> {
return
root
!=
null
&&
root
.
getId
()
<
0
;
}
/**
* A value type.
*/
static
interface
ValueType
{
/**
* Get the length in bytes.
*
* @param obj the object
* @return the length
*/
int
length
(
Object
obj
);
/**
* Write the object.
*
* @param buff the target buffer
* @param x the value
*/
void
write
(
ByteBuffer
buff
,
Object
x
);
/**
* Read an object.
*
* @param buff the source buffer
* @return the object
*/
Object
read
(
ByteBuffer
buff
);
/**
* Get the tag name of the class.
*
* @return the tag name
*/
String
getName
();
}
/**
* A key type.
*/
static
interface
KeyType
extends
ValueType
{
/**
* Compare two keys.
*
* @param a the first key
* @param b the second key
* @return -1 if the first key is smaller, 1 if larger, and 0 if equal
*/
int
compare
(
Object
a
,
Object
b
);
}
/**
* Compare two keys.
*
...
...
@@ -200,84 +145,12 @@ public class BtreeMap<K, V> {
return
keyType
.
compare
(
a
,
b
);
}
/**
* An integer type.
*/
static
class
IntegerType
implements
KeyType
{
public
int
compare
(
Object
a
,
Object
b
)
{
return
((
Integer
)
a
).
compareTo
((
Integer
)
b
);
}
public
int
length
(
Object
obj
)
{
return
getVarIntLen
((
Integer
)
obj
);
}
public
Integer
read
(
ByteBuffer
buff
)
{
return
readVarInt
(
buff
);
}
public
void
write
(
ByteBuffer
buff
,
Object
x
)
{
writeVarInt
(
buff
,
(
Integer
)
x
);
}
public
String
getName
()
{
return
"i"
;
}
}
/**
* A string type.
*/
static
class
StringType
implements
KeyType
{
public
int
compare
(
Object
a
,
Object
b
)
{
return
a
.
toString
().
compareTo
(
b
.
toString
());
}
public
int
length
(
Object
obj
)
{
try
{
byte
[]
bytes
=
obj
.
toString
().
getBytes
(
"UTF-8"
);
return
getVarIntLen
(
bytes
.
length
)
+
bytes
.
length
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
String
read
(
ByteBuffer
buff
)
{
int
len
=
readVarInt
(
buff
);
byte
[]
bytes
=
new
byte
[
len
];
buff
.
get
(
bytes
);
try
{
return
new
String
(
bytes
,
"UTF-8"
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
void
write
(
ByteBuffer
buff
,
Object
x
)
{
try
{
byte
[]
bytes
=
x
.
toString
().
getBytes
(
"UTF-8"
);
writeVarInt
(
buff
,
bytes
.
length
);
buff
.
put
(
bytes
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
String
getName
()
{
return
"s"
;
}
}
/**
* Get the key type.
*
* @return the key type
*/
Key
Type
getKeyType
()
{
Data
Type
getKeyType
()
{
return
keyType
;
}
...
...
@@ -286,7 +159,7 @@ public class BtreeMap<K, V> {
*
* @return the value type
*/
Value
Type
getValueType
()
{
Data
Type
getValueType
()
{
return
valueType
;
}
...
...
@@ -339,42 +212,7 @@ public class BtreeMap<K, V> {
* @return the iterator
*/
public
Iterator
<
K
>
keyIterator
(
K
from
)
{
return
new
Cursor
(
root
,
from
);
}
/**
* A cursor to iterate over elements in ascending order.
*/
class
Cursor
implements
Iterator
<
K
>
{
private
ArrayList
<
Page
.
CursorPos
>
parents
=
new
ArrayList
<
Page
.
CursorPos
>();
private
K
current
;
Cursor
(
Page
root
,
K
from
)
{
Page
.
min
(
root
,
parents
,
from
);
fetchNext
();
}
public
K
next
()
{
K
c
=
current
;
if
(
c
!=
null
)
{
fetchNext
();
}
return
c
==
null
?
null
:
c
;
}
@SuppressWarnings
(
"unchecked"
)
private
void
fetchNext
()
{
current
=
(
K
)
Page
.
nextKey
(
parents
);
}
public
boolean
hasNext
()
{
return
current
!=
null
;
}
public
void
remove
()
{
throw
new
UnsupportedOperationException
();
}
return
new
Cursor
<
K
>(
root
,
from
);
}
/**
...
...
@@ -395,124 +233,4 @@ public class BtreeMap<K, V> {
return
name
;
}
/**
* Read a variable size long.
*
* @param buff the source buffer
* @return the value
*/
static
long
readVarLong
(
ByteBuffer
buff
)
{
long
x
=
buff
.
get
();
if
(
x
>=
0
)
{
return
x
;
}
x
&=
0x7f
;
for
(
int
s
=
7
;;
s
+=
7
)
{
long
b
=
buff
.
get
();
x
|=
(
b
&
0x7f
)
<<
s
;
if
(
b
>=
0
)
{
return
x
;
}
}
}
/**
* Read a variable size int.
*
* @param buff the source buffer
* @return the value
*/
static
int
readVarInt
(
ByteBuffer
buff
)
{
int
b
=
buff
.
get
();
if
(
b
>=
0
)
{
return
b
;
}
// a separate function so that this one can be inlined
return
readVarIntRest
(
buff
,
b
);
}
private
static
int
readVarIntRest
(
ByteBuffer
buff
,
int
b
)
{
int
x
=
b
&
0x7f
;
b
=
buff
.
get
();
if
(
b
>=
0
)
{
return
x
|
(
b
<<
7
);
}
x
|=
(
b
&
0x7f
)
<<
7
;
b
=
buff
.
get
();
if
(
b
>=
0
)
{
return
x
|
(
b
<<
14
);
}
x
|=
(
b
&
0x7f
)
<<
14
;
b
=
buff
.
get
();
if
(
b
>=
0
)
{
return
x
|
b
<<
21
;
}
x
|=
((
b
&
0x7f
)
<<
21
)
|
(
buff
.
get
()
<<
28
);
return
x
;
}
/**
* Get the length of the variable size int.
*
* @param x the value
* @return the length in bytes
*/
static
int
getVarIntLen
(
int
x
)
{
if
((
x
&
(-
1
<<
7
))
==
0
)
{
return
1
;
}
else
if
((
x
&
(-
1
<<
14
))
==
0
)
{
return
2
;
}
else
if
((
x
&
(-
1
<<
21
))
==
0
)
{
return
3
;
}
else
if
((
x
&
(-
1
<<
28
))
==
0
)
{
return
4
;
}
return
5
;
}
/**
* Get the length of the variable size long.
*
* @param x the value
* @return the length in bytes
*/
static
int
getVarLongLen
(
long
x
)
{
int
i
=
1
;
while
(
true
)
{
x
>>>=
7
;
if
(
x
==
0
)
{
return
i
;
}
i
++;
}
}
/**
* Write a variable size int.
*
* @param buff the target buffer
* @param x the value
*/
static
void
writeVarInt
(
ByteBuffer
buff
,
int
x
)
{
while
((
x
&
~
0x7f
)
!=
0
)
{
buff
.
put
((
byte
)
(
0x80
|
(
x
&
0x7f
)));
x
>>>=
7
;
}
buff
.
put
((
byte
)
x
);
}
/**
* Write a variable size int.
*
* @param buff the target buffer
* @param x the value
*/
static
void
writeVarLong
(
ByteBuffer
buff
,
long
x
)
{
while
((
x
&
~
0x7f
)
!=
0
)
{
buff
.
put
((
byte
)
(
0x80
|
(
x
&
0x7f
)));
x
>>>=
7
;
}
buff
.
put
((
byte
)
x
);
}
}
h2/src/tools/org/h2/dev/store/btree/BtreeMapStore.java
浏览文件 @
5f3ca200
...
...
@@ -605,90 +605,6 @@ public class BtreeMapStore {
return
blocks
.
get
(
getBlockId
(
pageId
));
}
/**
* A block of data.
*/
static
class
Block
{
/**
* The block id.
*/
int
id
;
/**
* The start position within the file.
*/
long
start
;
/**
* The length in bytes.
*/
long
length
;
/**
* The entry count.
*/
int
entryCount
;
/**
* The number of life (non-garbage) objects.
*/
int
liveCount
;
/**
* The garbage collection priority.
*/
int
collectPriority
;
Block
(
int
id
)
{
this
.
id
=
id
;
}
/**
* Build a block from the given string.
*
* @param s the string
* @return the block
*/
static
Block
fromString
(
String
s
)
{
Block
b
=
new
Block
(
0
);
Properties
prop
=
new
Properties
();
try
{
prop
.
load
(
new
ByteArrayInputStream
(
s
.
getBytes
(
"UTF-8"
)));
b
.
id
=
Integer
.
parseInt
(
prop
.
get
(
"id"
).
toString
());
b
.
start
=
Long
.
parseLong
(
prop
.
get
(
"start"
).
toString
());
b
.
length
=
Long
.
parseLong
(
prop
.
get
(
"length"
).
toString
());
b
.
entryCount
=
Integer
.
parseInt
(
prop
.
get
(
"entryCount"
).
toString
());
b
.
liveCount
=
Integer
.
parseInt
(
prop
.
get
(
"liveCount"
).
toString
());
return
b
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
int
getFillRate
()
{
return
entryCount
==
0
?
0
:
100
*
liveCount
/
entryCount
;
}
public
int
hashCode
()
{
return
id
;
}
public
boolean
equals
(
Object
o
)
{
return
o
instanceof
Block
&&
((
Block
)
o
).
id
==
id
;
}
public
String
toString
()
{
return
"id:"
+
id
+
"\n"
+
"start:"
+
start
+
"\n"
+
"length:"
+
length
+
"\n"
+
"entryCount:"
+
entryCount
+
"\n"
+
"liveCount:"
+
liveCount
+
"\n"
;
}
}
/**
* Log the string, if logging is enabled.
*
...
...
h2/src/tools/org/h2/dev/store/btree/Cursor.java
0 → 100644
浏览文件 @
5f3ca200
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
dev
.
store
.
btree
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
/**
* A cursor to iterate over elements in ascending order.
*/
class
Cursor
<
K
>
implements
Iterator
<
K
>
{
private
ArrayList
<
CursorPos
>
parents
=
new
ArrayList
<
CursorPos
>();
private
K
current
;
Cursor
(
Page
root
,
K
from
)
{
Page
.
min
(
root
,
parents
,
from
);
fetchNext
();
}
public
K
next
()
{
K
c
=
current
;
if
(
c
!=
null
)
{
fetchNext
();
}
return
c
==
null
?
null
:
c
;
}
@SuppressWarnings
(
"unchecked"
)
private
void
fetchNext
()
{
current
=
(
K
)
Page
.
nextKey
(
parents
);
}
public
boolean
hasNext
()
{
return
current
!=
null
;
}
public
void
remove
()
{
throw
new
UnsupportedOperationException
();
}
}
h2/src/tools/org/h2/dev/store/btree/CursorPos.java
0 → 100644
浏览文件 @
5f3ca200
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
dev
.
store
.
btree
;
/**
* A position in a cursor
*/
class
CursorPos
{
/**
* The current page.
*/
Page
page
;
/**
* The current index.
*/
int
index
;
}
h2/src/tools/org/h2/dev/store/btree/DataType.java
0 → 100644
浏览文件 @
5f3ca200
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
dev
.
store
.
btree
;
import
java.nio.ByteBuffer
;
/**
* A value type.
*/
interface
DataType
{
/**
* Compare two keys.
*
* @param a the first key
* @param b the second key
* @return -1 if the first key is smaller, 1 if larger, and 0 if equal
*/
int
compare
(
Object
a
,
Object
b
);
/**
* Get the length in bytes.
*
* @param obj the object
* @return the length
*/
int
length
(
Object
obj
);
/**
* Write the object.
*
* @param buff the target buffer
* @param x the value
*/
void
write
(
ByteBuffer
buff
,
Object
x
);
/**
* Read an object.
*
* @param buff the source buffer
* @return the object
*/
Object
read
(
ByteBuffer
buff
);
/**
* Get the tag name of the class.
*
* @return the tag name
*/
String
getName
();
}
h2/src/tools/org/h2/dev/store/btree/DataUtils.java
0 → 100644
浏览文件 @
5f3ca200
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
dev
.
store
.
btree
;
import
java.nio.ByteBuffer
;
/**
* Utility methods
*/
public
class
DataUtils
{
/**
* Get the length of the variable size int.
*
* @param x the value
* @return the length in bytes
*/
static
int
getVarIntLen
(
int
x
)
{
if
((
x
&
(-
1
<<
7
))
==
0
)
{
return
1
;
}
else
if
((
x
&
(-
1
<<
14
))
==
0
)
{
return
2
;
}
else
if
((
x
&
(-
1
<<
21
))
==
0
)
{
return
3
;
}
else
if
((
x
&
(-
1
<<
28
))
==
0
)
{
return
4
;
}
return
5
;
}
/**
* Get the length of the variable size long.
*
* @param x the value
* @return the length in bytes
*/
static
int
getVarLongLen
(
long
x
)
{
int
i
=
1
;
while
(
true
)
{
x
>>>=
7
;
if
(
x
==
0
)
{
return
i
;
}
i
++;
}
}
/**
* Read a variable size int.
*
* @param buff the source buffer
* @return the value
*/
static
int
readVarInt
(
ByteBuffer
buff
)
{
int
b
=
buff
.
get
();
if
(
b
>=
0
)
{
return
b
;
}
// a separate function so that this one can be inlined
return
readVarIntRest
(
buff
,
b
);
}
private
static
int
readVarIntRest
(
ByteBuffer
buff
,
int
b
)
{
int
x
=
b
&
0x7f
;
b
=
buff
.
get
();
if
(
b
>=
0
)
{
return
x
|
(
b
<<
7
);
}
x
|=
(
b
&
0x7f
)
<<
7
;
b
=
buff
.
get
();
if
(
b
>=
0
)
{
return
x
|
(
b
<<
14
);
}
x
|=
(
b
&
0x7f
)
<<
14
;
b
=
buff
.
get
();
if
(
b
>=
0
)
{
return
x
|
b
<<
21
;
}
x
|=
((
b
&
0x7f
)
<<
21
)
|
(
buff
.
get
()
<<
28
);
return
x
;
}
/**
* Read a variable size long.
*
* @param buff the source buffer
* @return the value
*/
static
long
readVarLong
(
ByteBuffer
buff
)
{
long
x
=
buff
.
get
();
if
(
x
>=
0
)
{
return
x
;
}
x
&=
0x7f
;
for
(
int
s
=
7
;;
s
+=
7
)
{
long
b
=
buff
.
get
();
x
|=
(
b
&
0x7f
)
<<
s
;
if
(
b
>=
0
)
{
return
x
;
}
}
}
/**
* Write a variable size int.
*
* @param buff the target buffer
* @param x the value
*/
static
void
writeVarInt
(
ByteBuffer
buff
,
int
x
)
{
while
((
x
&
~
0x7f
)
!=
0
)
{
buff
.
put
((
byte
)
(
0x80
|
(
x
&
0x7f
)));
x
>>>=
7
;
}
buff
.
put
((
byte
)
x
);
}
/**
* Write a variable size int.
*
* @param buff the target buffer
* @param x the value
*/
static
void
writeVarLong
(
ByteBuffer
buff
,
long
x
)
{
while
((
x
&
~
0x7f
)
!=
0
)
{
buff
.
put
((
byte
)
(
0x80
|
(
x
&
0x7f
)));
x
>>>=
7
;
}
buff
.
put
((
byte
)
x
);
}
}
h2/src/tools/org/h2/dev/store/btree/IntegerType.java
0 → 100644
浏览文件 @
5f3ca200
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
dev
.
store
.
btree
;
import
java.nio.ByteBuffer
;
/**
* An integer type.
*/
class
IntegerType
implements
DataType
{
public
int
compare
(
Object
a
,
Object
b
)
{
return
((
Integer
)
a
).
compareTo
((
Integer
)
b
);
}
public
int
length
(
Object
obj
)
{
return
DataUtils
.
getVarIntLen
((
Integer
)
obj
);
}
public
Integer
read
(
ByteBuffer
buff
)
{
return
DataUtils
.
readVarInt
(
buff
);
}
public
void
write
(
ByteBuffer
buff
,
Object
x
)
{
DataUtils
.
writeVarInt
(
buff
,
(
Integer
)
x
);
}
public
String
getName
()
{
return
"i"
;
}
}
h2/src/tools/org/h2/dev/store/btree/Page.java
浏览文件 @
5f3ca200
...
...
@@ -167,22 +167,6 @@ class Page {
return
-(
low
+
1
);
}
/**
* A position in a cursor
*/
static
class
CursorPos
{
/**
* The current page.
*/
Page
page
;
/**
* The current index.
*/
int
index
;
}
/**
* Go to the first element for the given key.
*
...
...
@@ -453,7 +437,7 @@ class Page {
private
void
read
(
ByteBuffer
buff
)
{
boolean
node
=
buff
.
get
()
==
1
;
if
(
node
)
{
int
len
=
BtreeMap
.
readVarInt
(
buff
);
int
len
=
DataUtils
.
readVarInt
(
buff
);
children
=
new
long
[
len
];
keys
=
new
Object
[
len
-
1
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
...
...
@@ -463,7 +447,7 @@ class Page {
}
}
}
else
{
int
len
=
BtreeMap
.
readVarInt
(
buff
);
int
len
=
DataUtils
.
readVarInt
(
buff
);
keys
=
new
Object
[
len
];
values
=
new
Object
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
...
...
@@ -482,7 +466,7 @@ class Page {
if
(
children
!=
null
)
{
buff
.
put
((
byte
)
1
);
int
len
=
children
.
length
;
BtreeMap
.
writeVarInt
(
buff
,
len
);
DataUtils
.
writeVarInt
(
buff
,
len
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
long
c
=
map
.
readPage
(
children
[
i
]).
storedId
;
buff
.
putLong
(
c
);
...
...
@@ -493,7 +477,7 @@ class Page {
}
else
{
buff
.
put
((
byte
)
0
);
int
len
=
keys
.
length
;
BtreeMap
.
writeVarInt
(
buff
,
len
);
DataUtils
.
writeVarInt
(
buff
,
len
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
map
.
getKeyType
().
write
(
buff
,
keys
[
i
]);
map
.
getValueType
().
write
(
buff
,
values
[
i
]);
...
...
@@ -590,7 +574,7 @@ class Page {
int
byteCount
=
1
;
if
(
children
!=
null
)
{
int
len
=
children
.
length
;
byteCount
+=
BtreeMap
.
getVarIntLen
(
len
);
byteCount
+=
DataUtils
.
getVarIntLen
(
len
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
byteCount
+=
8
;
if
(
i
<
keys
.
length
)
{
...
...
@@ -599,7 +583,7 @@ class Page {
}
}
else
{
int
len
=
keys
.
length
;
byteCount
+=
BtreeMap
.
getVarIntLen
(
len
);
byteCount
+=
DataUtils
.
getVarIntLen
(
len
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
byteCount
+=
map
.
getKeyType
().
length
(
keys
[
i
]);
byteCount
+=
map
.
getValueType
().
length
(
values
[
i
]);
...
...
h2/src/tools/org/h2/dev/store/btree/StringType.java
0 → 100644
浏览文件 @
5f3ca200
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
dev
.
store
.
btree
;
import
java.nio.ByteBuffer
;
/**
* A string type.
*/
class
StringType
implements
DataType
{
public
int
compare
(
Object
a
,
Object
b
)
{
return
a
.
toString
().
compareTo
(
b
.
toString
());
}
public
int
length
(
Object
obj
)
{
try
{
byte
[]
bytes
=
obj
.
toString
().
getBytes
(
"UTF-8"
);
return
DataUtils
.
getVarIntLen
(
bytes
.
length
)
+
bytes
.
length
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
String
read
(
ByteBuffer
buff
)
{
int
len
=
DataUtils
.
readVarInt
(
buff
);
byte
[]
bytes
=
new
byte
[
len
];
buff
.
get
(
bytes
);
try
{
return
new
String
(
bytes
,
"UTF-8"
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
void
write
(
ByteBuffer
buff
,
Object
x
)
{
try
{
byte
[]
bytes
=
x
.
toString
().
getBytes
(
"UTF-8"
);
DataUtils
.
writeVarInt
(
buff
,
bytes
.
length
);
buff
.
put
(
bytes
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
String
getName
()
{
return
"s"
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论