Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Questdb
提交
519c40d1
Q
Questdb
项目概览
jobily
/
Questdb
12 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
Questdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
519c40d1
编写于
12月 13, 2014
作者:
V
Vlad Ilyushchenko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tidying up hash function
上级
67b4cfb8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
15 addition
and
124 deletion
+15
-124
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Hash.java
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Hash.java
+0
-62
nfsdb-core/src/main/java/com/nfsdb/journal/utils/MemoryBuffer.java
...e/src/main/java/com/nfsdb/journal/utils/MemoryBuffer.java
+0
-25
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Rnd.java
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Rnd.java
+8
-0
nfsdb-core/src/test/java/com/nfsdb/journal/lang/experimental/HashTest.java
...st/java/com/nfsdb/journal/lang/experimental/HashTest.java
+7
-37
未找到文件。
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Hash.java
浏览文件 @
519c40d1
...
...
@@ -36,68 +36,6 @@ public class Hash {
return
(
value
>>>
n
)
|
(
value
<<
(
32
-
n
));
}
public
static
int
hashXX
(
MemoryBuffer
data
,
int
seed
)
{
int
i32
;
int
p
=
0
;
int
len
=
data
.
length
();
if
(
len
>=
16
)
{
int
limit
=
len
-
16
;
int
v1
=
seed
+
PRIME32_1
+
PRIME32_2
;
int
v2
=
seed
+
PRIME32_2
;
int
v3
=
seed
;
int
v4
=
seed
-
PRIME32_1
;
do
{
v1
+=
data
.
getInt
(
p
)
*
PRIME32_2
;
v1
=
rotl
(
v1
,
13
);
v1
*=
PRIME32_1
;
p
+=
4
;
v2
+=
data
.
getInt
(
p
)
*
PRIME32_2
;
v2
=
rotl
(
v2
,
13
);
v2
*=
PRIME32_1
;
p
+=
4
;
v3
+=
data
.
getInt
(
p
)
*
PRIME32_2
;
v3
=
rotl
(
v3
,
13
);
v3
*=
PRIME32_1
;
p
+=
4
;
int
i
=
data
.
getInt
(
p
);
v4
+=
i
*
PRIME32_2
;
v4
=
rotl
(
v4
,
13
);
v4
*=
PRIME32_1
;
p
+=
4
;
}
while
(
p
<=
limit
);
i32
=
rotl
(
v1
,
1
)
+
rotl
(
v2
,
7
)
+
rotl
(
v3
,
12
)
+
rotl
(
v4
,
18
);
}
else
{
i32
=
seed
+
PRIME32_5
;
}
i32
+=
len
;
while
(
p
+
4
<=
len
)
{
i32
+=
data
.
getInt
(
p
)
*
PRIME32_3
;
i32
=
rotl
(
i32
,
17
)
*
PRIME32_4
;
p
+=
4
;
}
while
(
p
<
len
)
{
i32
+=
data
.
getByte
(
p
)
*
PRIME32_5
;
i32
=
rotl
(
i32
,
11
)
*
PRIME32_1
;
p
++;
}
i32
^=
i32
>>
15
;
i32
*=
PRIME32_2
;
i32
^=
i32
>>
13
;
i32
*=
PRIME32_3
;
i32
^=
i32
>>
16
;
return
i32
;
}
public
static
int
hashXX
(
long
address
,
int
len
,
int
seed
)
{
int
i32
;
long
p
=
address
;
...
...
nfsdb-core/src/main/java/com/nfsdb/journal/utils/MemoryBuffer.java
已删除
100644 → 0
浏览文件 @
67b4cfb8
/*
* Copyright (c) 2014. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.nfsdb.journal.utils
;
public
interface
MemoryBuffer
{
int
length
();
int
getInt
(
int
p
);
byte
getByte
(
int
p
);
}
\ No newline at end of file
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Rnd.java
浏览文件 @
519c40d1
...
...
@@ -63,6 +63,14 @@ public class Rnd {
return
new
String
(
chars
);
}
public
void
nextChars
(
long
address
,
int
len
)
{
long
limit
=
address
+
len
-
2
;
while
(
address
<
limit
)
{
Unsafe
.
getUnsafe
().
putChar
(
address
,
(
char
)
(
nextPositiveInt
()
%
25
+
66
));
address
+=
2
;
}
}
public
byte
[]
nextBytes
(
int
len
)
{
byte
bytes
[]
=
new
byte
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/lang/experimental/HashTest.java
浏览文件 @
519c40d1
/*
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
* Copyright (c) 2014. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -18,7 +18,6 @@ package com.nfsdb.journal.lang.experimental;
import
com.nfsdb.journal.collections.IntHashSet
;
import
com.nfsdb.journal.utils.Hash
;
import
com.nfsdb.journal.utils.MemoryBuffer
;
import
com.nfsdb.journal.utils.Rnd
;
import
com.nfsdb.journal.utils.Unsafe
;
import
org.junit.Assert
;
...
...
@@ -28,49 +27,20 @@ public class HashTest {
@Test
public
void
testStringHash
()
throws
Exception
{
MemoryBufferImpl
buf
=
new
MemoryBufferImpl
(
30
);
Rnd
rnd
=
new
Rnd
();
IntHashSet
hashes
=
new
IntHashSet
(
100000
);
final
int
LEN
=
30
;
long
address
=
Unsafe
.
getUnsafe
().
allocateMemory
(
LEN
);
for
(
int
i
=
0
;
i
<
100000
;
i
++)
{
buf
.
put
(
rnd
.
nextString
(
15
)
);
hashes
.
add
(
Hash
.
hashXX
(
buf
,
rnd
.
nextInt
()));
rnd
.
nextChars
(
address
,
LEN
);
hashes
.
add
(
Hash
.
hashXX
(
address
,
LEN
,
rnd
.
nextInt
()));
}
Assert
.
assertTrue
(
"Hash function distribution dropped"
,
hashes
.
size
()
>
99990
);
}
private
static
class
MemoryBufferImpl
implements
MemoryBuffer
{
private
final
long
address
;
private
final
int
len
;
public
MemoryBufferImpl
(
int
len
)
{
this
.
len
=
len
;
this
.
address
=
Unsafe
.
getUnsafe
().
allocateMemory
(
len
);
}
@Override
public
int
length
()
{
return
len
;
}
@Override
public
int
getInt
(
int
p
)
{
return
Unsafe
.
getUnsafe
().
getInt
(
address
+
p
);
}
System
.
out
.
println
(
hashes
.
size
());
@Override
public
byte
getByte
(
int
p
)
{
return
Unsafe
.
getUnsafe
().
getByte
(
address
+
p
);
}
Assert
.
assertTrue
(
"Hash function distribution dropped"
,
hashes
.
size
()
>
99990
);
public
void
put
(
CharSequence
value
)
{
for
(
int
i
=
0
;
i
<
value
.
length
();
i
++)
{
Unsafe
.
getUnsafe
().
putChar
(
address
+
i
*
2
,
value
.
charAt
(
i
));
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录