Algorithm-QuineMcCluskey
view release on metacpan or search on metacpan
lib/Algorithm/QuineMcCluskey/Util.pm view on Meta::CPAN
my @uels = uniqels(@els);
=cut
sub uniqels
{
my %h;
return map { $h{ join(",", @{$_}) }++ == 0 ? $_ : () } @_;
}
=head3 transpose()
Transposes a hash-of-arrays structure of the type used for %primes.
my %table90 = transpose(\%table)
=cut
sub transpose
{
my($table) = @_;
my(%r90, %hoh);
#
# Set up a hash-of-hashes, inverting the
# key to array-of-values relationship.
#
for my $r (keys %{$table})
{
$hoh{$_}{$r} = 1 for (@{$table->{$r}});
}
#
# For each key collect those sub-hash keys into arrays.
#
%r90 = map{ ($_ , [ keys %{$hoh{$_}} ]) } keys %hoh;
return %r90;
}
=head3 hammingd1pos()
Very specialized Hamming distance and position function.
Our calling code is only interested in Hamming distances of 1.
In those cases return the string position where the two values differ.
In all the other cases where the distance isn't one, return a -1.
$idx = hammingd1pos($val1, $val2);
=cut
sub hammingd1pos
{
#
# Xor the strings. The result will be a string in the
# non-printing range (in fact equal characters will result
# in a null character), so to each character Or a '0'.
#
my $v = ($_[0] ^ $_[1]) | (qq(\x30) x length $_[0]);
#
# Strings that don't have a Hamming distance of one are of no
# interest. Otherwise, return that character position.
#
return -1 unless(scalar(() = $v=~ m/[^0]/g) == 1);
$v =~ m/[^0]/g;
return pos($v) - 1;
}
=head1 SEE ALSO
L<Algorithm::QuineMcCluskey>
=head1 AUTHOR
Darren M. Kulp C<< <darren@kulp.ch> >>
John M. Gamble B<jgamble@cpan.org> (current maintainer)
=head1 LICENSE AND COPYRIGHT
Copyright (c) 2006 Darren Kulp. All rights reserved. This program is
free software; you can redistribute it and/or modify it under the same
terms as Perl itself.
See L<http://dev.perl.org/licenses/> for more information.
=cut
1;
__END__
( run in 0.641 second using v1.01-cache-2.11-cpan-13bb782fe5a )