[squeak-dev] Re: SparseLargeTable

nicolas cellier ncellier at ifrance.com
Wed Nov 5 22:08:31 UTC 2008


Eliot Miranda a écrit :
> 
> Can you say which methods require this and why?

Well there are just too many forms of
   1 to: self size do: [:i | (self at:i ) doSomething]
to fit in this list.

Of course, I doubt you want to iterate over 2**32 elements, so maybe 
this is a false probem.
Though you can legitimately attempt a:

	^aSparseTable findFirst: [:element | element > 0].


> 
> I'd like to plug those holes. I absolutely need 0-based sparse arrays :)
> 

Maybe you won't be trapped by any hole for your private usage...

That's different if the class is supposed to be generic.
But since an anythingBut-1-based sequenceable collection would not fit 
in existing code base without pain, that's probably a false problem too.

I try to imagine how to:

It would be safer to hook the class in a new hierarchy...
Beware, even SequenceableCollection is crippled with 1 to: self size do:
Only Collection implements all loops with do:

Personnally, I would like this
do:
     self error: 'you are trying to iterate over a huge collection'.

and implement some
nonDefaultDo: aBlock
     | chunk index |
     1 to: self basicSize do: [:i |
        (chunk := self basicAt: i) isNil ifFalse: [
            chunk do: [:element |
                element = defaultValue ifFalse: [
                    aBlock
                        value: element]]]]

Then I will trap myself with 0-based indices...
For example, i would write inner loop of nonDefaultWithIndexDo:
         1 to: chunk size do: [:j | (chunk at: j) = defaultValue...
or
         chunk withIndexDo: [:element :j |
                element = defaultValue ifFalse: [
                    aBlock
                        value: i - 1 * chunkSize + j + base - 1
                        value: element

But wait, who told me chunk was 1-based?
I could for example populate a SparseLargeTable with 0-based 
SparseLargeTable as arrayClass just for making my own 2**64 collection 
(i can't help challenging your 2**32)...
So I would need a (chunk withRankDo: ) or just (chunk atRank: ), and to 
cover my sparse case, probably generalize a nonDefaultWithRankDo:...
... or #nonDefaultWithOffsetDo: just to remove the - 1.

Yes, 0-based pain startingAt: second message (messageList atOffset: 1).

Nicolas




More information about the Squeak-dev mailing list