Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
ac8fbe88
Commit
ac8fbe88
authored
Mar 28, 2014
by
antirez
Browse files
HyperLogLog: use precomputed table for 2^(-M[i]).
parent
fdf81b2d
Changes
1
Show whitespace changes
Inline
Side-by-side
src/hyperloglog.c
View file @
ac8fbe88
...
@@ -277,6 +277,19 @@ uint64_t hllCount(uint8_t *registers) {
...
@@ -277,6 +277,19 @@ uint64_t hllCount(uint8_t *registers) {
int
ez
=
0
;
/* Number of registers equal to 0. */
int
ez
=
0
;
/* Number of registers equal to 0. */
int
j
;
int
j
;
/* We precompute 2^(-reg[j]) in a small table in order to
* speedup the computation of SUM(2^-register[0..i]). */
static
int
initialized
=
0
;
static
double
PE
[
64
];
if
(
!
initialized
)
{
PE
[
0
]
=
1
;
/* 2^(-reg[j]) is 1 when m is 0. */
for
(
j
=
1
;
j
<
64
;
j
++
)
{
/* 2^(-reg[j]) is the same as 1/2^reg[j]. */
PE
[
j
]
=
1
.
0
/
(
1ULL
<<
j
);
}
initialized
=
1
;
}
for
(
j
=
0
;
j
<
REDIS_HLL_REGISTERS
;
j
++
)
{
for
(
j
=
0
;
j
<
REDIS_HLL_REGISTERS
;
j
++
)
{
uint8_t
reg
;
uint8_t
reg
;
...
@@ -286,7 +299,7 @@ uint64_t hllCount(uint8_t *registers) {
...
@@ -286,7 +299,7 @@ uint64_t hllCount(uint8_t *registers) {
ez
++
;
ez
++
;
E
+=
1
;
/* 2^(-reg[j]) is 1 when m is 0. */
E
+=
1
;
/* 2^(-reg[j]) is 1 when m is 0. */
}
else
{
}
else
{
E
+=
1
.
0
/
(
1ULL
<<
reg
)
;
/*
2^(-reg[j]) is the same as 1/2^
reg[j]. */
E
+=
PE
[
reg
]
;
/*
Precomputed 2^(-
reg[j]
)
. */
}
}
}
}
/* Muliply the inverse of E for alpha_m * m^2 to have the raw estimate. */
/* Muliply the inverse of E for alpha_m * m^2 to have the raw estimate. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment