[squeak-dev] Dictionary rehash

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Dictionary rehash

Ralph Boland
In my own Squeak project I have a method

Dictionary>>rehash.

I don't remember why I wrote this method but
I just noticed that Dictionary>>rehash is not in
the original  Squeak 3.10.2 code.
Furthermore if used it should fail because
it will inherit rehash from Set which doesn't
work for Dictionaries.  My Dictionary>>rehash
method is like the one in Set except
associationsDo:  is used instead of  do:.

Is this a bug?

What is the purpose of rehash anyway?

Ralph Boland

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Dictionary rehash

Eliot Miranda-2


On Fri, Jul 17, 2009 at 2:22 PM, Ralph Boland <[hidden email]> wrote:
In my own Squeak project I have a method

Dictionary>>rehash.

I don't remember why I wrote this method but
I just noticed that Dictionary>>rehash is not in
the original  Squeak 3.10.2 code.
Furthermore if used it should fail because
it will inherit rehash from Set which doesn't
work for Dictionaries.  My Dictionary>>rehash
method is like the one in Set except
associationsDo:  is used instead of  do:.

Is this a bug?

Which, the absence of the method, the default to Set>>hash or the use of associationsDo: ?
yes. yes. no.

Note that in our system we have

Dictionary methods for private
rehash
"Smalltalk rehash."
| newSelf |
newSelf := self species new: self size.
self associationsDo: [:each | newSelf noCheckAdd: each].
array := newSelf array

What is the purpose of rehash anyway?

Rehash arranges that a hashed collection's contents are again accessible after hashes have changed.  For example, if one changes the hash method(s) of classes of elements of hashed collections one would need to rehash afterwards to keep those collections working properly.  One common uses is on loading objects from some binary stream where the newly created loaded objects have different hashes than they had when they were saved, and hence hashed collections referring to those objects must be rehashed sometime during the load process.

So that the Dictionary>>rehash method is missing is a bug, and that you're doing the right thing is not.

HTH



Ralph Boland