get instance using the hash value?
Lex Spoon
lex at cc.gatech.edu
Mon May 28 17:11:28 UTC 2001
"Richard A. O'Keefe" <ok at atlas.otago.ac.nz> wrote:
> An object has a hash value (self hash).
>
> 1. How can I get hold of an object with its hash value?
> anInstance _ AClassCanCreateInstanceUsingHashValue hash: 2340
>
> It is in the nature of hash codes that they are not unique.
> There could be many thousands of objects with that hash code.
> Hash codes are not pointers, they're just a hack to speed up table lookups.
>
> I haven't checked: does Squeak 3.x still use 12-bit hash codes?
YES! For my type inferencer, which has a few sets way bigger than 2^12,
I implement custom hash functions. 4096 is a lot for most purposes,
but ocassional cases require more.
(A cool trick would be if the VM offered optional "long identity
hashes". Small identity sets ask for regular 12-bit hashes, and large
ones ask for the large, optional ones. The same could be done at the
image level for regular #hash -- you could have #hashForSize: (or maybe
#hashOfSize:), and certain objects can generate better hashes for larger
collections. String in particular might benefit!)
Overall, hashing is a funny beast to work with. It works phenomenally
well when it works, but you have to get several things right or it can
fail horribly! A funny problem I had once involved removing the first
element from a set and then adding an arbitrary element to the middle;
thus, over time, I had systematically skewed the set's data to towards
the end of the set. Doh!
Lex
More information about the Squeak-dev
mailing list
|