-
-
Save t-mat/63b391d628980d5d276a002cc578136f to your computer and use it in GitHub Desktop.
xxHash test program by Stefano Marchini @smarchini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* xxHash test program by Stefano Marchini @smarchini */ | |
/* https://github.com/Cyan4973/xxHash/issues/816#issue-1613505078 */ | |
#define XXH_STATIC_LINKING_ONLY | |
#define XXH_IMPLEMENTATION | |
#include "xxhash.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main() { | |
enum { MAX = 4096 }; | |
size_t errorCount = 0; | |
char *string = malloc(MAX); | |
for (size_t i = 0; i < MAX; i++) string[i] = (char) (rand() & 0xff); | |
for (size_t len = 0; len < MAX; len++) { | |
XXH64_hash_t direct_hash = XXH3_64bits(string, len); | |
XXH3_state_t *state = XXH3_createState(); | |
XXH3_64bits_reset(state); | |
XXH3_64bits_update(state, string, len); | |
XXH64_hash_t streaming_hash = XXH3_64bits_digest(state); | |
if (direct_hash != streaming_hash) { | |
printf("len=%zu", len); | |
printf(", direct=0x"); | |
{ | |
XXH64_canonical_t direct; | |
XXH64_canonicalFromHash(&direct, direct_hash); | |
for (size_t i = 0; i < sizeof(direct.digest); ++i) { | |
printf("%02x", direct.digest[i]); | |
} | |
} | |
printf(", streaming=0x"); | |
{ | |
XXH64_canonical_t streaming; | |
XXH64_canonicalFromHash(&streaming, streaming_hash); | |
for (size_t i = 0; i < sizeof(streaming.digest); ++i) { | |
printf("%02x", streaming.digest[i]); | |
} | |
} | |
printf("\n"); | |
errorCount += 1; | |
} | |
} | |
free(string); | |
exit(errorCount == 0 ? EXIT_SUCCESS : EXIT_FAILURE); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment