S
Shot (Piotr Szotkowski)
--OmL7C/BU0IhhC9Of
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
I have a Set subclass, Block. I need two blocks to be considered the
same by Set iff they have the same elements. From what I gathered, Set
treats two objects as equal when they are eql? and have the same hash.
Implementing Block#eql? seems to be trivial, as Set#=3D=3D is there to help:
class Block < Set
def eql? other
self =3D=3D other
end
end
I=E2=80=99m stuck when it comes to Block#hash, though; I need these to be t=
rue:
Block.new.hash =3D=3D Block.new.hash
Block.new([1,2]).hash =3D=3D Block.new([1,2]).hash
What=E2=80=99s the proper way to go at it? Adding the elements=E2=80=99 has=
hes together
is obviously wrong, as four different elements might produce the same
sum when paired; also, the docs say, =E2=80=98any hash value that exceeds t=
he
capacity of a Fixnum will be truncated before being used,=E2=80=99 so hash =
can=E2=80=99t
exceed the (word - 1 bit) size.
-- Shot
--=20
Hell hath no fury like a bureaucrat scorned. -- Milton Friedman
--OmL7C/BU0IhhC9Of
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
iD8DBQFFvnd2i/mCfdEo8UoRAk2BAJ46G3spixNAe/Qr+K/T4X8FquSB5ACghgNL
TMZqsdmMz1FTrJqYdeOOQvI=
=Gt/7
-----END PGP SIGNATURE-----
--OmL7C/BU0IhhC9Of--
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
I have a Set subclass, Block. I need two blocks to be considered the
same by Set iff they have the same elements. From what I gathered, Set
treats two objects as equal when they are eql? and have the same hash.
Implementing Block#eql? seems to be trivial, as Set#=3D=3D is there to help:
class Block < Set
def eql? other
self =3D=3D other
end
end
I=E2=80=99m stuck when it comes to Block#hash, though; I need these to be t=
rue:
Block.new.hash =3D=3D Block.new.hash
Block.new([1,2]).hash =3D=3D Block.new([1,2]).hash
What=E2=80=99s the proper way to go at it? Adding the elements=E2=80=99 has=
hes together
is obviously wrong, as four different elements might produce the same
sum when paired; also, the docs say, =E2=80=98any hash value that exceeds t=
he
capacity of a Fixnum will be truncated before being used,=E2=80=99 so hash =
can=E2=80=99t
exceed the (word - 1 bit) size.
-- Shot
--=20
Hell hath no fury like a bureaucrat scorned. -- Milton Friedman
--OmL7C/BU0IhhC9Of
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
iD8DBQFFvnd2i/mCfdEo8UoRAk2BAJ46G3spixNAe/Qr+K/T4X8FquSB5ACghgNL
TMZqsdmMz1FTrJqYdeOOQvI=
=Gt/7
-----END PGP SIGNATURE-----
--OmL7C/BU0IhhC9Of--