Data::BitStream::BitVec - A Bit::Vector implementation of Data::BitStream
use Data::BitStream::BitVec; my $stream = Data::BitStream::BitVec->new; $stream->put_gamma($_) for (1 .. 20); $stream->rewind_for_read; my @values = $stream->get_gamma(-1);
An implementation of Data::BitStream. See the documentation for that module for many more examples, and Data::BitStream::Base for the API. This document only describes the unique features of this implementation, which is of limited value to people purely using Data::BitStream.
This implementation uses the Bit::Vector module for internal data storage, as that module has a number of very efficient methods for manipulating vectors. However, Bit::Vector stores and accesses all its data in little-endian form, making it extremely difficult to use as a bit stream. Hence some functions such as get_unary are blazing fast, as we can use one of the nice Bit::Vector functions. Many other functions are just as difficult or more difficult to create as regular vectors, and often turn out slower.
get_unary
Another interesting observation is that Bit::Vector is quite slow to resize the vector. Hence this implementation takes a rather aggressive stance in resizing, bumping up the size to 1.15 * (needed_bits + 2048) when the vector needs to grow. When the stream is closed for writing, it is resized to just the size needed.
1.15 * (needed_bits + 2048)
Hence this implementation mainly serves as an example. An XS implementation of a big-endian vector would make this extremely fast.
A private Bit::Vector object.
Resizes the vector to 0.
Resizes the vector to the actual length.
These methods have custom implementations.
The following roles are included.
Dana Jacobsen <dana@acm.org>
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.
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.