XXH_FORCE_INLINE XXH_errorcode XXH3_update()

in src/mlio-py/mlio/contrib/insights/hll/xxh3.h [1322:1388]


XXH_FORCE_INLINE XXH_errorcode XXH3_update(XXH3_state_t *state,
                                           const xxh_u8 *input,
                                           size_t len,
                                           XXH3_accWidth_e accWidth)
{
    if (input == NULL)
#if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER >= 1)
        return XXH_OK;
#else
        return XXH_ERROR;
#endif

    {
        const xxh_u8 *const bEnd = input + len;

        state->totalLen += len;

        if (state->bufferedSize + len <= XXH3_INTERNALBUFFER_SIZE) { /* fill in tmp buffer */
            XXH_memcpy(state->buffer + state->bufferedSize, input, len);
            state->bufferedSize += (XXH32_hash_t) len;
            return XXH_OK;
        }
        /* input now > XXH3_INTERNALBUFFER_SIZE */

#define XXH3_INTERNALBUFFER_STRIPES (XXH3_INTERNALBUFFER_SIZE / STRIPE_LEN)
        XXH_STATIC_ASSERT(XXH3_INTERNALBUFFER_SIZE % STRIPE_LEN == 0); /* clean multiple */

        if (state->bufferedSize) { /* some input within internal buffer: fill
                                      then consume it */
            size_t const loadSize = XXH3_INTERNALBUFFER_SIZE - state->bufferedSize;
            XXH_memcpy(state->buffer + state->bufferedSize, input, loadSize);
            input += loadSize;
            XXH3_consumeStripes(state->acc,
                                &state->nbStripesSoFar,
                                state->nbStripesPerBlock,
                                state->buffer,
                                XXH3_INTERNALBUFFER_STRIPES,
                                state->secret,
                                state->secretLimit,
                                accWidth);
            state->bufferedSize = 0;
        }

        /* consume input by full buffer quantities */
        if (input + XXH3_INTERNALBUFFER_SIZE <= bEnd) {
            const xxh_u8 *const limit = bEnd - XXH3_INTERNALBUFFER_SIZE;
            do {
                XXH3_consumeStripes(state->acc,
                                    &state->nbStripesSoFar,
                                    state->nbStripesPerBlock,
                                    input,
                                    XXH3_INTERNALBUFFER_STRIPES,
                                    state->secret,
                                    state->secretLimit,
                                    accWidth);
                input += XXH3_INTERNALBUFFER_SIZE;
            } while (input <= limit);
        }

        if (input < bEnd) { /* some remaining input input : buffer it */
            XXH_memcpy(state->buffer, input, (size_t)(bEnd - input));
            state->bufferedSize = (XXH32_hash_t)(bEnd - input);
        }
    }

    return XXH_OK;
}