MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / createHLLObject

Function createHLLObject

src/hyperloglog.cpp:1124–1154  ·  view source on GitHub ↗

Create an HLL object. We always create the HLL using sparse encoding. * This will be upgraded to the dense representation as needed. */

Source from the content-addressed store, hash-verified

1122/* Create an HLL object. We always create the HLL using sparse encoding.
1123 * This will be upgraded to the dense representation as needed. */
1124robj *createHLLObject(void) {
1125 robj *o;
1126 struct hllhdr *hdr;
1127 sds s;
1128 uint8_t *p;
1129 int sparselen = HLL_HDR_SIZE +
1130 (((HLL_REGISTERS+(HLL_SPARSE_XZERO_MAX_LEN-1)) /
1131 HLL_SPARSE_XZERO_MAX_LEN)*2);
1132 int aux;
1133
1134 /* Populate the sparse representation with as many XZERO opcodes as
1135 * needed to represent all the registers. */
1136 aux = HLL_REGISTERS;
1137 s = sdsnewlen(NULL,sparselen);
1138 p = (uint8_t*)s + HLL_HDR_SIZE;
1139 while(aux) {
1140 int xzero = HLL_SPARSE_XZERO_MAX_LEN;
1141 if (xzero > aux) xzero = aux;
1142 HLL_SPARSE_XZERO_SET(p,xzero);
1143 p += 2;
1144 aux -= xzero;
1145 }
1146 serverAssert((p-(uint8_t*)s) == sparselen);
1147
1148 /* Create the actual object. */
1149 o = createObject(OBJ_STRING,s);
1150 hdr = (hllhdr*)ptrFromObj(o);
1151 memcpy(hdr->magic,"HYLL",4);
1152 hdr->encoding = HLL_SPARSE;
1153 return o;
1154}
1155
1156/* Check if the object is a String with a valid HLL representation.
1157 * Return C_OK if this is true, otherwise reply to the client

Callers 3

pfaddCommandFunction · 0.85
pfmergeCommandFunction · 0.85
pfselftestCommandFunction · 0.85

Calls 3

sdsnewlenFunction · 0.85
createObjectFunction · 0.85
ptrFromObjFunction · 0.85

Tested by

no test coverage detected