Re: [Python-Dev] Why not using the hash when comparing strings?

2012年10月18日 18:24:25 -0700

2012年10月18日 Victor Stinner <[email protected]>:
> 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 == Py_EQ || op == Py_NE)
> && a->ob_shash != -1
> && b->ob_shash != -1
> && a->ob_shash != b->ob_shash) {
> /* strings are not equal */
> }
>
> There are hash collision, so a->ob_shash == b->ob_shash doesn't mean
> that the two strings are equal. But if the two hashs are different,
> the two strings are different. Isn't it?
It would be interesting to see how common it is for strings which have
their hash computed to be compared.
-- 
Regards,
Benjamin
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to