From ce76b1888eee5b70a19c8e3b3dd5facd01251e1d Mon Sep 17 00:00:00 2001
From: Doug Coleman <doug.coleman@gmail.com>
Date: Thu, 8 May 2008 19:36:44 -0500
Subject: [PATCH] add adler-32 checksum, tests, and docs

---
 extra/checksums/adler-32/adler-32-docs.factor  | 11 +++++++++++
 extra/checksums/adler-32/adler-32-tests.factor |  5 +++++
 extra/checksums/adler-32/adler-32.factor       | 15 +++++++++++++++
 extra/checksums/adler-32/authors.txt           |  1 +
 4 files changed, 32 insertions(+)
 create mode 100755 extra/checksums/adler-32/adler-32-docs.factor
 create mode 100644 extra/checksums/adler-32/adler-32-tests.factor
 create mode 100644 extra/checksums/adler-32/adler-32.factor
 create mode 100644 extra/checksums/adler-32/authors.txt

diff --git a/extra/checksums/adler-32/adler-32-docs.factor b/extra/checksums/adler-32/adler-32-docs.factor
new file mode 100755
index 0000000000..b7400cbaa0
--- /dev/null
+++ b/extra/checksums/adler-32/adler-32-docs.factor
@@ -0,0 +1,11 @@
+USING: help.markup help.syntax ;
+IN: checksums.adler-32
+
+HELP: adler-32
+{ $description "Adler-32 checksum algorithm." } ;
+
+ARTICLE: "checksums.adler-32" "Adler-32 checksum"
+"The Adler-32 checksum algorithm implements simple and fast checksum. It is used in zlib and rsync."
+{ $subsection adler-32 } ;
+
+ABOUT: "checksums.adler-32"
diff --git a/extra/checksums/adler-32/adler-32-tests.factor b/extra/checksums/adler-32/adler-32-tests.factor
new file mode 100644
index 0000000000..ccee74baae
--- /dev/null
+++ b/extra/checksums/adler-32/adler-32-tests.factor
@@ -0,0 +1,5 @@
+USING: checksums.adler-32 checksums strings tools.test ;
+IN: checksums.adler-32.tests
+
+[ 300286872 ] [ "Wikipedia" adler-32 checksum-bytes ] unit-test
+[ 2679885283 ] [ 10000 CHAR: a <string> adler-32 checksum-bytes ] unit-test
diff --git a/extra/checksums/adler-32/adler-32.factor b/extra/checksums/adler-32/adler-32.factor
new file mode 100644
index 0000000000..1be4bfb584
--- /dev/null
+++ b/extra/checksums/adler-32/adler-32.factor
@@ -0,0 +1,15 @@
+! Copyright (C) 2008 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: checksums classes.singleton kernel math math.ranges
+math.vectors sequences ;
+IN: checksums.adler-32
+
+SINGLETON: adler-32
+
+: adler-32-modulus 65521 ; inline
+
+M: adler-32 checksum-bytes ( bytes checksum -- value )
+    drop
+    [ sum 1+ ]
+    [ [ dup length [1,b] <reversed> v. ] [ length ] bi + ] bi
+    [ adler-32-modulus mod ] bi@ 16 shift bitor ;
diff --git a/extra/checksums/adler-32/authors.txt b/extra/checksums/adler-32/authors.txt
new file mode 100644
index 0000000000..7c1b2f2279
--- /dev/null
+++ b/extra/checksums/adler-32/authors.txt
@@ -0,0 +1 @@
+Doug Coleman