static void test_bigend_u16(TestBatch *batch) { size_t count = 32; uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, U16_MAX + 1); size_t amount = (count + 1) * sizeof(uint16_t); char *allocated = (char*)CALLOCATE(amount, sizeof(char)); char *encoded = allocated + 1; // Intentionally misaligned. char *target = encoded; for (size_t i = 0; i < count; i++) { NumUtil_encode_bigend_u16((uint16_t)ints[i], &target); target += sizeof(uint16_t); } target = encoded; for (size_t i = 0; i < count; i++) { uint16_t got = NumUtil_decode_bigend_u16(target); TEST_INT_EQ(batch, got, (long)ints[i], "bigend u16"); target += sizeof(uint16_t); } target = encoded; NumUtil_encode_bigend_u16(1, &target); TEST_INT_EQ(batch, encoded[0], 0, "Truly big-endian u16"); TEST_INT_EQ(batch, encoded[1], 1, "Truly big-endian u16"); FREEMEM(allocated); FREEMEM(ints); }
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); } }