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