++ed by:
John Gamble
and 1 contributors

# NAME

Algorithm::QuineMcCluskey::Util - provide utility functions to Algorithm::QuineMcCluskey

# DESCRIPTION

This module provides various utilities designed for (but not limited to) use in Algorithm::QuineMcCluskey.

The prime implicant and essentials "tables" are in the form of a hash of array refs, and are manipulated with the functions find_essentials(), least_covered(), purge_elements(), remels(), row_dominance(), transpose(), and uniqels().

## FUNCTIONS

### matchcount()

Returns the count of a search string Y found in the source string X.

E.g.:

``````    my \$str = "d10d11d1d";
matchcount(\$str, "d");     # returns 4
matchcount(\$str, "d1");    # returns 3``````

To search for only the string without a regular expression accidentally interfering, enclose the search string between '\Q' and '\E'. E.g.:

``````    #
# We don't know what's in \$looking, so de-magic it.
#
matchcount(\$str, '\E' . \$looking . '\Q]);``````

Returns the terms that match a mask made up of zeros, ones, and don't-care characters.

``    my @rterms = maskedmatch("010-0", @terms);``

Returns the indexes of the terms that match a mask made up of zeros, ones, and don't-care characters.

``    my @pos = maskedmatchindexes("010-0", @terms);``

### find_essentials()

Find the essential prime implicants in a primes table.

``    my @essentials = find_essentials(\%primes);``

### row_dominance()

Row dominance checking.

``````    @dominated_rows = row_dominance(\%primes, 0);

@dominant_rows = row_dominance(\%primes, 1);``````

A row i of a PI chart dominates row j if row i contains an x in each column dominated by it.

A column p of a PI chart dominates column q if column p contains an x in each row dominated by it.

Return those rows (columns are handled by rotating the primes hash before calling this function).

### covered_least()

Find the term with the fewest implicant covers, along with a list of those covers.

``    my(\$term, @covers) = covered_least(\%primes);``

### purge_elements()

``    purge_elements(\%prime_implicants, @essentials);``

Given a table of prime implicants, delete the list of elements (usually the essential prime implicants) from the table, both row-wise and column-wise.

### remels()

Given a reference to a hash of arrayrefs and a reference to an array of values, remove the values from the individual arrayrefs if the values matches their masks.

Deletes the entire arrayref from the hash if the last element of the array is removed.

``    remels(\%primes, @elements);``

Returns the number of removals made.

### uniqels()

Returns the unique arrays from an array of arrays (i.e., we're ensuring non-duplicate answers).

``    my @uels = uniqels(@els);``

### transpose()

Transposes a hash-of-arrays structure of the type used for %primes.

``    my %table90 = transpose(\%table)``

### 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);``

Algorithm::QuineMcCluskey

# AUTHOR

Darren M. Kulp `<darren@kulp.ch>`

John M. Gamble jgamble@cpan.org (current maintainer)