| 130 | } |
| 131 | |
| 132 | void 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 | |
| 162 | int main() |
| 163 | { |