bugs? hash and the debugger.

Dan Ingalls Dan.Ingalls at disney.com
Sun Dec 12 23:57:13 UTC 1999


>  But I was wrong: the order of elements returned by
>aSet>>do: varies even the two Sets have "same" elements.
>So, sorting the elements with respect to the hash value
>before picking the items is needed.
>
>-----------------
>hash
>	| hash array |
>	hash _ self species hash.
>	array _ (self collect: [:elem| elem hash]) asSortedCollection.
>	array size = 0 ifTrue: [^hash].
>	hash _ (hash + (array at: 1)) bitXor: ((array at: array size)).
>	^hash.
>-----------------

Yoshiki -

Hash should be a fast function, since it is often used for quick rejection of potentially long comparisons.  How about making the default collection hash be order independent, so there's no need to sort as part of hashing, and perhaps fall back to a simple function of size if it is greater than, say, 10.

hash
	| hash |
	hash := self species hash.
	self size > 10 ifTrue: [^ hash + size].
	self do: [:elem | hash := hash bitXor: elem hash].
	^ hash.

Would this answer your needs?

	- Dan





More information about the Squeak-dev mailing list