| 5 | #include "../choc/memory/choc_xxHash.h" |
| 6 | |
| 7 | void demonstrateBasicHashing() |
| 8 | { |
| 9 | std::cout << "=== Basic xxHash Demonstration ===\n\n"; |
| 10 | |
| 11 | std::vector<std::string> testStrings = { |
| 12 | "Hello, CHOC!", |
| 13 | "Hello, world!", |
| 14 | "The quick brown fox jumps over the lazy dog", |
| 15 | "", // Empty string |
| 16 | "A", // Single character |
| 17 | "xxHash is a fast hashing algorithm" |
| 18 | }; |
| 19 | |
| 20 | uint32_t seed = 0; |
| 21 | |
| 22 | std::cout << "32-bit Hashes:\n"; |
| 23 | std::cout << std::setfill ('-') << std::setw (70) << "" << std::setfill (' ') << "\n"; |
| 24 | |
| 25 | for (const auto& str : testStrings) |
| 26 | { |
| 27 | choc::hash::xxHash32 hasher32 (seed); |
| 28 | hasher32.addInput (str.data(), str.length()); |
| 29 | uint32_t hash32 = hasher32.getHash(); |
| 30 | |
| 31 | std::cout << std::left << std::setw (40) << ("\"" + str + "\"") |
| 32 | << " -> 0x" << std::hex << std::setw (8) << std::setfill ('0') |
| 33 | << hash32 << std::dec << std::setfill (' ') << "\n"; |
| 34 | } |
| 35 | |
| 36 | std::cout << "\n64-bit Hashes:\n"; |
| 37 | std::cout << std::setfill ('-') << std::setw (70) << "" << std::setfill (' ') << "\n"; |
| 38 | |
| 39 | for (const auto& str : testStrings) |
| 40 | { |
| 41 | choc::hash::xxHash64 hasher64 (seed); |
| 42 | hasher64.addInput (str.data(), str.length()); |
| 43 | uint64_t hash64 = hasher64.getHash(); |
| 44 | |
| 45 | std::cout << std::left << std::setw (40) << ("\"" + str + "\"") |
| 46 | << " -> 0x" << std::hex << std::setw (16) << std::setfill ('0') |
| 47 | << hash64 << std::dec << std::setfill (' ') << "\n"; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | void demonstrateHashConsistency() |
| 52 | { |