#define XXH_INLINE_ALL #include "vendor_xxhash.h" #include "include/cxxhash.h" #include uint64_t cxx_xxh3_64(const void *data, size_t len) { return XXH3_64bits(data, len); } cxx_hash128 cxx_xxh3_128(const void *data, size_t len) { XXH128_hash_t h = XXH3_128bits(data, len); cxx_hash128 out = { h.low64, h.high64 }; return out; } struct cxx_xxh3_state { XXH3_state_t *st; int is128; }; cxx_xxh3_state *cxx_xxh3_create(int is128) { cxx_xxh3_state *s = malloc(sizeof(cxx_xxh3_state)); if (!s) return NULL; s->st = XXH3_createState(); s->is128 = is128; if (is128) XXH3_128bits_reset(s->st); else XXH3_64bits_reset(s->st); return s; } void cxx_xxh3_update(cxx_xxh3_state *s, const void *data, size_t len) { if (s->is128) XXH3_128bits_update(s->st, data, len); else XXH3_64bits_update(s->st, data, len); } uint64_t cxx_xxh3_digest64(cxx_xxh3_state *s) { return XXH3_64bits_digest(s->st); } cxx_hash128 cxx_xxh3_digest128(cxx_xxh3_state *s) { XXH128_hash_t h = XXH3_128bits_digest(s->st); cxx_hash128 out = { h.low64, h.high64 }; return out; } void cxx_xxh3_free(cxx_xxh3_state *s) { if (s) { XXH3_freeState(s->st); free(s); } }