package Set::Bit;

use strict;
use vars qw($VERSION @ISA);

require Exporter;
require DynaLoader;

@ISA = qw(Exporter DynaLoader);
$VERSION = '1.01';

bootstrap Set::Bit $VERSION;

sub elements
{
    my $set = shift;
    grep { $set->member($_) } 0..$set->top
}

sub print
{
    my $set = shift;
    join ", ", $set->elements
}

sub print_address
{
    my $set = shift;
    printf STDERR "vector %p\n", $$set;
}
 
1

__END__

=head1 NAME

Set::Bit - Set of bits

=head1 SYNOPSIS

    use Set::Bit;

    $a = new Set::Bit $nA;
    $b = new Set::Bit $nB;

    $a->insert($n);
    $a->remove($n);
    $a->member($n) and ...
    
    $c = union     $a $b
    $d = intersect $a $b
    
    $elements = $a->elements;
    $elements = $a->print;
                $a->print_address;

=head1 DESCRIPTION

C<Set::Bit> implements a set of integers in the range 0..n;
It allocates a single bit for each integer in the range, 
so storage is compact and set operations are fast.

This module was written for instructional purposes.
If you actually want a set like this, 
consider using C<Set::IntRange> or C<Bit::Vector>,
available on CPAN.

=head1 METHODS

=over 4

=item I<$a> = C<new> C<Set::Bit> I<$nA>

Creates and returns a new C<Set::Bit> object.
The object represents a set of integers in the range 0..I<$nA>-1.

=item I<$a>->C<insert>(I<$n>)

Inserts the integer I<$n> into the set I<$a>.

=item I<$a>->C<remove>(I<$n>)

Removes the integer I<$n> from the set I<$a>.

=item I<$a>->C<member>(I<$n>)

Returns true iff the integer I<$n> is an element of the set I<$a>.

=item I<$c> = C<union> I<$a> I<$b>

Returns the union of I<$a> I<$b>

=item I<$c> = C<intersect> I<$a> I<$b>

Returns the intersection of I<$a> I<$b>

=item I<@elements> = I<$c>->C<elements>

Returns a list of the elements of I<$a>.

=item I<$elements> = I<$a>->C<print>

Returns a print representation of $a.

=item I<$a>->C<print_address>

Prints the machine address of the C<Vector> struct for $a.

=back

=head1 AUTHOR

Steven McDougall, swmcd@world.std.com

=head1 SEE ALSO

perl(1), Set::IntRange, Bit::Vector

=cut
