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