Acme-Bitfield

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


Sets the raw binary representation. The input string will be truncated or padded to match the `size`, and any excess
bits in the last byte will be zeroed.

## `fill( )`

Sets all bits within the `size` to 1.

## `find_missing( )`

Returns the index of the first bit set to 0, or `undef` if all bits are set.

## `inverse( )`

Returns a new bitfield object with all bits within the `size` inverted. Bit 0 becomes 1, and 1 becomes 0.

## `union( $other )`

Returns a new bitfield object representing the bitwise OR of this bitfield and `$other`.

## `intersection( $other )`

lib/Acme/Bitfield.pod  view on Meta::CPAN


Sets the raw binary representation. The input string will be truncated or padded to match the C<size>, and any excess
bits in the last byte will be zeroed.

=head2 C<fill( )>

Sets all bits within the C<size> to 1.

=head2 C<find_missing( )>

Returns the index of the first bit set to 0, or C<undef> if all bits are set.

=head2 C<inverse( )>

Returns a new bitfield object with all bits within the C<size> inverted. Bit 0 becomes 1, and 1 becomes 0.

=head2 C<union( $other )>

Returns a new bitfield object representing the bitwise OR of this bitfield and C<$other>.

=head2 C<intersection( $other )>

t/basics.t  view on Meta::CPAN

        $bf->set(0);    # Should be 0x80 in the first byte
        is unpack( 'H*', $bf->data ), '80', 'Index 0 is high bit of first byte';
        $bf->clear(0);
        $bf->set(7);    # Should be 0x01
        is unpack( 'H*', $bf->data ), '01', 'Index 7 is low bit of first byte';
    };
    subtest 'Fill and Find Missing' => sub {
        my $bf = Acme::Bitfield->new( size => 5 );
        $bf->fill();
        is $bf->count,          5,     'All 5 bits set';
        is $bf->find_missing(), undef, 'No missing bits';
        $bf->clear(2);
        is $bf->find_missing(), 2, 'Found missing bit at index 2';
    };
};
subtest Inverse => sub {
    subtest 'Inverse Method' => sub {
        my $bf = Acme::Bitfield->new( size => 10 );
        $bf->set(0);
        $bf->set(5);
        $bf->set(9);



( run in 1.839 second using v1.01-cache-2.11-cpan-d80b1682f3f )