<div dir="ltr"><br><br><div class="gmail_quote">On Fri, Aug 8, 2008 at 5:46 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;">
2008/8/9 Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt;:<br>
<div><div></div><div class="Wj3C7c">&gt;<br>
&gt;<br>
&gt; On Fri, Aug 8, 2008 at 3:53 PM, Igor Stasenko &lt;<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Sets which not allowing contain nil as element is a point of<br>
&gt;&gt; inconvenience.<br>
&gt;&gt;<br>
&gt;&gt; There are two ways how get around that:<br>
&gt;&gt; - initialize an array which contains set elements with unique object ~~<br>
&gt;&gt; nil.<br>
&gt;&gt; and fix methods which testing for an empty slots to compare against<br>
&gt;&gt; this object, not nil.<br>
&gt;&gt; This can cause a slowdown during rehashing, because VM initially<br>
&gt;&gt; creating arrays filled with nils, while we need to fill them with<br>
&gt;&gt; another object.<br>
&gt;&gt; There is also a problem with preserving it &#39;uniqueness&#39; by not giving<br>
&gt;&gt; this object outside a set.<br>
&gt;&gt;<br>
&gt;&gt; - add an instVar &#39;containsNil&#39;<br>
&gt;&gt; then when set receiving &#39;add: nil&#39; , it simply sets this flag to true.<br>
&gt;&gt; modify #collect: , #do: , #remove: to be aware of flag value.<br>
&gt;&gt;<br>
&gt;&gt; I find the second way is more appropriate. While it costs additional<br>
&gt;&gt; memory per Set/IdentitySet instance, it costs almost nothing in speed.<br>
&gt;&gt;<br>
&gt;&gt; What do you think about supporting Sets to contain nils in general,<br>
&gt;&gt; and about methods how to achieve that?<br>
&gt;<br>
&gt; Here&#39;s a third approach (a variation on your 2nd approach). &nbsp;Have an instVar<br>
&gt; &#39;includesSelf&#39; and fill the array with the Set itself. &nbsp;So add a new<br>
&gt; primitive new:fillWith: (primitiveNewWithArgAndFillValue?) and use this to<br>
&gt; create the empty array filled with the Set itself. &nbsp;Check for adding the set<br>
&gt; itself, and itself being the null entry. &nbsp;The advantage over the flag for<br>
&gt; nil approach is that you kill two birds with one stone.<br>
&gt; 1. You need a unique value anyway, and the Set can nicely be its own unique<br>
&gt; value<br>
&gt; 2. recursive collections are a problem to print and with the explicit flag<br>
&gt; this becomes much easier to deal with.<br>
<br>
</div></div>In math domain, any set includes itself , not as element of course,<br>
but as subset :)<br>
And i don&#39;t see how this is better comparing to having &#39;containsNil&#39; ivar?<br>
You still have to test this flag in each method which deals with<br>
elements , so be it containsFoo or containsBar - no real difference.</blockquote><div><br></div><div>One difference is the use of self for the unique object instead of another.</div><div>Another difference is that recursive sets no longer fail to print, inspect, etc.</div>
<div><br></div><div>I think those are real differences.</div><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
<div class="Ih2E3d"><br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; Best regards,<br>
&gt;&gt; Igor Stasenko AKA sig.<br>
&gt;&gt;<br>
<br>
<br>
<br>
</div>--<br>
<div><div></div><div class="Wj3C7c">Best regards,<br>
Igor Stasenko AKA sig.<br>
<br>
</div></div></blockquote></div><br></div>