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
c39a0f7c
Commit
c39a0f7c
authored
Dec 22, 2017
by
antirez
Browse files
Hyperloglog: Support for PFMERGE sparse encoding as target.
This is a fix for #3819.
parent
8a012df9
Changes
1
Show whitespace changes
Inline
Side-by-side
src/hyperloglog.c
View file @
c39a0f7c
...
@@ -1298,6 +1298,7 @@ void pfmergeCommand(client *c) {
...
@@ -1298,6 +1298,7 @@ void pfmergeCommand(client *c) {
uint8_t
max
[
HLL_REGISTERS
];
uint8_t
max
[
HLL_REGISTERS
];
struct
hllhdr
*
hdr
;
struct
hllhdr
*
hdr
;
int
j
;
int
j
;
int
use_dense
=
0
;
/* Use dense representation as target? */
/* Compute an HLL with M[i] = MAX(M[i]_j).
/* Compute an HLL with M[i] = MAX(M[i]_j).
* We store the maximum into the max array of registers. We'll write
* We store the maximum into the max array of registers. We'll write
...
@@ -1309,6 +1310,11 @@ void pfmergeCommand(client *c) {
...
@@ -1309,6 +1310,11 @@ void pfmergeCommand(client *c) {
if
(
o
==
NULL
)
continue
;
/* Assume empty HLL for non existing var. */
if
(
o
==
NULL
)
continue
;
/* Assume empty HLL for non existing var. */
if
(
isHLLObjectOrReply
(
c
,
o
)
!=
C_OK
)
return
;
if
(
isHLLObjectOrReply
(
c
,
o
)
!=
C_OK
)
return
;
/* If at least one involved HLL is dense, use the dense representation
* as target ASAP to save time and avoid the conversion step. */
hdr
=
o
->
ptr
;
if
(
hdr
->
encoding
==
HLL_DENSE
)
use_dense
=
1
;
/* Merge with this HLL with our 'max' HHL by setting max[i]
/* Merge with this HLL with our 'max' HHL by setting max[i]
* to MAX(max[i],hll[i]). */
* to MAX(max[i],hll[i]). */
if
(
hllMerge
(
max
,
o
)
==
C_ERR
)
{
if
(
hllMerge
(
max
,
o
)
==
C_ERR
)
{
...
@@ -1332,8 +1338,9 @@ void pfmergeCommand(client *c) {
...
@@ -1332,8 +1338,9 @@ void pfmergeCommand(client *c) {
o
=
dbUnshareStringValue
(
c
->
db
,
c
->
argv
[
1
],
o
);
o
=
dbUnshareStringValue
(
c
->
db
,
c
->
argv
[
1
],
o
);
}
}
/* Only support dense objects as destination. */
/* Convert the destination object to dense representation if at least
if
(
hllSparseToDense
(
o
)
==
C_ERR
)
{
* one of the inputs was dense. */
if
(
use_dense
&&
hllSparseToDense
(
o
)
==
C_ERR
)
{
addReplySds
(
c
,
sdsnew
(
invalid_hll_err
));
addReplySds
(
c
,
sdsnew
(
invalid_hll_err
));
return
;
return
;
}
}
...
@@ -1342,7 +1349,11 @@ void pfmergeCommand(client *c) {
...
@@ -1342,7 +1349,11 @@ void pfmergeCommand(client *c) {
* invalidate the cached value. */
* invalidate the cached value. */
hdr
=
o
->
ptr
;
hdr
=
o
->
ptr
;
for
(
j
=
0
;
j
<
HLL_REGISTERS
;
j
++
)
{
for
(
j
=
0
;
j
<
HLL_REGISTERS
;
j
++
)
{
HLL_DENSE_SET_REGISTER
(
hdr
->
registers
,
j
,
max
[
j
]);
if
(
max
[
j
]
==
0
)
continue
;
switch
(
hdr
->
encoding
)
{
case
HLL_DENSE
:
hllDenseSet
(
hdr
->
registers
,
j
,
max
[
j
]);
break
;
case
HLL_SPARSE
:
hllSparseSet
(
o
,
j
,
max
[
j
]);
break
;
}
}
}
HLL_INVALIDATE_CACHE
(
hdr
);
HLL_INVALIDATE_CACHE
(
hdr
);
...
...
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