=head2 index Usage : my $bucket = Data::Bucket->index(data => strings, %other); Purpose : Build a data structure with @strings partitioned into buckets Returns : An object. Argument : A list of data compatible with the compute_index() function =cut sub index { my ($class, %parm) = @_; exists $parm{data} or die "Data must be passed for indexing" ; ref $parm{data} eq 'ARRAY' or die 'You must pass an array ref'; my $self = bless (\%parm, ref ($class) || $class); $self->bucket_hash; return $self; } =head2 bucket_hash Usage : Called internally by index() Purpose : Partition $self->{data} by repeated calls to $self->compute_record_index Returns : Nothing Argument : None. =cut sub bucket_hash { my ($self) = @_; for my $data (@{$self->{data}}) { my $index = $self->compute_record_index($data); my @index = ref $index eq 'ARRAY' ? @$index : ($index) ; for (@index) { push @{ $self->{bucket}{$_} } , $data ; } } return $self; }