[squeak-dev] WeakArray>>grownBy: question (was: The Inbox:
Collections-cmm.673.mcz)
David T. Lewis
lewis at mail.msen.com
Sat Jan 2 23:39:57 UTC 2016
On Fri, Jan 01, 2016 at 03:45:04PM -0600, Chris Muller wrote:
> > what about using the idea of HashedCollection >> #growSize? It is "self
> > class goodPrimeAtLeast: array size * 3 // 2 + 2". Is it specific to hashing
> > that a prime number is used there?
>
> Yes.. and now I understand why it grows linearly; because its a
> linearly-searched Array. The elements are not interspersed as in a
> HashedCollection, we don't "need" the extra room for that purpose, it
> was just to reduce the number of times it needs to grwo by a factor of
> 10. My change simply reduces the number of times it must grow even
> more, however, since it appears we have nothing to ever shrink it back
> down, we should not be growing by double right now, because that would
> waste too many slots. This way, a max of 10 slots is wasted.
>
> Still, we need the as: WeakArray fix..
I have a feeling this has been discussed before, but I am curious. If I
have a WeakArray and I send #grownBy:, and if the method comment for
SequenceableCollection>>grownBy: says this:
"Answer a copy of receiver collection with size grown by length"
Then why is it acceptable to answer an Array rather than a WeakArray?
I think the answer has to do with this:
WeakArray>>species
"More useful to have strongly-referenced results of #select: and #collect:."
^ Array
So if WeakArray>>species should answer an Array, then should #grownBy:
be reimplemented in WeakArray so that it behaves as advertised? Or
perhaps SequenceableCollection>>grownBy: should use #class rather than
#species to figure out what kind of thing to answer?
Dave
More information about the Squeak-dev
mailing list
|