[squeak-dev] Ideas about sets and dictionaries

Igor Stasenko siguctua at gmail.com
Thu Nov 12 01:03:17 UTC 2009


2009/11/12 Eliot Miranda <eliot.miranda at gmail.com>:
>
>
> On Wed, Nov 11, 2009 at 3:56 PM, Igor Stasenko <siguctua at gmail.com> wrote:
>>
>> @Levente..
>> there is no need to introduce a 'containsNil' flag, nor use other than
>> nil filler object.
>> The tally ivar, which is already there can be used to reflect if set
>> contains nil:
>>
>> tally >= 0  - set contains tally number of elements without nil
>> tally == -1 - set contains only single element - nil
>> tally < -1  - set contains a (tally abs) number of elements including nil
>>
>
> Neat.  It might be even easier to use floating point to indicate nil :)
> So if
>         tally class = SmallInteger
> it doesn't include nil, but if
>         tally class = Float
> it does.

Hehe.. just another way. But it having certain risks, i think, because
 5.0 is quite same as 5
from arithmetic POV while 5 and -5 are distinct values from all POV,
which can't be mixed unintentionally.

A test if set contains nil, then could be just
 tally isInteger  ifFalse: [... contains nil ]

(its faster & we don't care about particular class, isn't?)

> Once tally has been set to a Double all the loops still work,
> increasing the tally still works, etc.

Loops do not refer to tally (all iterations using array ivar and its
size), so there no iterations in sets which may require floating point
value, and hence producing a lot of garbage & waste cycles on it.

Tally comes into play only when you adding or removing objects, and
testing if element is included in set.

>From this point i even consider it could be better than using negative
values, if you provide a little more arguments
that there are no any risks :)

>>
>> i can implement it, if you want.
>>
>> The number of changes is quite minimal, and won't make image to die
>> violently, because:
>>  - currently all sets having tally >=0, so even if you change things
>> to support nils as i proposing, no existing sets having chances to
>> behave differently
>>  - currently all sets can't meaningfully include nil, and there is no
>> code which intentionally puts nil in sets, because it leads to error.
>>
>> 2009/11/12 Eliot Miranda <eliot.miranda at gmail.com>:
>> >
>> >
>> > On Wed, Nov 11, 2009 at 3:14 PM, Russell N Hyer
>> > <hrothgar.ofstingan at gmail.com> wrote:
>> >>
>> >> I still don't comprehend the purpose behind having more than one
>> >> flavour of empty in regards to empty set based mathematics.
>> >
>> > nil is an object like any other, and Sets can contain arbitrary objects.
>> > An empty Set contains no objects.  The fact that internally an empty Set
>> > has
>> > some slots intialized to nil is an implementation detail that in no way
>> > implies that it contains nil.
>> > So if sets are capable of including arbitrary objects they should be
>> > able to
>> > contain nil.  There are lots of contexts in which having collections
>> > that
>> > can include nil is useful.  The compiler is one.  Storing and
>> > reconstituting
>> > object graphs is another.
>> > Or in summary nil ~~ #isEmpty.
>> > HTH
>> > Eliot
>> >>
>> >> 2009/11/11, Igor Stasenko <siguctua at gmail.com>:
>> >> > Just want to add that enabling a set to contain nils already
>> >> > discussed
>> >> > before.
>> >> >
>> >> >
>> >> >
>> >> > http://n4.nabble.com/squeak-dev-Letting-Set-contain-nils-td69437.html#a69437
>> >> >
>> >> > ... and as you may guess, i supporting Levente in this :)
>> >> >
>> >> > --
>> >> > Best regards,
>> >> > Igor Stasenko AKA sig.
>> >> >
>>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko AKA sig.
>>
>
>
>
>
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list