Statistics::SparseVector - Perl5 extension for manipulating sparse bitvectors
use Statistics::SparseVector; # methods that create new bitvectors $vec = Statistics::SparseVector->new($n); $vec2 = $vec1->Clone(); $vec = Statistics::SparseVector->new_Enum($s, $n); $vec = Statistics::SparseVector->new_Bin($s, $n); # miscellaneous $vec2->Substitute_Vector($vec1, $of22, $len2, $off1, $len1); $vec->Size(); $vec->to_Enum(); $vec->to_Bin(); $vec->Fill(); $vec->Empty(); $vec->increment(); $n = $vec->Norm(); @list = $vec->indices(); # manipulation on the bit level $vec->Bit_Off($i); $vec->Bit_On($i); $vec->bit_flip($i); $vec->bit_test($i); # overloaded operators # increment $vec++; # stringify "$vec"
This module implements sparse bitvectors. Several methods for manipulating bitvectors are implemented. On purpose the naming of the methods is identical to the Bit::Vector package by Stephen Beyer; if you find your vectors to be sparse (have little bits that are on) you can easily switch to a less memory consuming representation.
new
$vec = Statistics::BitVector->new($n);
A bitvector of length $n is created. All bits are zero.
$n
Clone
$clone = $vec->Clone();
A copy of $vec is returned.
$vec
new_Enum
$vec = Statistics::BitVector->new_Enum($enumstring, $n);
A new bitvector of length $n is created from the comma-separated list of in $enumstring.
$enumstring
new_Bin
$vec = Statistics::BitVector->new_Bin($bitstring, $n);
A new bitvector of length $n is created from bitstring $bitstring.
$bitstring
Substitute_Vector
$vec2->Substitute_Vector($vec1, $off2, $len2, $off1, $len1);
$len2 contiguous bits in target vector $vec2 starting from $off2 are replaced by $len1 contiguous bits from source vector $vec1 starting at bit $off1. If $off2 equals the length of $vec2 the bits from $vec1 are appended. If $len1 is zero the $len2 bits from $vec2 are deleted.
$len2
$vec2
$off2
$len1
$vec1
$off1
Fill
$vec->Fill();
All bits of $vec are set to one.
Empty
$vec->Empty();
All bits of $vec are set to zero.
increment
$vec->increment(); $vec++;
The integer value of the bitvector is increased by one.
Bit_Off
$vec->Bit_Off($i);
Bit $i is set to zero.
$i
Bit_On
$vec->Bit_On($i);
Bit $i is set to one.
bit_flip
$vec->bit_flip($i);
Bit $i is flipped.
bit_test
$vec->bit_test($i);
Returns 1 if bit $i is one, 0 otherwise.
1
0
Size
$n = $vec->Size();
Returns the size of the vector.
to_Enum
$enumstring = $vec->to_Enum();
Returns a comma-separated list of bits that are set.
indices
Returns an array of indices of bits that are set.
to_Bin
$bitstring = $vec->to_Bin();
Returns a bitstring; bits should be read from right to left.
Norm
Returns the number of set bits.
++
$vec++;
Same as method increment.
$string = "$vec";
Data::Dumper wants to stringify vectors. Probably because Statistics::SparseVector is an overloaded package it expects double quotes to be overloaded as well.
Data::Dumper
Statistics::SparseVector
Internally sparse vectors are represented by hashes.
Only a few methods from Bit::Vector are implemented. Maybe new ones will follow in the future.
Method Substitute_Vector is not thorougly debugged.
Version 0.1.
perl(1), Bit::Vector(3), Statistics::MaxEntropy(3), Statistics::ME.wrapper.pl(3), Statistics::Candidates(3).
Statistics::MaxEntropy comes with ABSOLUTELY NO WARRANTY and may be copied only under the terms of the GNU Library General Public License (version 2, or later), which may be found in the distribution.
Statistics::MaxEntropy
To install Statistics::MaxEntropy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Statistics::MaxEntropy
CPAN shell
perl -MCPAN -e shell install Statistics::MaxEntropy
For more information on module installation, please visit the detailed CPAN module installation guide.