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
a9e057e0
You need to sign in or sign up before continuing.
Commit
a9e057e0
authored
Apr 12, 2014
by
antirez
Browse files
Abstract hllSparseAdd() / hllDenseAdd() via hllAdd().
parent
0b7d08ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/hyperloglog.c
View file @
a9e057e0
...
@@ -909,6 +909,16 @@ uint64_t hllCount(struct hllhdr *hdr) {
...
@@ -909,6 +909,16 @@ uint64_t hllCount(struct hllhdr *hdr) {
return
(
uint64_t
)
E
;
return
(
uint64_t
)
E
;
}
}
/* Call hllDenseAdd() or hllSparseAdd() according to the HLL encoding. */
int
hllAdd
(
robj
*
o
,
unsigned
char
*
ele
,
size_t
elesize
)
{
struct
hllhdr
*
hdr
=
o
->
ptr
;
switch
(
hdr
->
encoding
)
{
case
HLL_DENSE
:
return
hllDenseAdd
(
hdr
->
registers
,
ele
,
elesize
);
case
HLL_SPARSE
:
return
hllSparseAdd
(
o
,
ele
,
elesize
);
default:
return
-
1
;
/* Invalid representation. */
}
}
/* ========================== HyperLogLog commands ========================== */
/* ========================== HyperLogLog commands ========================== */
/* Create an HLL object. We always create the HLL using sparse encoding.
/* Create an HLL object. We always create the HLL using sparse encoding.
...
@@ -996,14 +1006,19 @@ void pfaddCommand(redisClient *c) {
...
@@ -996,14 +1006,19 @@ void pfaddCommand(redisClient *c) {
o
=
dbUnshareStringValue
(
c
->
db
,
c
->
argv
[
1
],
o
);
o
=
dbUnshareStringValue
(
c
->
db
,
c
->
argv
[
1
],
o
);
}
}
/* Perform the low level ADD operation for every element. */
/* Perform the low level ADD operation for every element. */
hdr
=
o
->
ptr
;
for
(
j
=
2
;
j
<
c
->
argc
;
j
++
)
{
for
(
j
=
2
;
j
<
c
->
argc
;
j
++
)
{
if
(
hllDenseAdd
(
hdr
->
registers
,
(
unsigned
char
*
)
c
->
argv
[
j
]
->
ptr
,
int
retval
=
hllAdd
(
o
,
(
unsigned
char
*
)
c
->
argv
[
j
]
->
ptr
,
sdslen
(
c
->
argv
[
j
]
->
ptr
)))
sdslen
(
c
->
argv
[
j
]
->
ptr
));
{
switch
(
retval
)
{
case
1
:
updated
++
;
updated
++
;
break
;
case
-
1
:
addReplyError
(
c
,
"Invalid HyperLogLog representation"
);
return
;
}
}
}
}
hdr
=
o
->
ptr
;
if
(
updated
)
{
if
(
updated
)
{
signalModifiedKey
(
c
->
db
,
c
->
argv
[
1
]);
signalModifiedKey
(
c
->
db
,
c
->
argv
[
1
]);
notifyKeyspaceEvent
(
REDIS_NOTIFY_STRING
,
"pfadd"
,
c
->
argv
[
1
],
c
->
db
->
id
);
notifyKeyspaceEvent
(
REDIS_NOTIFY_STRING
,
"pfadd"
,
c
->
argv
[
1
],
c
->
db
->
id
);
...
...
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