[FIX][BUG] Set>>atRandom: is not random ( another - better? - solution)

Ned Konz ned at squeakland.org
Fri Feb 27 17:55:09 UTC 2004


On Friday 27 February 2004 9:42 am, Lothar Schenk wrote:
> I think, I have now a better solution. It takes advantage of the fact, that
> Sets are not guaranteed to be in a particular order, i.e. it should be
> possible to move the elements around within the array used for
> implementation without affecting the outside behavior. (SOMEBODY PLEASE
> CONFIRM THIS).

No, the array is in a particular order: its members are in slots whose indices 
are computed using the hash of the object modulo the size of the array.

So re-ordering the array (at least without changing the rest of the logic) 
will cause lookup failures, or big slowdowns. Don't do that.

-- 
Ned Konz
http://bike-nomad.com/squeak/



More information about the Squeak-dev mailing list