<div dir="ltr"><br><br><div class="gmail_quote">On Fri, Aug 8, 2008 at 3:53 PM, Igor Stasenko <span dir="ltr">&lt;<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Sets which not allowing contain nil as element is a point of inconvenience.<br>
<br>
There are two ways how get around that:<br>
- initialize an array which contains set elements with unique object ~~ nil.<br>
and fix methods which testing for an empty slots to compare against<br>
this object, not nil.<br>
This can cause a slowdown during rehashing, because VM initially<br>
creating arrays filled with nils, while we need to fill them with<br>
another object.<br>
There is also a problem with preserving it &#39;uniqueness&#39; by not giving<br>
this object outside a set.<br>
<br>
- add an instVar &#39;containsNil&#39;<br>
then when set receiving &#39;add: nil&#39; , it simply sets this flag to true.<br>
modify #collect: , #do: , #remove: to be aware of flag value.<br>
<br>
I find the second way is more appropriate. While it costs additional<br>
memory per Set/IdentitySet instance, it costs almost nothing in speed.<br>
<br>
What do you think about supporting Sets to contain nils in general,<br>
and about methods how to achieve that?</blockquote><div><br></div><div>Here&#39;s a third approach (a variation on your 2nd approach). &nbsp;Have an instVar &#39;includesSelf&#39; and fill the array with the Set itself. &nbsp;So add a new primitive new:fillWith: (primitiveNewWithArgAndFillValue?) and use this to create the empty array filled with the Set itself. &nbsp;Check for adding the set itself, and itself being the null entry. &nbsp;The advantage over the flag for nil approach is that you kill two birds with one stone.&nbsp;</div>
<div><br></div><div>1. You need a unique value anyway, and the Set can nicely be its own unique value</div><div>2. recursive collections are a problem to print and with the explicit flag this becomes much easier to deal with.</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
<font color="#888888"><br>
--<br>
Best regards,<br>
Igor Stasenko AKA sig.<br>
<br>
</font></blockquote></div><br></div>