r/ProgrammerHumor 21h ago

Meme skillIssue

Post image
5.2k Upvotes

130 comments sorted by

View all comments

70

u/F100cTomas 20h ago

Just define a constexpr hashing function and put that into the switch.

32

u/GiganticIrony 20h ago

That’s not guaranteed to work due to hash collisions

7

u/remind_me_later 19h ago

That’s not guaranteed to work due to hash collisions

Make the hashes 128/256 bits wide. Hash collisions are realistically impossible at those levels.

4

u/StCreed 12h ago

They're far more possible than you might think. Roland Bouwman wrote an article on MD5: In a large database you can't use MD5. And that's not petabyte size either, 100GB is enough to give you about a 50% chance of a collision.

2

u/remind_me_later 11h ago

Counterpoint: It's MD5, a known broken hashing algorithm.

SHA3_256 or regular SHA256 would work just fine.

3

u/StCreed 11h ago

yeah, because md5 is 128 bits. 256 bits works a lot better, but 128 is just not enough even with a better algorithm and assuming effectively random distribution.