Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
6bed9021
提交
6bed9021
authored
12 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
LIRS replacement algorithm
上级
b052ab59
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
729 行增加
和
18 行删除
+729
-18
TestCache.java
h2/src/test/org/h2/test/store/TestCache.java
+18
-18
LIRSCache.java
h2/src/tools/org/h2/dev/store/btree/LIRSCache.java
+711
-0
没有找到文件。
h2/src/test/org/h2/test/store/TestCache.java
浏览文件 @
6bed9021
...
...
@@ -10,7 +10,7 @@ import java.util.HashSet;
import
java.util.List
;
import
java.util.Map.Entry
;
import
java.util.Random
;
import
org.h2.dev.store.btree.
CacheLirs
;
import
org.h2.dev.store.btree.
LIRSCache
;
import
org.h2.test.TestBase
;
import
org.h2.upgrade.v1_1.util.Profiler
;
import
org.h2.util.New
;
...
...
@@ -46,7 +46,7 @@ public class TestCache extends TestBase {
}
private
void
testEdgeCases
()
{
CacheLirs
<
Integer
,
Integer
>
test
=
CacheLirs
.
newInstance
(
1
,
1
);
LIRSCache
<
Integer
,
Integer
>
test
=
LIRSCache
.
newInstance
(
1
,
1
);
test
.
put
(
1
,
10
,
100
);
assertEquals
(
10
,
test
.
get
(
1
).
intValue
());
try
{
...
...
@@ -85,8 +85,8 @@ public class TestCache extends TestBase {
verifyMapSize
(
385
,
1024
);
verifyMapSize
(
769
,
2048
);
CacheLirs
<
Integer
,
Integer
>
test
;
test
=
CacheLirs
.
newInstance
(
1000
,
1
);
LIRSCache
<
Integer
,
Integer
>
test
;
test
=
LIRSCache
.
newInstance
(
1000
,
1
);
for
(
int
j
=
0
;
j
<
2000
;
j
++)
{
test
.
put
(
j
,
j
);
}
...
...
@@ -99,17 +99,17 @@ public class TestCache extends TestBase {
}
private
void
verifyMapSize
(
int
elements
,
int
mapSize
)
{
CacheLirs
<
Integer
,
Integer
>
test
;
test
=
CacheLirs
.
newInstance
(
elements
-
1
,
1
);
LIRSCache
<
Integer
,
Integer
>
test
;
test
=
LIRSCache
.
newInstance
(
elements
-
1
,
1
);
assertTrue
(
mapSize
>
test
.
sizeMapArray
());
test
=
CacheLirs
.
newInstance
(
elements
,
1
);
test
=
LIRSCache
.
newInstance
(
elements
,
1
);
assertEquals
(
mapSize
,
test
.
sizeMapArray
());
test
=
CacheLirs
.
newInstance
(
elements
*
100
,
100
);
test
=
LIRSCache
.
newInstance
(
elements
*
100
,
100
);
assertEquals
(
mapSize
,
test
.
sizeMapArray
());
}
private
void
testGetPutPeekRemove
()
{
CacheLirs
<
Integer
,
Integer
>
test
=
CacheLirs
.
newInstance
(
4
,
1
);
LIRSCache
<
Integer
,
Integer
>
test
=
LIRSCache
.
newInstance
(
4
,
1
);
test
.
put
(
1
,
10
);
test
.
put
(
2
,
20
);
test
.
put
(
3
,
30
);
...
...
@@ -226,7 +226,7 @@ public class TestCache extends TestBase {
}
private
void
testPruneStack
()
{
CacheLirs
<
Integer
,
Integer
>
test
=
CacheLirs
.
newInstance
(
5
,
1
);
LIRSCache
<
Integer
,
Integer
>
test
=
LIRSCache
.
newInstance
(
5
,
1
);
for
(
int
i
=
0
;
i
<
7
;
i
++)
{
test
.
put
(
i
,
i
*
10
);
}
...
...
@@ -245,7 +245,7 @@ public class TestCache extends TestBase {
}
private
void
testClear
()
{
CacheLirs
<
Integer
,
Integer
>
test
=
CacheLirs
.
newInstance
(
40
,
10
);
LIRSCache
<
Integer
,
Integer
>
test
=
LIRSCache
.
newInstance
(
40
,
10
);
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
test
.
put
(
i
,
10
*
i
,
9
);
}
...
...
@@ -294,7 +294,7 @@ public class TestCache extends TestBase {
}
private
void
testLimitHot
()
{
CacheLirs
<
Integer
,
Integer
>
test
=
CacheLirs
.
newInstance
(
100
,
1
);
LIRSCache
<
Integer
,
Integer
>
test
=
LIRSCache
.
newInstance
(
100
,
1
);
for
(
int
i
=
0
;
i
<
300
;
i
++)
{
test
.
put
(
i
,
10
*
i
);
}
...
...
@@ -304,7 +304,7 @@ public class TestCache extends TestBase {
}
private
void
testLimitNonResident
()
{
CacheLirs
<
Integer
,
Integer
>
test
=
CacheLirs
.
newInstance
(
4
,
1
);
LIRSCache
<
Integer
,
Integer
>
test
=
LIRSCache
.
newInstance
(
4
,
1
);
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
test
.
put
(
i
,
10
*
i
);
}
...
...
@@ -339,7 +339,7 @@ public class TestCache extends TestBase {
}
CacheLirs
<
BadHash
,
Integer
>
test
=
CacheLirs
.
newInstance
(
size
*
2
,
1
);
LIRSCache
<
BadHash
,
Integer
>
test
=
LIRSCache
.
newInstance
(
size
*
2
,
1
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
test
.
put
(
new
BadHash
(
i
),
i
);
}
...
...
@@ -378,7 +378,7 @@ public class TestCache extends TestBase {
boolean
log
=
false
;
int
size
=
20
;
// cache size 11 (10 hot, 1 cold)
CacheLirs
<
Integer
,
Integer
>
test
=
CacheLirs
.
newInstance
(
size
/
2
+
1
,
1
);
LIRSCache
<
Integer
,
Integer
>
test
=
LIRSCache
.
newInstance
(
size
/
2
+
1
,
1
);
// init the cache with some dummy entries
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
test
.
put
(-
i
,
-
i
*
10
);
...
...
@@ -432,7 +432,7 @@ public class TestCache extends TestBase {
int
size
=
10
;
Random
r
=
new
Random
(
1
);
for
(
int
j
=
0
;
j
<
100
;
j
++)
{
CacheLirs
<
Integer
,
Integer
>
test
=
CacheLirs
.
newInstance
(
size
/
2
,
1
);
LIRSCache
<
Integer
,
Integer
>
test
=
LIRSCache
.
newInstance
(
size
/
2
,
1
);
HashMap
<
Integer
,
Integer
>
good
=
New
.
hashMap
();
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
int
key
=
r
.
nextInt
(
size
);
...
...
@@ -473,7 +473,7 @@ public class TestCache extends TestBase {
}
}
private
static
<
K
,
V
>
String
toString
(
CacheLirs
<
K
,
V
>
cache
)
{
private
static
<
K
,
V
>
String
toString
(
LIRSCache
<
K
,
V
>
cache
)
{
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"mem: "
+
cache
.
getUsedMemory
());
buff
.
append
(
" stack:"
);
...
...
@@ -491,7 +491,7 @@ public class TestCache extends TestBase {
return
buff
.
toString
();
}
private
<
K
,
V
>
void
verify
(
CacheLirs
<
K
,
V
>
cache
,
String
expected
)
{
private
<
K
,
V
>
void
verify
(
LIRSCache
<
K
,
V
>
cache
,
String
expected
)
{
if
(
expected
!=
null
)
{
String
got
=
toString
(
cache
);
assertEquals
(
expected
,
got
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/dev/store/btree/LIRSCache.java
0 → 100644
浏览文件 @
6bed9021
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论