[Newbies] Iterating and removing items from OrderedCollections

Marcin Tustin mm3 at zepler.net
Thu Sep 18 08:31:53 UTC 2008


Why are there nils in the middle of the queue?

The obvious thing is to use a linked structure or one which has amortised
constant time addition of elements, and simply count how many items have
been added to the queue to limit its size.


On 9/18/08, Ian J Cottee <icottee at bluefountain.com> wrote:
>
> Hello all
>
> I've got an OrderedCollection that is normally a fixed size (let's say
> 10 elements). Each element in the collection is another an object or
> nil. So for example, at a point in time it might look like
>
> [nil, nil, Object, nil, Object, Object, nil, nil, Object, nil]
>
> What I want is to be able to resize the collection. Making it bigger
> is no problem for me, I can just add nils to the end of the
> collection. Making it smaller is involving a little bit of pain. I can
> see ways of doing it but theyr'e not elegant and I'm sure there are
> cleaner ways of doing it. If I made the above queue smaller I'd
> basically remove the nils starting from the beginning. So a resize to
> size 7 would give me
>
> [ Object, Object, Object, nil, nil, Object, nil]
>
> i.e. the first three nils have been removed.
>
> Does anybody have any comments on appropriate code to handle this? If
> not, I'll go with the ugly stuff but it would be nice to know the
> correct SmallTalk way.
>
> Many thanks for any suggestions.
>
> Ian
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20080918/ae02df03/attachment.html


More information about the Beginners mailing list