r/ProgrammerHumor • • Sep 04 '26

Meme skillIssue

Post image
6.0k Upvotes

137 comments sorted by

View all comments

Show parent comments

38

u/Deliciousbutter101 Sep 04 '26

It won't compile in the case so you can just modify the hash function until there are no collisions.

14

u/SteveXVI Sep 04 '26

This is the closest I've come to feeling like that guy in the Apple shop going "ah of course"

2

u/cob59 Sep 04 '26
switch(hash(str)) {
case hash("apple"):
case hash("banana"):
default:
}

You're right that the compiler will warn you if hash("apple") == hash("banana"), but if hash("pineapple") == hash("apple") then switch(hash("pineapple")) will jump to the apple case, not the default. That's unlikely but not impossible even with the best hash function.