Commit e8e717e1 authored by antirez's avatar antirez
Browse files

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.
parent 2067644a
...@@ -560,12 +560,16 @@ double hllDenseSum(uint8_t *registers, double *PE, int *ezp) { ...@@ -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 /* Convert the HLL with sparse representation given as input in its dense
* representation. Both representations are represented by SDS strings, and * representation. Both representations are represented by SDS strings, and
* the input representation is freed as a side effect. */ * the input representation is freed as a side effect. */
sds hllSparseToDense(sds sparse) { void hllSparseToDense(robj *o) {
sds dense; sds sparse = o->ptr, dense;
struct hllhdr *hdr, *oldhdr = (struct hllhdr*)sparse; struct hllhdr *hdr, *oldhdr = (struct hllhdr*)sparse;
int idx = 0, runlen, regval; int idx = 0, runlen, regval;
uint8_t *p = (uint8_t*)sparse, *end = p+sdslen(sparse); 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. /* Create a string of the right size filled with zero bytes.
* Note that the cached cardinality is set to 0 as a side effect * Note that the cached cardinality is set to 0 as a side effect
* that is exactly the cardinality of an empty HLL. */ * that is exactly the cardinality of an empty HLL. */
...@@ -597,9 +601,9 @@ sds hllSparseToDense(sds sparse) { ...@@ -597,9 +601,9 @@ sds hllSparseToDense(sds sparse) {
} }
} }
/* Free the old representation and return the new one. */ /* Free the old representation and set the new one. */
sdsfree(sparse); sdsfree(o->ptr);
return dense; o->ptr = dense;
} }
/* "Add" the element in the sparse hyperloglog data structure. /* "Add" the element in the sparse hyperloglog data structure.
...@@ -805,7 +809,7 @@ updated: ...@@ -805,7 +809,7 @@ updated:
return 1; return 1;
promote: /* Promote to dense representation. */ promote: /* Promote to dense representation. */
o->ptr = hllSparseToDense(o->ptr); hllSparseToDense(o);
hdr = o->ptr; hdr = o->ptr;
return hllDenseAdd(hdr->registers, ele, elesize); return hllDenseAdd(hdr->registers, ele, elesize);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment