From: Konrad Meyer Date: 2007-09-10T04:35:04+09:00 Subject: Re: Hash --nextPart9518005.DP6sjhEFFz Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Sunday 09 September 2007 12:23:43 pm Ron Green wrote: > Peter Cooper wrote: > > On 9/9/07, Ron Green wrote: > >> > >> Marcel Molina Jr. wrote: > >> > It should be noted though that String#hash isn't garaunteed to be > >> > unique. > >> > >> Then,again I ask, what is it good for? > >=20 > >=20 > > It's still useful as a hash. Marcel wasn't wrong, but *no* fixed size=20 > > hash > > is "guaranteed" to be unique as that's absolutely impossible, per the > > pigeonhole principle=20 > > (http://en.wikipedia.org/wiki/Pigeonhole_principle). > > String#hash's hash is of a far lower "quality" than that offered by,=20 > > say, > > SHA-1 or SHA-2. > >=20 > > Regards, > > Peter Cooper > > http://www.rubyinside.com/ >=20 > Peter, > If Its not guaranteed to be unique, then it can't be used for identity. > Can you give me an example of how i would use string.hash? Let's put it this way. MD5 and SHA-* hashes aren't *guaranteed* to be unique either. There's just many more cases where strings will share a hash with String#hash as opposed to something like MD5/SHA-*. Hashes are useful for identify strings in hashtables. You use this every time you say something like: foo =3D {"bar" =3D> "baz"} foo["bar"] # =3D> "baz" HTH, =2D-=20 Konrad Meyer http://konrad.sobertillnoon.com/ --nextPart9518005.DP6sjhEFFz Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBG5EriCHB0oCiR2cwRAvaaAJ91scTFNpTDfPNUaXzOswwfcyvTjwCgoRBH Qfi/XhKnqsF1CjNQDINtUP8= =UXmM -----END PGP SIGNATURE----- --nextPart9518005.DP6sjhEFFz--