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

Function demonstrateCollisionResistance

examples/xxhash_example.cpp:132–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132void demonstrateCollisionResistance()
133{
134 std::cout << "\n=== Simple Collision Test ===\n\n";
135
136 std::vector<std::string> similarStrings = {
137 "test",
138 "Test",
139 "test1",
140 "test2",
141 "tset", // anagram
142 "testing"
143 };
144
145 uint32_t seed = 0;
146
147 std::cout << "Testing similar strings for hash collisions:\n";
148 for (const auto& str : similarStrings)
149 {
150 choc::hash::xxHash32 hasher32 (seed);
151 hasher32.addInput (str.data(), str.length());
152 uint32_t hash32 = hasher32.getHash();
153
154 std::cout << std::left << std::setw (15) << ("\"" + str + "\"")
155 << " -> 0x" << std::hex << std::setw (8) << std::setfill ('0')
156 << hash32 << std::dec << std::setfill (' ') << "\n";
157 }
158
159 std::cout << "\nNote: Each string produces a different hash (no collisions)\n";
160}
161
162int main()
163{

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