Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
9abf5e1d
提交
9abf5e1d
authored
7月 23, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A concurrent list, to replace the array list of old roots.
上级
1f9fcba2
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
110 行增加
和
125 行删除
+110
-125
ConcurrentArrayList.java
h2/src/main/org/h2/mvstore/ConcurrentArrayList.java
+98
-117
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+2
-2
TestConcurrentLinkedList.java
h2/src/test/org/h2/test/store/TestConcurrentLinkedList.java
+7
-5
ConcurrentLinkedList.java
h2/src/tools/org/h2/dev/util/ConcurrentLinkedList.java
+3
-1
没有找到文件。
h2/src/main/org/h2/mvstore/ConcurrentArrayList.java
浏览文件 @
9abf5e1d
...
...
@@ -17,122 +17,103 @@ import java.util.Iterator;
*/
public
class
ConcurrentArrayList
<
K
>
{
// /**
// * The list.
// */
// volatile List<K> list = new List<K>(null, 0, 0);
//
// /**
// * Get the first element, or null if none.
// *
// * @return the first element
// */
// public K peekFirst() {
// return list.peekFirst();
// }
//
// /**
// * Get the last element, or null if none.
// *
// * @return the last element
// */
// public K peekLast() {
// return list.peekLast();
// }
//
// /**
// * Add an element at the end.
// *
// * @param obj the element
// */
// public synchronized void add(K obj) {
// K[] array = new K[list.length + 1];
// if (list.length > 0) {
// System.arraycopy(list.list, list.offset, dest, destPos, length)
// Arrays.copyOf(, newLength)
// list = new List<K>(list.add(obj);
// }
//
// /**
// * Remove the first element, if it matches.
// *
// * @param obj the element to remove
// * @return true if the element matched and was removed
// */
// public synchronized boolean removeFirst(K obj) {
// if (head.obj != obj) {
// return false;
// }
// head = head.next;
// return true;
// }
//
// /**
// * Remove the last element, if it matches.
// *
// * @param obj the element to remove
// * @return true if the element matched and was removed
// */
// public synchronized boolean removeLast(K obj) {
// if (peekLast() != obj) {
// return false;
// }
// head = Entry.removeLast(head);
// return true;
// }
//
// /**
// * Get an iterator over all entries.
// *
// * @return the iterator
// */
// public Iterator<K> iterator() {
// return new Iterator<K>() {
//
// List<K> list = head;
//
// @Override
// public boolean hasNext() {
// return current != NULL;
// }
//
// @Override
// public K next() {
// K x = current.obj;
// current = current.next;
// return x;
// }
//
// @Override
// public void remove() {
// throw DataUtils.newUnsupportedOperationException("remove");
// }
//
// };
// }
//
// /**
// * An entry in the linked list.
// */
// private static class List<K> {
// final K[] list;
// final int offset;
// final int length;
//
// List(K[] list, int offset, int length) {
// this.list = list;
// this.offset = offset;
// this.length = length;
// }
//
// public K peekFirst() {
// return length == 0 ? null : list[offset];
// }
//
// public K peekLast() {
// return length == 0 ? null : list[offset + length - 1];
// }
//
// }
/**
* The array.
*/
@SuppressWarnings
(
"unchecked"
)
K
[]
array
=
(
K
[])
new
Object
[
0
];
/**
* Get the first element, or null if none.
*
* @return the first element
*/
public
K
peekFirst
()
{
K
[]
a
=
array
;
return
a
.
length
==
0
?
null
:
a
[
0
];
}
/**
* Get the last element, or null if none.
*
* @return the last element
*/
public
K
peekLast
()
{
K
[]
a
=
array
;
int
len
=
a
.
length
;
return
len
==
0
?
null
:
a
[
len
-
1
];
}
/**
* Add an element at the end.
*
* @param obj the element
*/
public
synchronized
void
add
(
K
obj
)
{
int
len
=
array
.
length
;
array
=
Arrays
.
copyOf
(
array
,
len
+
1
);
array
[
len
]
=
obj
;
}
/**
* Remove the first element, if it matches.
*
* @param obj the element to remove
* @return true if the element matched and was removed
*/
public
synchronized
boolean
removeFirst
(
K
obj
)
{
if
(
peekFirst
()
!=
obj
)
{
return
false
;
}
int
len
=
array
.
length
;
@SuppressWarnings
(
"unchecked"
)
K
[]
a
=
(
K
[])
new
Object
[
len
-
1
];
System
.
arraycopy
(
array
,
1
,
a
,
0
,
len
-
1
);
array
=
a
;
return
true
;
}
/**
* Remove the last element, if it matches.
*
* @param obj the element to remove
* @return true if the element matched and was removed
*/
public
synchronized
boolean
removeLast
(
K
obj
)
{
if
(
peekLast
()
!=
obj
)
{
return
false
;
}
array
=
Arrays
.
copyOf
(
array
,
array
.
length
-
1
);
return
true
;
}
/**
* Get an iterator over all entries.
*
* @return the iterator
*/
public
Iterator
<
K
>
iterator
()
{
return
new
Iterator
<
K
>()
{
K
[]
a
=
array
;
int
index
;
@Override
public
boolean
hasNext
()
{
return
index
<
a
.
length
;
}
@Override
public
K
next
()
{
return
a
[
index
++];
}
@Override
public
void
remove
()
{
throw
DataUtils
.
newUnsupportedOperationException
(
"remove"
);
}
};
}
}
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
9abf5e1d
...
...
@@ -53,8 +53,8 @@ public class MVMap<K, V> extends AbstractMap<K, V>
private
final
DataType
keyType
;
private
final
DataType
valueType
;
private
Concurrent
Linked
List
<
Page
>
oldRoots
=
new
Concurrent
Linked
List
<
Page
>();
private
Concurrent
Array
List
<
Page
>
oldRoots
=
new
Concurrent
Array
List
<
Page
>();
private
boolean
closed
;
private
boolean
readOnly
;
...
...
h2/src/test/org/h2/test/store/TestConcurrentLinkedList.java
浏览文件 @
9abf5e1d
...
...
@@ -10,7 +10,7 @@ import java.util.LinkedList;
import
java.util.Random
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.h2.mvstore.Concurrent
Linked
List
;
import
org.h2.mvstore.Concurrent
Array
List
;
import
org.h2.test.TestBase
;
import
org.h2.util.Task
;
...
...
@@ -48,8 +48,10 @@ public class TestConcurrentLinkedList extends TestBase {
private
void
testPerformance
(
final
boolean
stock
)
{
System
.
out
.
print
(
stock
?
"stock "
:
"custom "
);
long
start
=
System
.
currentTimeMillis
();
final
ConcurrentLinkedList
<
Integer
>
test
=
new
ConcurrentLinkedList
<
Integer
>();
// final ConcurrentRing<Integer> test = new ConcurrentRing<Integer>();
// final ConcurrentLinkedList<Integer> test =
// new ConcurrentLinkedList<Integer>();
final
ConcurrentArrayList
<
Integer
>
test
=
new
ConcurrentArrayList
<
Integer
>();
final
LinkedList
<
Integer
>
x
=
new
LinkedList
<
Integer
>();
final
AtomicInteger
counter
=
new
AtomicInteger
();
Task
task
=
new
Task
()
{
...
...
@@ -107,7 +109,7 @@ public class TestConcurrentLinkedList extends TestBase {
}
private
void
testConcurrent
()
{
final
Concurrent
LinkedList
<
Integer
>
test
=
new
ConcurrentLinked
List
<
Integer
>();
final
Concurrent
ArrayList
<
Integer
>
test
=
new
ConcurrentArray
List
<
Integer
>();
// final ConcurrentRing<Integer> test = new ConcurrentRing<Integer>();
final
AtomicInteger
counter
=
new
AtomicInteger
();
final
AtomicInteger
size
=
new
AtomicInteger
();
...
...
@@ -140,7 +142,7 @@ public class TestConcurrentLinkedList extends TestBase {
private
void
testRandomized
()
{
Random
r
=
new
Random
(
0
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
Concurrent
LinkedList
<
Integer
>
test
=
new
ConcurrentLinked
List
<
Integer
>();
Concurrent
ArrayList
<
Integer
>
test
=
new
ConcurrentArray
List
<
Integer
>();
// ConcurrentRing<Integer> test = new ConcurrentRing<Integer>();
LinkedList
<
Integer
>
x
=
new
LinkedList
<
Integer
>();
StringBuilder
buff
=
new
StringBuilder
();
...
...
h2/src/
main/org/h2/mvstore
/ConcurrentLinkedList.java
→
h2/src/
tools/org/h2/dev/util
/ConcurrentLinkedList.java
浏览文件 @
9abf5e1d
...
...
@@ -3,10 +3,12 @@
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
mvstore
;
package
org
.
h2
.
dev
.
util
;
import
java.util.Iterator
;
import
org.h2.mvstore.DataUtils
;
/**
* A very simple linked list that supports concurrent access.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论