3 ms·
Maybe a data structure where you have an array of data and its hashed value, an eq implementation needs to go over the array to compare, but the ne implementati
by unrealhoang 4y ago
Maybe a data structure where you have an array of data and its hashed value, an eq implementation needs to go over the array to compare, but the ne implementation can short circuit by just comparing the hash. hash(a) != hash(b) => a != b, the reverse doesn't hold.
- brundolf 4y agoI thought about that sort of thing too, but eq returns equal-or-not-equal, so it could apply the same short-circuit Simpler example: if two lists don't have the same length you know they're unequal without looking at the items. But you could early-terminate eq the same way and actually benefit both eq and ne
- remram 4y agoThat is not true, the eq method can also short-circuit, in the same situation (hashes are different).