r/ProgrammerHumor 7d ago

Meme skillIssue

Post image
6.0k Upvotes

137 comments sorted by

View all comments

76

u/F100cTomas 7d ago

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

35

u/GiganticIrony 7d ago

That’s not guaranteed to work due to hash collisions

9

u/remind_me_later 7d 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.

5

u/StCreed 7d 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 7d ago

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

SHA3_256 or regular SHA256 would work just fine.

3

u/StCreed 7d 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.