Data::BitStream::Code::StartStop - A Role implementing Start/Stop and Start-Step-Stop codes
version 0.08
A role written for Data::BitStream that provides get and set methods for Start/Stop and Start-Step-Stop codes. The role applies to a stream object.
Start-Step-Stop codes are described in Fiala and Greene (1989). The Start/Stop codes are described in Steven Pigeon (2001) and are a generalization of the S-S-S codes. This implementation turns the Start-Step-Stop parameters into Start/Stop codes.
use Data::BitStream; my $stream = Data::BitStream->new; my @array = (4, 2, 0, 3, 7, 72, 0, 1, 13); $stream->put_startstop( [0,3,2,0], @array ); $stream->rewind_for_read; my @array2 = $stream->get_startstop( [0,3,2,0], -1); $stream->erase_for_write; $stream->put_startstepstop( [3,2,9], @array ); $stream->rewind_for_read; my @array3 = $stream->get_startstepstop( [3,2,9], -1); # @array equals @array2 equals @array3
Given a set of parameters @m, returns the maximum integer that can be encoded with those parameters (the minimum is always 0, like other codes). For example, for two example the {0,3,2,0} parameters from Pigeon's paper:
{0,3,2,0}
$maxval = Data::BitStream::Code::StartStop::max_code_for_startstop([0,3,2,0]); # $maxval will be 72 $maxval = Data::BitStream::Code::StartStop::max_code_for_startstop([3,3,3,0]); # $maxval will be 1095
Insert one or more values as Start/Stop codes. Returns 1.
Insert one or more values as Start-Step-Stop codes. Returns 1.
Decode one or more Start/Stop codes from the stream. If count is omitted, one value will be read. If count is negative, values will be read until the end of the stream is reached. In scalar context it returns the last code read; in array context it returns an array of all codes read.
Decode one or more Start-Step-Stop codes from the stream. If count is omitted, one value will be read. If count is negative, values will be read until the end of the stream is reached. In scalar context it returns the last code read; in array context it returns an array of all codes read.
The Start/Stop and Start-Step-Stop parameters are passed as a array reference.
For Start-Step-Stop codes, there must be exactly three entries. All three parameters must be greater than or equal to zero. These are turned into Start/Stop codes.
There must be a minimum of two Start/Stop parameters. Each parameter must be greater than or equal to zero. A parameter of undef will be treated as equal to the maximum supported bits in an integer.
These methods are required for the role.
Dana Jacobsen <dana@acm.org>
Copyright 2011-2012 by Dana Jacobsen <dana@acm.org>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Data::BitStream, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::BitStream
CPAN shell
perl -MCPAN -e shell install Data::BitStream
For more information on module installation, please visit the detailed CPAN module installation guide.