bugs? hash and the debugger.
ohshima at is.titech.ac.jp
ohshima at is.titech.ac.jp
Wed Dec 8 10:54:50 UTC 1999
Hi,
> > So, I propose to define Collection>>hash something like:
> >----------
> >hash
> > | hash index |
> > hash _ self species hash.
> > index _ 0.
> > self do: [:item |
> > (index _ index + 1) > 3 ifTrue: [^hash].
> > hash _ hash bitXor: (((hash bitShift: -6) bitOr: ((hash bitAnd: 16r3F)
> >bitShift: 6)) + item hash).
> > ].
> > ^hash.
> >----------
> >
> > How do you think?
>
> This looks like it corresponds to the implementation of Collection>>=
> nicely, and should work for any kind of Collection.
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.
-----------------
It would be nice if the instances of Set and Dictionary
hold cached hash value in order to avoid the recalculation
of hash, but it requires VM modification.
-- Yoshiki
More information about the Squeak-dev
mailing list
|