checksum.bsd: adding BSD checksum algorithm.
parent
e1cac84203
commit
c7e7b618b4
|
|
@ -0,0 +1 @@
|
||||||
|
John Benediktsson
|
||||||
|
|
@ -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"
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
BSD checksum algorithm
|
||||||
Loading…
Reference in New Issue