1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* complex.c (nucomp_eql_p): new.

* complex.c (nucomp_hash): should use hash values of the elements.

	* rational.c (nurat_hash): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2008-09-15 04:20:46 +00:00
parent 0675246ba6
commit 05ac51d225
5 changed files with 35 additions and 9 deletions

View file

@ -1,3 +1,11 @@
Mon Sep 15 13:17:21 2008 Tadayoshi Funaba <tadf@dotrb.org>
* complex.c (nucomp_eql_p): new.
* complex.c (nucomp_hash): should use hash values of the elements.
* rational.c (nurat_hash): ditto.
Mon Sep 15 11:11:04 2008 Tanaka Akira <akr@fsij.org>
* transcode_data.h (rb_transcoder): resetsize_func and resetstate_func

View file

@ -23,7 +23,7 @@ VALUE rb_cComplex;
static ID id_Unify, id_abs, id_abs2, id_arg, id_cmp, id_conjugate,
id_convert, id_denominator, id_divmod, id_equal_p, id_exact_p, id_expt,
id_floor, id_format, id_idiv, id_inspect, id_negate, id_new, id_new_bang,
id_floor, id_hash, id_idiv, id_inspect, id_negate, id_new, id_new_bang,
id_numerator, id_polar, id_quo, id_scalar_p, id_to_f, id_to_i, id_to_r,
id_to_s, id_truncate;
@ -163,6 +163,7 @@ fun1(conjugate)
fun1(denominator)
fun1(exact_p)
fun1(floor)
fun1(hash)
fun1(inspect)
fun1(negate)
fun1(numerator)
@ -847,7 +848,21 @@ static VALUE
nucomp_hash(VALUE self)
{
get_dat1(self);
return f_xor(dat->real, dat->image);
return f_xor(f_hash(dat->real), f_hash(dat->image));
}
static VALUE
nucomp_eql_p(VALUE self, VALUE other)
{
if (k_complex_p(other)) {
get_dat2(self, other);
return f_boolcast((CLASS_OF(adat->real) == CLASS_OF(bdat->real)) &&
(CLASS_OF(adat->image) == CLASS_OF(bdat->image)) &&
f_equal_p(self, other));
}
return Qfalse;
}
#ifndef HAVE_SIGNBIT
@ -1354,7 +1369,7 @@ Init_Complex(void)
id_exact_p = rb_intern("exact?");
id_expt = rb_intern("**");
id_floor = rb_intern("floor");
id_format = rb_intern("format");
id_hash = rb_intern("hash");
id_idiv = rb_intern("div");
id_inspect = rb_intern("inspect");
id_negate = rb_intern("-@");
@ -1451,6 +1466,7 @@ Init_Complex(void)
rb_define_method(rb_cComplex, "denominator", nucomp_denominator, 0);
rb_define_method(rb_cComplex, "hash", nucomp_hash, 0);
rb_define_method(rb_cComplex, "eql?", nucomp_eql_p, 1);
rb_define_method(rb_cComplex, "to_s", nucomp_to_s, 0);
rb_define_method(rb_cComplex, "inspect", nucomp_inspect, 0);

4
hash.c
View file

@ -39,8 +39,6 @@ static ID id_hash, id_yield, id_default;
static int
rb_any_cmp(VALUE a, VALUE b)
{
VALUE args[2];
if (a == b) return 0;
if (FIXNUM_P(a) && FIXNUM_P(b)) {
return a != b;
@ -54,8 +52,6 @@ rb_any_cmp(VALUE a, VALUE b)
return a != b;
}
args[0] = a;
args[1] = b;
return !rb_eql(a, b);
}

View file

@ -27,8 +27,8 @@
VALUE rb_cRational;
static ID id_Unify, id_abs, id_cmp, id_convert, id_equal_p, id_expt,
id_floor, id_format, id_idiv, id_inspect, id_integer_p, id_negate,
id_new, id_new_bang, id_to_f, id_to_i, id_to_s, id_truncate;
id_floor, id_format, id_hash, id_idiv, id_inspect, id_integer_p,
id_negate, id_new, id_new_bang, id_to_f, id_to_i, id_to_s, id_truncate;
#define f_boolcast(x) ((x) ? Qtrue : Qfalse)
@ -139,6 +139,7 @@ binop(xor, '^')
fun1(abs)
fun1(floor)
fun1(hash)
fun1(inspect)
fun1(integer_p)
fun1(negate)
@ -1486,6 +1487,7 @@ Init_Rational(void)
id_expt = rb_intern("**");
id_floor = rb_intern("floor");
id_format = rb_intern("format");
id_hash = rb_intern("hash");
id_idiv = rb_intern("div");
id_inspect = rb_intern("inspect");
id_integer_p = rb_intern("integer?");

View file

@ -51,6 +51,7 @@ class Complex_Test < Test::Unit::TestCase
def test_hash
assert_instance_of(Fixnum, Complex(1,2).hash)
assert_instance_of(Fixnum, Complex(1.0,2.0).hash)
h = {}
h[Complex(0)] = 0
@ -63,6 +64,9 @@ class Complex_Test < Test::Unit::TestCase
h[Complex(0,0)] = 9
assert_equal(4, h.size)
h[Complex(0.0,0.0)] = 9.0
assert_equal(5, h.size)
end
def test_freeze