{ $class-description "This is an instance of the " { $link block-checksum } " mixin. It calculates multiple checksums by sequentially passing the data it receives to all the checksums in its " { $slot "checksums" } " slot. This way, even though the individual checksums are not calculated in parallel, you still can have the performance benefits of only reading a disk file once, or not having to temporarily store the data streamed from a network." } ;
HELP: multi-state
-{ $class-description "This class represents the current state of a " { $link multi-checksum } " checksum calculation. It has an array of associated checksum states until it is disposed. You may call " { $link add-checksum-bytes } " multiple times to pipe data to all the checksums in the " { $slot "checksums" } " slot. When finished, call " { $link get-checksum } " to receive the results and release implementation-specific resources, or " { $link dispose } " to release the resources and discard the result. After the first " { $link get-checksum } " call the returned value is stored in the " { $slot "results" } " slot, and subsequent calls return the same value." }
+{ $class-description "This class represents the current state of a " { $link multi-checksum } " checksum calculation. It has an array of associated checksum states until it is disposed. You may call " { $link add-checksum-bytes } " multiple times to pipe data to all the checksum states in the " { $slot "states" } " slot. When finished, call " { $link get-checksum } " to receive the results and release implementation-specific resources, or " { $link dispose } " to release the resources and discard the result. After the first " { $link get-checksum } " call the returned value is stored in the " { $slot "results" } " slot, and subsequent calls return the same value." }
{ $notes "It is not possible to add more data to the checksum after the first " { $link get-checksum } " call."
$nl
"Most code should use " { $link with-checksum-state } " to make sure the resources are properly disposed of. Higher level words like " { $link checksum-bytes } " and " { $link checksum-stream } " use it to perform the disposal." } ;
! Copyright (C) 2018 Alexander Ilin.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors checksums checksums.common destructors fry kernel
-sequences ;
+USING: accessors checksums checksums.common destructors fry
+kernel sequences ;
IN: checksums.multi
TUPLE: multi-checksum checksums ;
-INSTANCE: multi-checksum block-checksum
+
C: <multi-checksum> multi-checksum
TUPLE: multi-state < disposable states results ;
M: multi-checksum initialize-checksum-state
- checksums>> [ initialize-checksum-state ] V{ } map-as
+ checksums>> [ initialize-checksum-state ] map
multi-state new-disposable swap >>states ;
M: multi-state dispose*
M: multi-state get-checksum
dup results>> [
- dup states>> [ get-checksum ] { } map-as [ >>results ] keep
+ dup states>> [ get-checksum ] map [ >>results ] keep
] unless* nip ;
+
+INSTANCE: multi-checksum block-checksum