summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-04-13 22:59:27 +0200
committerantirez <antirez@gmail.com>2014-04-16 15:09:46 +0200
commit5786846122a6983b2c79d7161818b033dcfefd2a (patch)
tree58c5b6eb6288dcf2477e9add23e2b805a7f7418d /src
parent68fb3019a09dddbc0e1f6c43a113e4a85addb7a0 (diff)
downloadredis-5786846122a6983b2c79d7161818b033dcfefd2a.tar.gz
hllSparseToDense API changed to take ref to object.
The new API takes directly the object doing everything needed to turn it into a dense representation, including setting the new representation as object->ptr.
Diffstat (limited to 'src')
-rw-r--r--src/hyperloglog.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/hyperloglog.c b/src/hyperloglog.c
index b3235e1fb..0f92ff50a 100644
--- a/src/hyperloglog.c
+++ b/src/hyperloglog.c
@@ -560,12 +560,16 @@ double hllDenseSum(uint8_t *registers, double *PE, int *ezp) {
/* Convert the HLL with sparse representation given as input in its dense
* representation. Both representations are represented by SDS strings, and
* the input representation is freed as a side effect. */
-sds hllSparseToDense(sds sparse) {
- sds dense;
+void hllSparseToDense(robj *o) {
+ sds sparse = o->ptr, dense;
struct hllhdr *hdr, *oldhdr = (struct hllhdr*)sparse;
int idx = 0, runlen, regval;
uint8_t *p = (uint8_t*)sparse, *end = p+sdslen(sparse);
+ /* If the representation is already the right one return ASAP. */
+ hdr = (struct hllhdr*) sparse;
+ if (hdr->encoding == HLL_DENSE) return;
+
/* Create a string of the right size filled with zero bytes.
* Note that the cached cardinality is set to 0 as a side effect
* that is exactly the cardinality of an empty HLL. */
@@ -597,9 +601,9 @@ sds hllSparseToDense(sds sparse) {
}
}
- /* Free the old representation and return the new one. */
- sdsfree(sparse);
- return dense;
+ /* Free the old representation and set the new one. */
+ sdsfree(o->ptr);
+ o->ptr = dense;
}
/* "Add" the element in the sparse hyperloglog data structure.
@@ -805,7 +809,7 @@ updated:
return 1;
promote: /* Promote to dense representation. */
- o->ptr = hllSparseToDense(o->ptr);
+ hllSparseToDense(o);
hdr = o->ptr;
return hllDenseAdd(hdr->registers, ele, elesize);
}