Algorithm-Hamming-Perl
view release on metacpan or search on metacpan
EXPORT SUBROUTINES
hamming (SCALAR)
Returns the Hamming code from the provided input data.
unhamming (SCALAR)
Returns the original data from the provided Hamming
code. Single bit errors are auto corrected.
unhamming_err (SCALAR)
Returns the original data from the provided Hamming
code, and a number counting the number of bytes that
were corrected. Single bit errors are auto corrected.
OTHER SUBROUTINES
Algorithm::Hamming::Perl::hamming_faster ()
This is an optional subroutine that will speed Hamming
encoding if it is run once at the start of the program.
It does this by using a larger (hash) cache of
preprocessed results. The disadvantage is that it uses
more memory, and can add several seconds to invocation
time. Only use this if you are encoding more than 1 Mb
of data.
INSTALLATION
perl Makefile.PL
make
make test
make install
DEPENDENCIES
ExtUtils::MakeMaker
EXAMPLES
See the example perl programs provided with this module
"example*". An encoding and decoding example,
use Algorithm::Hamming::Perl qw(hamming unhamming);
$data = "Hello";
$hamcode = hamming($data);
$original = unhamming($hamcode);
LIMITATIONS
This is Perl only and can be slow. The Hamming encoding used
can only repair a single bit error within a byte - ie if two
bits are damaged within the one byte then this encoding
cannot auto correct the error.
BUGS
Try not to join Hamming encoded strings together - this may
give results that look like a bug. If an odd number of input
byes is encoded, the output code is short half a byte - and
so is padded with '0' bits. Joining these with a string
concatenation will contain the padding bits that will
confuse decoding.
The above problem can occur when inputing and outputing
certain lengths to filehandles. To be safe, my example code
uses a buffer of 3072 bytes - a safe size to use with
filehandles.
AUTHOR
Brendan Gregg <brendan.gregg@tpg.com.au> [Sydney, Australia]
( run in 2.900 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )