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 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 or C, available on CPAN. =head1 METHODS =over 4 =item I<$a> = C C I<$nA> Creates and returns a new C object. The object represents a set of integers in the range 0..I<$nA>-1. =item I<$a>->C(I<$n>) Inserts the integer I<$n> into the set I<$a>. =item I<$a>->C(I<$n>) Removes the integer I<$n> from the set I<$a>. =item I<$a>->C(I<$n>) Returns true iff the integer I<$n> is an element of the set I<$a>. =item I<$c> = C I<$a> I<$b> Returns the union of I<$a> I<$b> =item I<$c> = C I<$a> I<$b> Returns the intersection of I<$a> I<$b> =item I<@elements> = I<$c>->C Returns a list of the elements of I<$a>. =item I<$elements> = I<$a>->C Returns a print representation of $a. =item I<$a>->C Prints the machine address of the C struct for $a. =back =head1 AUTHOR Steven McDougall, swmcd@world.std.com =head1 SEE ALSO perl(1), Set::IntRange, Bit::Vector =cut