Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
3ed947fb
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3ed947fb
编写于
3月 29, 2014
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
HLLCOUNT 3x faster taking fast path for default params.
上级
28dce36f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
47 addition
and
11 deletion
+47
-11
src/hyperloglog.c
src/hyperloglog.c
+47
-11
未找到文件。
src/hyperloglog.c
浏览文件 @
3ed947fb
...
...
@@ -290,16 +290,52 @@ uint64_t hllCount(uint8_t *registers) {
initialized
=
1
;
}
/* Compute SUM(2^-register[0..i]). */
for
(
j
=
0
;
j
<
REDIS_HLL_REGISTERS
;
j
++
)
{
unsigned
long
reg
;
HLL_GET_REGISTER
(
reg
,
registers
,
j
);
if
(
reg
==
0
)
{
ez
++
;
E
+=
1
;
/* 2^(-reg[j]) is 1 when m is 0. */
}
else
{
E
+=
PE
[
reg
];
/* Precomputed 2^(-reg[j]). */
/* Compute SUM(2^-register[0..i]).
* Redis default is to use 16384 registers 6 bits each. The code works
* with other values by modifying the defines, but for our target value
* we take a faster path with unrolled loops. */
if
(
REDIS_HLL_REGISTERS
==
16384
&&
REDIS_HLL_BITS
==
6
&&
1
)
{
uint8_t
*
r
=
registers
;
unsigned
long
r0
,
r1
,
r2
,
r3
,
r4
,
r5
,
r6
,
r7
,
r8
,
r9
,
r10
,
r11
,
r12
,
r13
,
r14
,
r15
;
for
(
j
=
0
;
j
<
1024
;
j
++
)
{
/* Handle 16 registers per iteration. */
r0
=
r
[
0
]
&
63
;
if
(
r0
==
0
)
ez
++
;
r1
=
(
r
[
0
]
<<
6
|
r
[
1
]
>>
2
)
&
63
;
if
(
r1
==
0
)
ez
++
;
r2
=
(
r
[
1
]
<<
4
|
r
[
2
]
>>
4
)
&
63
;
if
(
r2
==
0
)
ez
++
;
r3
=
((
r
[
2
]
<<
2
)
|
(
r
[
3
]
>>
6
))
&
63
;
if
(
r3
==
0
)
ez
++
;
r4
=
(
r
[
3
]
|
r
[
4
]
>>
8
)
&
63
;
if
(
r4
==
0
)
ez
++
;
r5
=
(
r
[
3
]
<<
6
|
r
[
4
]
>>
2
)
&
63
;
if
(
r5
==
0
)
ez
++
;
r6
=
(
r
[
4
]
<<
4
|
r
[
5
]
>>
4
)
&
63
;
if
(
r6
==
0
)
ez
++
;
r7
=
(
r
[
5
]
<<
2
|
r
[
6
]
>>
6
)
&
63
;
if
(
r7
==
0
)
ez
++
;
r8
=
(
r
[
6
]
|
r
[
7
]
>>
8
)
&
63
;
if
(
r8
==
0
)
ez
++
;
r9
=
(
r
[
6
]
<<
6
|
r
[
7
]
>>
2
)
&
63
;
if
(
r9
==
0
)
ez
++
;
r10
=
(
r
[
7
]
<<
4
|
r
[
8
]
>>
4
)
&
63
;
if
(
r10
==
0
)
ez
++
;
r11
=
(
r
[
8
]
<<
2
|
r
[
9
]
>>
6
)
&
63
;
if
(
r11
==
0
)
ez
++
;
r12
=
(
r
[
9
]
|
r
[
10
]
>>
8
)
&
63
;
if
(
r12
==
0
)
ez
++
;
r13
=
(
r
[
9
]
<<
6
|
r
[
10
]
>>
2
)
&
63
;
if
(
r13
==
0
)
ez
++
;
r14
=
(
r
[
10
]
<<
4
|
r
[
11
]
>>
4
)
&
63
;
if
(
r14
==
0
)
ez
++
;
r15
=
(
r
[
11
]
<<
2
|
r
[
12
]
>>
6
)
&
63
;
if
(
r15
==
0
)
ez
++
;
/* Additional parens will allow the compiler to optimize the
* code more with a loss of precision that is not very relevant
* here (floating point math is not commutative!). */
E
+=
(
PE
[
r0
]
+
PE
[
r1
])
+
(
PE
[
r2
]
+
PE
[
r3
])
+
(
PE
[
r4
]
+
PE
[
r5
])
+
(
PE
[
r6
]
+
PE
[
r7
])
+
(
PE
[
r8
]
+
PE
[
r9
])
+
(
PE
[
r10
]
+
PE
[
r11
])
+
(
PE
[
r12
]
+
PE
[
r13
])
+
(
PE
[
r14
]
+
PE
[
r15
]);
r
+=
12
;
}
}
else
{
for
(
j
=
0
;
j
<
REDIS_HLL_REGISTERS
;
j
++
)
{
unsigned
long
reg
;
HLL_GET_REGISTER
(
reg
,
registers
,
j
);
if
(
reg
==
0
)
{
ez
++
;
E
+=
1
;
/* 2^(-reg[j]) is 1 when m is 0. */
}
else
{
E
+=
PE
[
reg
];
/* Precomputed 2^(-reg[j]). */
}
}
}
/* Muliply the inverse of E for alpha_m * m^2 to have the raw estimate. */
...
...
@@ -376,7 +412,7 @@ void hllCountCommand(redisClient *c) {
if
(
o
==
NULL
)
{
/* No key? Cardinality is zero since no element was added, otherwise
* we would have a key as H
H
LADD creates it as a side effect. */
* we would have a key as H
L
LADD creates it as a side effect. */
addReply
(
c
,
shared
.
czero
);
}
else
{
/* Key exists, check type */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录