Data::BitStream::Code::Comma - A Role implementing Comma codes
version 0.08
A role written for Data::BitStream that provides get and set methods for Comma codes. The role applies to a stream object.
Comma codes are described in many sources. The codes are written in k-bit chunks, where a chunk consisting of all 1 bits indicates the end of the code. The number to be encoded is stored in base 2^k-1. The case of 1-bit comma codes degenerates into unary codes. The most common comma code in current use is the ternary comma code which uses 2-bit chunks and stores the number in base 3 (hence why it is called ternary comma). Example for ternary comma:
k
2^k-1
value code binary bits 0 c 11 2 1 1c 0111 4 2 2c 1011 4 3 10c 010011 6 4 11c 010111 6 .. 8 22c 101011 6 9 100c 01000011 8 .. 64 2101c 1001000111 10 .. 10000 111201101c 01010110000101000111 20
Comma codes using larger chunks compact larger numbers better, but the terminator also grows. This means smaller values take more bits to encode, and all codes have many wasted bits after the information.
Also note that skipping the leading 0s for all codes results in a large waste of space. For instance, the codes 0xc, 0xxc, 0xxxc, etc. are all not used, even though they are uniquely decodable. Note that Fenwick's table 6 (p6) shows 0c being used, but no other leading zero. This is not the case in Sayood's table 3.19 (p71) where no entry has a leading zero.
0
0xc
0xxc
0xxxc
0c
These codes are a special case of the block-based taboo codes (Pigeon 2001). The taboo codes fully utilize all the bits.
Insert one or more values as Comma codes using $bits bits. Returns 1.
$bits
Decode one or more Comma 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 parameter bits must be an integer between 1 and 16. This indicates the number of bits used per chunk.
bits
If bits is 1, then unary coding is used.
Ternary comma coding is the special case of comma coding with bits=2.
bits=2
Byte coding is the special case of comma coding with bits=8.
bits=8
These methods are required for the role.
Dana Jacobsen <dana@acm.org>
Copyright 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.