Maybe you will be interested in reading "Introduction to Algorithms".
There is a whole chapter discussing how to implement hash tables
including criteria of good hash functions.


On Fri, Dec 30, 2011 at 5:09 PM, Nikolai Weibull <now / bitwi.se> wrote:
> On Fri, Dec 30, 2011 at 06:25, Josh Cheek <josh.cheek / gmail.com> wrote:
>> On Thu, Dec 29, 2011 at 5:47 PM, Nikolai Weibull <now / bitwi.se> wrote:
>>> So, again, what=92s the standard way of implementing #hash for value ob=
jects in Ruby?
>
>> If there is one, I don't know what it is, which implies there isn't one.
>
> That=92s a very bold statement to make, considering that you don=92t seem
> to know how #hash should be implemented:
>
>> I usually just delegate to one of my attributes' hash methods (e.g. for =
a
>> user, I might use its user's name's hash). I'm not sure what advantage
>> would be gained by establishing a standard.
>
> If there was a standard way, then no one would have to ask if there
> was one. =A0It would make implementing #hash, which you should/must do
> if you implement #=3D=3D, trivial, as there=92s then only one way to do s=
o.
> It would make hashing conflicts less likely, as the correct set of
> parameters would be used, whatever the object, and a uniform
> distribution could be established across different classes of objects.
>
> Perhaps Ruby=92s internal hashing functions (rb_hash_start,
> rb_hash_uint, rb_hash_end) could be exposed in some new object?
>
> Note that these functions are currently not being used in a uniform
> way internally. =A0For example, Struct starts with the #hash of the
> object=92s class, while Array starts with #length.
>