NAME

Data::BitStream::Code::StartStop - A Role implementing Start/Stop and Start-Step-Stop codes

VERSION

version 0.01

DESCRIPTION

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.

EXAMPLES

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

METHODS

Provided Class Methods

max_code_for_startstop([@m])

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:

$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

Provided Object Methods

put_startstop([@m], $value)
put_startstop([@m], @values)

Insert one or more values as Start/Stop codes. Returns 1.

put_startstepstop([$start, $step, $stop], $value)
put_startstepstop([$start, $step, $stop], @values)

Insert one or more values as Start-Step-Stop codes. Returns 1.

get_startstop([@m])
get_startstop([@m], $count)

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.

get_startstepstop([$start, $step, $stop])
get_startstepstop([$start, $step, $stop], $count)

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.

Parameters

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.

Required Methods

maxbits
read
write
skip
put_unary
put_binword
put_rice

These methods are required for the role.

SEE ALSO

Steven Pigeon, "Start/Stop Codes", in Proceedings of the 2001 Data Compression Conference, 2001.
E.R. Fiala, D.H. Greene, “Data Compression with Finite Windows”, Comm ACM, Vol 32, No 4, pp 490–505 , April 1989
Peter Fenwick, "Punctured Elias Codes for variable-length coding of the integers", Technical Report 137, Department of Computer Science, University of Auckland, December 1996

AUTHORS

Dana Jacobsen <dana@acm.org>

COPYRIGHT

Copyright 2011 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.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 318:

Non-ASCII character seen before =encoding in '“Data'. Assuming UTF-8