<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1476" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Fix for Set atRandom:&nbsp; I'd make it a changeset 
but I don't know how to make a changeset with a single entry.&nbsp; I told it to 
save a ChangeSet and it saved out 26 megabytes.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Since Sets never shrink, it does make sense to have 
the relatively prime scanning for large capacity, nearly empty 
sets.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Note that there&nbsp;is a possible 
optimization&nbsp;for generating relatively prime numbers.&nbsp; If the Set is a 
power of two in length, then any odd number will do. Unfortunately Set's class 
method "sizeFor" makes it impossible to make a set a power of two in 
length.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>So, this version checks, and does the optimization 
if it will do any good.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>If you want that optimization of an optimazation to 
be enabled for new Sets&nbsp;then change&nbsp;sizeFor as 
well.&nbsp;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>sizeFor: nElements<BR>&nbsp;"Large enough size to 
hold nElements with some slop (see fullCheck)"<BR>&nbsp;nElements &lt;= 0 
ifTrue: [^ 1].<BR>&nbsp;^ nElements*2</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>atRandom: aGenerator<BR>&nbsp; | ind entry i span 
foundrelativeprime |<BR>&nbsp;&nbsp;&nbsp; self 
emptyCheck.<BR>&nbsp;&nbsp;&nbsp; entry _ nil.<BR>&nbsp;&nbsp;&nbsp; 
i_1.<BR>&nbsp;&nbsp;&nbsp; "try 30 times with random 
samples"<BR>&nbsp;&nbsp;&nbsp; [ entry == nil and: [i&lt;30] ] whileTrue: 
[<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ind _ aGenerator 
nextInt: array size.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
entry _ array at: 
ind.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i _ 
i+1<BR>&nbsp;&nbsp;&nbsp; ].<BR>&nbsp;&nbsp;&nbsp; entry == nil&nbsp; ifTrue: 
[<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "failed 30 random samples - the 
array must be almost empty"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "pick 
a random, relatively prime span and scan every 
entry"<BR>&nbsp;<BR>&nbsp;&nbsp;"Special case for Sets that are powers of two in 
size. "<BR>&nbsp;&nbsp;"If you make a Set that's a power of two in size &gt; 1 
then it will"<BR>&nbsp;&nbsp;"always be a power of two in 
size"<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;(array size bitAnd: ((array size) - 1)) = 0 
ifTrue: [<BR>&nbsp;&nbsp; &nbsp;&nbsp;span _ (aGenerator nextInt: (((array size) 
+ 1) // 2)) * 2 - 1.<BR>&nbsp;&nbsp;] ifFalse: [&nbsp;<BR>&nbsp;&nbsp;&nbsp;"not 
a power of two - find any number that's relatively 
prime"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;foundrelativeprime _ 
false.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;[ 
foundrelativeprime] whileFalse: 
[<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;span _ 1 + (aGenerator nextInt: ((array 
size)-1)).<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;foundrelativeprime _ (1 = ((array size) gcd: 
span)).<BR>&nbsp;&nbsp;&nbsp;].<BR>&nbsp;&nbsp;].<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;i _ array size.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;[i 
&gt; 1] whileTrue: 
[<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ind _ 
(ind+span-1) \\ (array size) + 
1.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entry _ 
array at: 
ind.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entry 
== nil 
ifFalse:[^entry].<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
i _ i-1.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
].<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self 
errorEmptyCollection.<BR>&nbsp;&nbsp;&nbsp; ].<BR>&nbsp;&nbsp;&nbsp; 
^entry.</FONT></DIV></BODY></HTML>