[Python-checkins] python/dist/src/Objects setobject.c,1.23,1.24

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Thu Jun 10 17:38:43 EDT 2004


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28236

Modified Files:
	setobject.c 
Log Message:
Fixups to the hash function for frozensets.

* Non-zero initial value so that hash(frozenset()) != hash(0).
* Final permutation to differentiate nested sets.
* Add logic to make sure that -1 is not a possible hash value.



Index: setobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/setobject.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** setobject.c	30 May 2004 07:26:45 -0000	1.23
--- setobject.c	10 Jun 2004 21:38:41 -0000	1.24
***************
*** 664,668 ****
  	PyObject *key, *value;
  	int pos = 0;
! 	long hash = 0;
  
  	if (so->hash != -1)
--- 664,668 ----
  	PyObject *key, *value;
  	int pos = 0;
! 	long hash = 1905176217L;
  
  	if (so->hash != -1)
***************
*** 677,680 ****
--- 677,683 ----
  		hash ^= PyObject_Hash(key) * 3644798167u;
  	}
+ 	hash *= 69069L;
+ 	if (hash == -1)
+ 		hash = 590923713L;
  	so->hash = hash;
  	return hash;




More information about the Python-checkins mailing list