Alexandre B A Villares 🐍 on Nostr: Today, implementing a custom __hash__() for a class, I had to deal with the fact that ...
Today, implementing a custom __hash__() for a class, I had to deal with the fact that in many #Python implementations hash(-1) is equal to hash(-2), both are -2, and so are the hashes of (-1, -1, -1, -1) and (-2, -2, -2, -2). The good news is that I knew about hash collisions and could quickly figure out the problem and manage a workaround :)
Published at
2024-10-31 16:51:52Event JSON
{
"id": "59dc249c3afd21930b308e98eb1390d6309af8a63e9a187454e59ca7a61e5431",
"pubkey": "883b5e42e69fa4eb2bee76e555c217028b48dc7676f61453c7f506fd1a33ab62",
"created_at": 1730393512,
"kind": 1,
"tags": [
[
"t",
"python"
],
[
"proxy",
"https://ciberlandia.pt/users/villares/statuses/113403069209721627",
"activitypub"
]
],
"content": "Today, implementing a custom __hash__() for a class, I had to deal with the fact that in many #Python implementations hash(-1) is equal to hash(-2), both are -2, and so are the hashes of (-1, -1, -1, -1) and (-2, -2, -2, -2). The good news is that I knew about hash collisions and could quickly figure out the problem and manage a workaround :)",
"sig": "f8e18b9fe1d07a0480e473add270e868ed44db46ccc7a01b05e50939018704e9d7b46d298ac92ccd933fd901a1c7332d1931545f849cf490ee41ed99f8f825e6"
}