MCPcopy Create free account
hub / github.com/Tracktion/choc / demonstrateStreamingHash

Function demonstrateStreamingHash

examples/xxhash_example.cpp:102–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102void demonstrateStreamingHash()
103{
104 std::cout << "\n=== Streaming Hash Demo ===\n\n";
105
106 std::string fullData = "This is a test of streaming hash functionality!";
107 uint32_t seed = 0;
108
109 // Hash all at once
110 choc::hash::xxHash32 hasher_all (seed);
111 hasher_all.addInput (fullData.data(), fullData.length());
112 uint32_t hash_all = hasher_all.getHash();
113
114 // Hash in chunks
115 choc::hash::xxHash32 hasher_chunks (seed);
116 size_t chunkSize = 8;
117
118 for (size_t i = 0; i < fullData.length(); i += chunkSize)
119 {
120 size_t currentChunkSize = std::min (chunkSize, fullData.length() - i);
121 hasher_chunks.addInput (fullData.data() + i, currentChunkSize);
122 }
123
124 uint32_t hash_chunks = hasher_chunks.getHash();
125
126 std::cout << "Full string: \"" << fullData << "\"\n";
127 std::cout << "Hash (all at once): 0x" << std::hex << hash_all << "\n";
128 std::cout << "Hash (8-byte chunks): 0x" << std::hex << hash_chunks << std::dec << "\n";
129 std::cout << "Hashes match: " << (hash_all == hash_chunks ? "YES" : "NO") << "\n";
130}
131
132void demonstrateCollisionResistance()
133{

Callers 1

mainFunction · 0.85

Calls 4

addInputMethod · 0.80
getHashMethod · 0.80
dataMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected