File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ Tue Apr 15 19:12:21 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
2
+
3
+ * struct.c (rb_struct_hash): new methods Struct#hash, Struct#eql?.
4
+
1
5
Tue Apr 15 16:05:11 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
2
6
3
7
* numeric.c (rb_fix2str): buffer was insufficient.
Original file line number Diff line number Diff line change @@ -576,6 +576,22 @@ rb_struct_equal(s, s2)
576
576
return Qtrue ;
577
577
}
578
578
579
+ static VALUE
580
+ rb_struct_hash (s )
581
+ VALUE s ;
582
+ {
583
+ long i , h ;
584
+ VALUE n ;
585
+
586
+ h = rb_hash (rb_obj_class (s ));
587
+ for (i = 0 ; i < RSTRUCT (s )-> len ; i ++ ) {
588
+ h = (h << 1 ) | (h < 0 ? 1 : 0 );
589
+ n = rb_hash (RSTRUCT (s )-> ptr [i ]);
590
+ h ^= NUM2LONG (n );
591
+ }
592
+ return LONG2FIX (h );
593
+ }
594
+
579
595
static VALUE
580
596
rb_struct_size (s )
581
597
VALUE s ;
@@ -596,6 +612,8 @@ Init_Struct()
596
612
rb_define_method (rb_cStruct , "copy_object" , rb_struct_copy_object , 1 );
597
613
598
614
rb_define_method (rb_cStruct , "==" , rb_struct_equal , 1 );
615
+ rb_define_method (rb_cStruct , "eql?" , rb_struct_equal , 1 );
616
+ rb_define_method (rb_cStruct , "hash" , rb_struct_hash , 0 );
599
617
600
618
rb_define_method (rb_cStruct , "to_s" , rb_struct_to_s , 0 );
601
619
rb_define_method (rb_cStruct , "inspect" , rb_struct_inspect , 0 );
You can’t perform that action at this time.
0 commit comments