]> gitweb.factorcode.org Git - factor.git/commitdiff
checksum.bsd: adding BSD checksum algorithm.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 10 Apr 2013 16:24:45 +0000 (09:24 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 10 Apr 2013 16:24:45 +0000 (09:24 -0700)
basis/checksums/bsd/authors.txt [new file with mode: 0644]
basis/checksums/bsd/bsd-docs.factor [new file with mode: 0644]
basis/checksums/bsd/bsd-tests.factor [new file with mode: 0644]
basis/checksums/bsd/bsd.factor [new file with mode: 0644]
basis/checksums/bsd/summary.txt [new file with mode: 0644]

diff --git a/basis/checksums/bsd/authors.txt b/basis/checksums/bsd/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/basis/checksums/bsd/bsd-docs.factor b/basis/checksums/bsd/bsd-docs.factor
new file mode 100644 (file)
index 0000000..5253ab6
--- /dev/null
@@ -0,0 +1,11 @@
+USING: help.markup help.syntax ;
+IN: checksums.bsd
+
+HELP: bsd
+{ $class-description "BSD checksum algorithm." } ;
+
+ARTICLE: "checksums.bsd" "BSD checksum"
+"The BSD checksum algorithm implements simple and fast 16-bit checksum. It is a commonly used, legacy checksum algorithm implemented in BSD and available through the GNU " { $snippet "sum" } " utility."
+{ $subsections bsd } ;
+
+ABOUT: "checksums.bsd"
diff --git a/basis/checksums/bsd/bsd-tests.factor b/basis/checksums/bsd/bsd-tests.factor
new file mode 100644 (file)
index 0000000..0e43088
--- /dev/null
@@ -0,0 +1,5 @@
+USING: checksums.bsd checksums strings tools.test ;
+IN: checksums.bsd
+
+{ 15816 } [ "Wikipedia" bsd checksum-bytes ] unit-test
+{ 47937 } [ 10000 CHAR: a <string> bsd checksum-bytes ] unit-test
diff --git a/basis/checksums/bsd/bsd.factor b/basis/checksums/bsd/bsd.factor
new file mode 100644 (file)
index 0000000..0b61551
--- /dev/null
@@ -0,0 +1,14 @@
+! Copyright (C) 2013 John Benediktsson.
+! See http://factorcode.org/license.txt for BSD license.
+USING: checksums kernel math sequences ;
+IN: checksums.bsd
+
+SINGLETON: bsd
+
+M: bsd checksum-bytes ( bytes checksum -- value )
+    drop 0 [
+        [ [ -1 shift ] [ 1 bitand 15 shift ] bi + ] dip
+        + 0xffff bitand
+    ] reduce ;
+
+INSTANCE: bsd checksum
diff --git a/basis/checksums/bsd/summary.txt b/basis/checksums/bsd/summary.txt
new file mode 100644 (file)
index 0000000..14d83b0
--- /dev/null
@@ -0,0 +1 @@
+BSD checksum algorithm