예제 #1
0
파일: SortCollector.c 프로젝트: theory/lucy
static INLINE int32_t
SI_compare_by_ord32(SortCollectorIVARS *ivars, uint32_t tick,
                    int32_t a, int32_t b) {
    uint8_t *ord_bytes = (uint8_t*)ivars->ord_arrays[tick];
    uint8_t *address_a = ord_bytes + a * sizeof(uint32_t);
    uint8_t *address_b = ord_bytes + b * sizeof(uint32_t);
    int32_t  ord_a = NumUtil_decode_bigend_u32(address_a);
    int32_t  ord_b = NumUtil_decode_bigend_u32(address_b);
    return ord_a - ord_b;
}
예제 #2
0
static void
test_bigend_u32(TestBatch *batch) {
    size_t    count     = 32;
    uint64_t *ints      = TestUtils_random_u64s(NULL, count, 0, U64_C(1) + U32_MAX);
    size_t    amount    = (count + 1) * sizeof(uint32_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_u32((uint32_t)ints[i], &target);
        target += sizeof(uint32_t);
    }
    target = encoded;
    for (size_t i = 0; i < count; i++) {
        uint32_t got = NumUtil_decode_bigend_u32(target);
        TEST_INT_EQ(batch, got, (long)ints[i], "bigend u32");
        target += sizeof(uint32_t);
    }

    target = encoded;
    NumUtil_encode_bigend_u32(1, &target);
    TEST_INT_EQ(batch, encoded[0], 0, "Truly big-endian u32");
    TEST_INT_EQ(batch, encoded[3], 1, "Truly big-endian u32");

    FREEMEM(allocated);
    FREEMEM(ints);
}
예제 #3
0
파일: InStream.c 프로젝트: theory/lucy
float
InStream_read_f32(InStream *self) {
    union { float f; uint32_t u32; } duo;
    SI_read_bytes(self, (char*)&duo, sizeof(float));
#ifdef LITTLE_END
    duo.u32 = NumUtil_decode_bigend_u32(&duo.u32);
#endif
    return duo.f;
}
예제 #4
0
파일: InStream.c 프로젝트: theory/lucy
static INLINE uint32_t
SI_read_u32(InStream *self) {
    uint32_t retval;
    SI_read_bytes(self, (char*)&retval, 4);
#ifdef LITTLE_END
    retval = NumUtil_decode_bigend_u32((char*)&retval);
#endif
    return retval;
}
예제 #5
0
파일: SortCache.c 프로젝트: apache/lucy
int32_t
SortCache_Ordinal_IMP(SortCache *self, int32_t doc_id) {
    SortCacheIVARS *const ivars = SortCache_IVARS(self);
    if (doc_id > ivars->doc_max || doc_id < 0) {
        THROW(ERR, "Out of range: %i32 max: %i32", doc_id, ivars->doc_max);
    }
    switch (ivars->ord_width) {
        case 1: return NumUtil_u1get(ivars->ords, (uint32_t)doc_id);
        case 2: return NumUtil_u2get(ivars->ords, (uint32_t)doc_id);
        case 4: return NumUtil_u4get(ivars->ords, (uint32_t)doc_id);
        case 8: {
                uint8_t *ints = (uint8_t*)ivars->ords;
                return ints[doc_id];
            }
        case 16:
            if (ivars->native_ords) {
                uint16_t *ints = (uint16_t*)ivars->ords;
                return ints[doc_id];
            }
            else {
                uint8_t *bytes = (uint8_t*)ivars->ords;
                bytes += (size_t)doc_id * sizeof(uint16_t);
                return NumUtil_decode_bigend_u16(bytes);
            }
        case 32:
            if (ivars->native_ords) {
                int32_t *ints = (int32_t*)ivars->ords;
                return ints[doc_id];
            }
            else {
                uint8_t *bytes = (uint8_t*)ivars->ords;
                bytes += (size_t)doc_id * sizeof(int32_t);
                return (int32_t)NumUtil_decode_bigend_u32(bytes);
            }
        default: {
                THROW(ERR, "Invalid ord width: %i32", ivars->ord_width);
                UNREACHABLE_RETURN(int32_t);
            }
    }
}