Set class comment

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Set class comment

Casey Ransberger-2
I noticed that the class comment for Set still thinks you can't stick nil in a set. I was going to update it, but I'm a little confused about what's going on in #array. 

#(#foo # bar #baz nil) asSet array

{nil . nil . nil . a SetElement . nil . #foo . #baz . nil . nil . nil . #bar}

Can I assume that the SetElement is a stand in for the nil item in the Set?

See below for what I have so far.

=================================================

As of Squeak 4.1, Sets can contain nil.

I represent a set of objects without duplicates.  I can hold anything that responds to
#hash and #=.  My instances will automatically grow, if necessary,
Note that I rely on #=, not #==.  If you want a set using #==, use IdentitySet.

Instance structure:

  array An array whose non-nil elements are the elements of the set,
and whose nil elements are empty slots.  There is always at least one nil.
In fact I try to keep my "load" at 75% or less so that hashing will work well.

  tally The number of elements in the set.  The array size is always greater than this.

The core operation is #findElementOrNil:, which either finds the position where an
object is stored in array, if it is present, or finds a suitable position holding nil, if
its argument is not present in array,


Reply | Threaded
Open this post in threaded view
|

Re: Set class comment

Levente Uzonyi-2
On Mon, 29 Mar 2010, Casey Ransberger wrote:

> I noticed that the class comment for Set still thinks you can't stick nil in
> a set. I was going to update it, but I'm a little confused about what's
> going on in #array.

I'm about to fix the class comments for the HashedCollection hierarchy,
but help is always welcome, especially from a native english speaker.

>
> #(#foo # bar #baz nil) asSet array
>
> {nil . nil . nil . a SetElement . nil . #foo . #baz . nil . nil . nil .
> #bar}
>
> Can I assume that the SetElement is a stand in for the nil item in the Set?

Yes.

>
> See below for what I have so far.
>
> =================================================
>
> As of Squeak 4.1, Sets can contain nil.
>
> I represent a set of objects without duplicates.  I can hold anything that
> responds to
> #hash and #=.  My instances will automatically grow, if necessary,
> Note that I rely on #=, not #==.  If you want a set using #==, use
> IdentitySet.
>
> Instance structure:
>
>  array An array whose non-nil elements are the elements of the set,
> and whose nil elements are empty slots.  There is always at least one nil.
> In fact I try to keep my "load" at 75% or less so that hashing will work
> well.

This also applies for Dictionary, so it'd be better in the comment of
HashedCollection IMHO.

>
>  tally The number of elements in the set.  The array size is always greater
> than this.

Same as above.

>
> The core operation is #findElementOrNil:, which either finds the position
> where an
> object is stored in array, if it is present, or finds a suitable position
> holding nil, if
> its argument is not present in array,

Same as above, but this is a bit obsolete, #scanFor: is the current lookup
method, #findElementOrNil: is only a compatibility method now.

I'd be very important to mention that the objects' hash must not change
while they are added to a set, otherwise the set becomes invalid. If that
happens #rehash can be used to fix it.


Levente

>

Reply | Threaded
Open this post in threaded view
|

Re: Set class comment

Nicolas Cellier
See also probably obsolete http://bugs.squeak.org/view.php?id=6942

Nicolas

2010/3/30 Levente Uzonyi <[hidden email]>:

> On Mon, 29 Mar 2010, Casey Ransberger wrote:
>
>> I noticed that the class comment for Set still thinks you can't stick nil
>> in
>> a set. I was going to update it, but I'm a little confused about what's
>> going on in #array.
>
> I'm about to fix the class comments for the HashedCollection hierarchy, but
> help is always welcome, especially from a native english speaker.
>
>>
>> #(#foo # bar #baz nil) asSet array
>>
>> {nil . nil . nil . a SetElement . nil . #foo . #baz . nil . nil . nil .
>> #bar}
>>
>> Can I assume that the SetElement is a stand in for the nil item in the
>> Set?
>
> Yes.
>
>>
>> See below for what I have so far.
>>
>> =================================================
>>
>> As of Squeak 4.1, Sets can contain nil.
>>
>> I represent a set of objects without duplicates.  I can hold anything that
>> responds to
>> #hash and #=.  My instances will automatically grow, if necessary,
>> Note that I rely on #=, not #==.  If you want a set using #==, use
>> IdentitySet.
>>
>> Instance structure:
>>
>>  array An array whose non-nil elements are the elements of the set,
>> and whose nil elements are empty slots.  There is always at least one nil.
>> In fact I try to keep my "load" at 75% or less so that hashing will work
>> well.
>
> This also applies for Dictionary, so it'd be better in the comment of
> HashedCollection IMHO.
>
>>
>>  tally The number of elements in the set.  The array size is always
>> greater
>> than this.
>
> Same as above.
>
>>
>> The core operation is #findElementOrNil:, which either finds the position
>> where an
>> object is stored in array, if it is present, or finds a suitable position
>> holding nil, if
>> its argument is not present in array,
>
> Same as above, but this is a bit obsolete, #scanFor: is the current lookup
> method, #findElementOrNil: is only a compatibility method now.
>
> I'd be very important to mention that the objects' hash must not change
> while they are added to a set, otherwise the set becomes invalid. If that
> happens #rehash can be used to fix it.
>
>
> Levente
>
>>
>
>