mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* struct.c (rb_struct_hash): new methods Struct#hash, Struct#eql?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d79a04f0d4
commit
df61e2aad6
2 changed files with 22 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
Tue Apr 15 19:12:21 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||
|
||||
* struct.c (rb_struct_hash): new methods Struct#hash, Struct#eql?.
|
||||
|
||||
Tue Apr 15 16:05:11 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||
|
||||
* numeric.c (rb_fix2str): buffer was insufficient.
|
||||
|
|
18
struct.c
18
struct.c
|
@ -576,6 +576,22 @@ rb_struct_equal(s, s2)
|
|||
return Qtrue;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_struct_hash(s)
|
||||
VALUE s;
|
||||
{
|
||||
long i, h;
|
||||
VALUE n;
|
||||
|
||||
h = rb_hash(rb_obj_class(s));
|
||||
for (i = 0; i < RSTRUCT(s)->len; i++) {
|
||||
h = (h << 1) | (h<0 ? 1 : 0);
|
||||
n = rb_hash(RSTRUCT(s)->ptr[i]);
|
||||
h ^= NUM2LONG(n);
|
||||
}
|
||||
return LONG2FIX(h);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_struct_size(s)
|
||||
VALUE s;
|
||||
|
@ -596,6 +612,8 @@ Init_Struct()
|
|||
rb_define_method(rb_cStruct, "copy_object", rb_struct_copy_object, 1);
|
||||
|
||||
rb_define_method(rb_cStruct, "==", rb_struct_equal, 1);
|
||||
rb_define_method(rb_cStruct, "eql?", rb_struct_equal, 1);
|
||||
rb_define_method(rb_cStruct, "hash", rb_struct_hash, 0);
|
||||
|
||||
rb_define_method(rb_cStruct, "to_s", rb_struct_to_s, 0);
|
||||
rb_define_method(rb_cStruct, "inspect", rb_struct_inspect, 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue