[squeak-dev] Re: SparseLargeTable
nicolas cellier
ncellier at ifrance.com
Wed Nov 5 19:41:47 UTC 2008
Eliot Miranda a écrit :
>
> Also, lastChunkSize is not set to a correct size.
> It should be:
> (lastChunkSize := size - base + 1 \\ chunkSize) = 0 ifTrue:
> [lastChunkSize := chunkSize].
> which can be more efficiently written:
> lastChunkSize := size - base \\ chunkSize + 1.
>
> Well, I guess every one use with base = 1...
>
>
> No that's not right. base determines the first index, so that e.g.
> SparseLargeArray
> new: (2 raisedToInteger: 32)
> chunkSize: 32 * 1024
> arrayClass: ByteArray
> base: 0
> defaultValue: 0
>
> provides a bye-addressible array of 2^32 elements with indices 0 through
> (2 raisedTo: 32) - 1.
>
That's interesting because that's exactly how I understood 'base' first.
But that's not how it did work before your patches.
SparseLargeTable inherits from ArrayedCollection for which the whole
protocol require indices between 1 and self size...
And that is effectively how SparseLargeTable at: and at:put: did handle
the indices... (mySparseTable at: 0) did not work.
A logical explanation was that base was here for saving bytes, but that
was only a deduction, i did not discuss that with Yoshiki.
That's also why the (self basicAt: anIndex) were protected in #noChekAt:
the first elements (before base) and also the last ones (see how
#zapDefaultOnlyEntries use #privateSize: ) were potentially out of self
"basicBounds".
Now, the modifications you made are appealing, but beware not using one
of the 1-based inherited message on self. That's rather not bug-proof.
Nicolas
More information about the Squeak-dev
mailing list
|