[squeak-dev] Letting Set contain nils?

Igor Stasenko siguctua at gmail.com
Fri Aug 8 22:53:23 UTC 2008


Sets which not allowing contain nil as element is a point of inconvenience.

There are two ways how get around that:
- initialize an array which contains set elements with unique object ~~ nil.
and fix methods which testing for an empty slots to compare against
this object, not nil.
This can cause a slowdown during rehashing, because VM initially
creating arrays filled with nils, while we need to fill them with
another object.
There is also a problem with preserving it 'uniqueness' by not giving
this object outside a set.

- add an instVar 'containsNil'
then when set receiving 'add: nil' , it simply sets this flag to true.
modify #collect: , #do: , #remove: to be aware of flag value.

I find the second way is more appropriate. While it costs additional
memory per Set/IdentitySet instance, it costs almost nothing in speed.

What do you think about supporting Sets to contain nils in general,
and about methods how to achieve that?

-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list