3 ms·
You could still use a TreeSet which only requires ordering and equality, but not hashing. As a side note, though, your earlier example would not be comparable
by ygra 8y ago
You could still use a TreeSet which only requires ordering and equality, but not hashing.
As a side note, though, your earlier example would not be comparable via Equals, as it violates transitivity. Which is also what makes it impossible to generate a hash code consistent with its Equals implementation.
- _cs2017_ 8y agoOh yeah absolutely you can use better structures even without hashing, I was just saying that a hash table isn't always an option. Lack of transitivity: you can still dedupe based on a transitive closure of whatever relationship I provide. It's easy if I want to dedupe numbers closer than 0.01 (using sorting) but much harder to do it efficiently for vectors.
- Thiez 8y ago> Which is also what makes it impossible to generate a hash code consistent with its Equals implementation. How so? `return 0;` is always a legal hash function, albeit a pretty lousy one.