[前][次][番号順一覧][スレッド一覧]

ruby-changes:14515

From: tenderlove <ko1@a...>
Date: Tue, 19 Jan 2010 09:06:30 +0900 (JST)
Subject: [ruby-changes:14515] Ruby:r26352 (trunk): * ext/zlib/zlib.c: added Zlib.crc32_combine and Zlib.adler32_combine

tenderlove	2010-01-19 09:06:04 +0900 (Tue, 19 Jan 2010)

  New Revision: 26352

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26352

  Log:
    * ext/zlib/zlib.c: added Zlib.crc32_combine and Zlib.adler32_combine
    
    * test/zlib/test_zlib.rb: corresponding tests [ruby-core:27551]

  Modified files:
    trunk/ChangeLog
    trunk/ext/zlib/zlib.c
    trunk/test/zlib/test_zlib.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26351)
+++ ChangeLog	(revision 26352)
@@ -1,3 +1,10 @@
+Tue Jan 19 09:03:37 2010  Aaron Patterson <tenderlove@r...>
+
+	* ext/zlib/zlib.c: added Zlib.crc32_combine and Zlib.adler32_combine
+
+	* test/zlib/test_zlib.rb: corresponding tests [ruby-core:27551]
+
+
 Tue Jan 19 02:02:32 2010  Yusuke Endoh  <mame@t...>
 
 	* test/ruby/test_array.rb: add some tests (for coverage).
Index: ext/zlib/zlib.c
===================================================================
--- ext/zlib/zlib.c	(revision 26351)
+++ ext/zlib/zlib.c	(revision 26352)
@@ -319,6 +319,21 @@
 }
 
 /*
+ * call-seq: Zlib.adler32_combine(adler1, adler2, len2)
+ *
+ * Combine two Adler-32 check values in to one.  +alder1+ is the first Adler-32
+ * value, +adler2+ is the second Adler-32 value.  +len2+ is the length of the
+ * string used to generate +adler2+.
+ *
+ */
+static VALUE
+rb_zlib_adler32_combine(VALUE klass, VALUE adler1, VALUE adler2, VALUE len2)
+{
+  return ULONG2NUM(
+	adler32_combine(NUM2ULONG(adler1), NUM2ULONG(adler2), NUM2LONG(len2)));
+}
+
+/*
  * call-seq: Zlib.crc32(string, adler)
  *
  * Calculates CRC checksum for +string+, and returns updated value of +crc+. If
@@ -334,6 +349,21 @@
 }
 
 /*
+ * call-seq: Zlib.crc32_combine(crc1, crc2, len2)
+ *
+ * Combine two CRC-32 check values in to one.  +crc1+ is the first CRC-32
+ * value, +crc2+ is the second CRC-32 value.  +len2+ is the length of the
+ * string used to generate +crc2+.
+ *
+ */
+static VALUE
+rb_zlib_crc32_combine(VALUE klass, VALUE crc1, VALUE crc2, VALUE len2)
+{
+  return ULONG2NUM(
+	crc32_combine(NUM2ULONG(crc1), NUM2ULONG(crc2), NUM2LONG(len2)));
+}
+
+/*
  * Returns the table for calculating CRC checksum as an array.
  */
 static VALUE
@@ -3468,7 +3498,9 @@
 
     rb_define_module_function(mZlib, "zlib_version", rb_zlib_version, 0);
     rb_define_module_function(mZlib, "adler32", rb_zlib_adler32, -1);
+    rb_define_module_function(mZlib, "adler32_combine", rb_zlib_adler32_combine, 3);
     rb_define_module_function(mZlib, "crc32", rb_zlib_crc32, -1);
+    rb_define_module_function(mZlib, "crc32_combine", rb_zlib_crc32_combine, 3);
     rb_define_module_function(mZlib, "crc_table", rb_zlib_crc_table, 0);
 
     rb_define_const(mZlib, "VERSION", rb_str_new2(RUBY_ZLIB_VERSION));
Index: test/zlib/test_zlib.rb
===================================================================
--- test/zlib/test_zlib.rb	(revision 26351)
+++ test/zlib/test_zlib.rb	(revision 26352)
@@ -662,6 +662,12 @@
       assert_equal(0x8a62c964, Zlib.adler32("abc\x01\x02\x03" * 10000))
     end
 
+    def test_adler32_combine
+      one = Zlib.adler32("fo")
+      two = Zlib.adler32("o")
+      assert_equal(0x02820145, Zlib.adler32_combine(one, two, 1))
+    end
+
     def test_crc32
       assert_equal(0x00000000, Zlib.crc32)
       assert_equal(0x8c736521, Zlib.crc32("foo"))
@@ -669,6 +675,12 @@
       assert_equal(0x07f0d68f, Zlib.crc32("abc\x01\x02\x03" * 10000))
     end
 
+    def test_crc32_combine
+      one = Zlib.crc32("fo")
+      two = Zlib.crc32("o")
+      assert_equal(0x8c736521, Zlib.crc32_combine(one, two, 1))
+    end
+
     def test_crc_table
       t = Zlib.crc_table
       assert_instance_of(Array, t)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]