]> gitweb.factorcode.org Git - factor.git/commitdiff
add examples to checksums docs
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 30 Sep 2009 07:26:32 +0000 (02:26 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 30 Sep 2009 07:26:32 +0000 (02:26 -0500)
core/checksums/checksums-docs.factor

index a05bf3a68534bce8940aa334bc8ff8c260e60170..4ffd6f442736201ae67c420c03f2c8e1b871fd10 100644 (file)
@@ -20,15 +20,39 @@ HELP: checksum-stream
 
 HELP: checksum-bytes
 { $values { "bytes" "a sequence of bytes" } { "checksum" "a checksum specifier" } { "value" byte-array } }
-{ $contract "Computes the checksum of all data in a sequence." } ;
+{ $contract "Computes the checksum of all data in a sequence." }
+{ $examples
+    { $example
+        "USING: checksums checksums.crc32 prettyprint ;"
+        "B{ 1 10 100 } crc32 checksum-bytes ."
+        "B{ 78 179 254 238 }"
+    }
+} ;
 
 HELP: checksum-lines
 { $values { "lines" "a sequence of sequences of bytes" } { "checksum" "a checksum specifier" } { "value" byte-array } }
-{ $contract "Computes the checksum of all data in a sequence." } ;
+{ $contract "Computes the checksum of all data in a sequence." }
+{ $examples
+    { $example
+        "USING: checksums checksums.crc32 prettyprint ;"
+"""{
+    "Take me out to the ball game"
+    "Take me out with the crowd"
+} crc32 checksum-lines ."""
+        "B{ 111 205 9 27 }"
+    }
+} ;
 
 HELP: checksum-file
 { $values { "path" "a pathname specifier" } { "checksum" "a checksum specifier" } { "value" byte-array } }
-{ $contract "Computes the checksum of all data in a file." } ;
+{ $contract "Computes the checksum of all data in a file." }
+{ $examples
+    { $example
+        "USING: checksums checksums.crc32 prettyprint ;"
+        """"resource:license.txt" crc32 checksum-file ."""
+        "B{ 100 139 199 92 }"
+    }
+} ;
 
 ARTICLE: "checksums" "Checksums"
 "A " { $emphasis "checksum" } " is a function mapping sequences of bytes to fixed-length strings. While checksums are not one-to-one, a good checksum should have a low probability of collision. Additionally, some checksum algorithms are designed to be hard to reverse, in the sense that finding an input string which hashes to a given checksum string requires a brute-force search."