[Python-Dev] Why not using the hash when comparing strings? (original) (raw)
MRAB python at mrabarnett.plus.com
Fri Oct 19 03:30:41 CEST 2012
- Previous message: [Python-Dev] Why not using the hash when comparing strings?
- Next message: [Python-Dev] Rejecting PEPs 407 and 413?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2012-10-19 02:03, Victor Stinner wrote:
Hi,
I would like to know if there a reason for not using the hash of (bytes or unicode) strings when comparing two objects and the hash of the two objects was already been computed. Using the hash would speed up comparaison of long strings when the two strings are different. Something like: if ((op == PyEQ || op == PyNE) && a->obshash != -1 && b->obshash != -1 && a->obshash != b->obshash) { /* strings are not equal */ } There are hash collision, so a->obshash == b->obshash doesn't mean that the two strings are equal. But if the two hashs are different, the two strings are different. Isn't it? Correct. It's true for any hashable type.
- Previous message: [Python-Dev] Why not using the hash when comparing strings?
- Next message: [Python-Dev] Rejecting PEPs 407 and 413?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]