static void S_write_ord(void *ords, int32_t width, int32_t doc_id, int32_t ord) { switch (width) { case 1: if (ord) { NumUtil_u1set(ords, doc_id); } else { NumUtil_u1clear(ords, doc_id); } break; case 2: NumUtil_u2set(ords, doc_id, ord); break; case 4: NumUtil_u4set(ords, doc_id, ord); break; case 8: { uint8_t *ints = (uint8_t*)ords; ints[doc_id] = ord; } break; case 16: { uint8_t *bytes = (uint8_t*)ords; bytes += doc_id * sizeof(uint16_t); NumUtil_encode_bigend_u16(ord, &bytes); } break; case 32: { uint8_t *bytes = (uint8_t*)ords; bytes += doc_id * sizeof(uint32_t); NumUtil_encode_bigend_u32(ord, &bytes); } break; default: THROW(ERR, "Invalid width: %i32", width); } }
static void test_u4(TestBatch *batch) { size_t count = 128; uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, 16); uint8_t *bits = (uint8_t*)CALLOCATE((count / 2), sizeof(uint8_t)); for (size_t i = 0; i < count; i++) { NumUtil_u4set(bits, i, (uint8_t)ints[i]); } for (size_t i = 0; i < count; i++) { TEST_INT_EQ(batch, NumUtil_u4get(bits, i), (long)ints[i], "u4"); } FREEMEM(bits); FREEMEM(ints); }