help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] [PATCH] Add #atAll:, improve MappedCollection


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] [PATCH] Add #atAll:, improve MappedCollection
Date: Thu, 07 Jun 2007 10:04:39 +0200
User-agent: Thunderbird 2.0.0.0 (Macintosh/20070326)


Great!  I'll add that

aSeqCollect atAll: anInterval

is a powerfully expressive idiom

Fully agreed -- to the point that I was surprised of its absence.

enabled by this extension, replacing all sorts of specialized collection methods

What are you thinking of?

I should add that MappedCollection is also a powerful tool with this respect, since basically

    MappedCollection collection: foo map: aCollection

is a lazy version of "foo atAll: aCollection". For Intervals, using a MappedCollection may save lots of memory.

An interesting example is that of matrices, implemented over a single array with rows*cols elements:

    initialize
        rowSections := (0 to: rows - 1) collect: [ :n |
             MappedCollection
                  collection: data
                  map: (n * cols + 1 to: (n + 1) * cols) ].
        columnSections := (1 to: cols) collect: [ :n |
             MappedCollection
                  collection: data
                  map: (n to: rows * cols by: cols) ].

    at: n
        ^rowSections at: n

    columnAt: n
        ^columnSections at: n

    at: row at: column
        ^(self at: row) at: column

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]