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.
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.
Hence this implementation mainly serves as an example. An XS implementation of a big-endian vector would make this extremely fast.
Resizes the vector to 0.
Resizes the vector to the actual length.
These methods have custom implementations.
The following roles are included.
Dana Jacobsen <firstname.lastname@example.org>
Copyright 2011 by Dana Jacobsen <email@example.com>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.