Algorithm-Diff-Any
view release on metacpan or search on metacpan
lib/Algorithm/Diff/Any.pm view on Meta::CPAN
LCS_length
diff
sdiff
compact_diff
traverse_sequences
traverse_balanced
);
=head1 NAME
Algorithm::Diff::Any - Perl module to find differences between files
=head1 VERSION
Version 1.001 ($Id: Any.pm 10595 2009-12-23 00:29:52Z FREQUENCY@cpan.org $)
=cut
our $VERSION = '1.001';
$VERSION = eval $VERSION;
our $DRIVER = 'PP';
# Try to load the XS version first
eval {
require Algorithm::Diff::XS;
$DRIVER = 'XS';
# Import external subroutines here
no strict 'refs';
for my $func (@EXPORT_OK) {
*{$func} = \&{'Algorithm::Diff::XS::' . $func};
}
};
# Fall back on the Perl version
if ($@) {
require Algorithm::Diff;
# Import external subroutines here
no strict 'refs';
for my $func (@EXPORT_OK) {
*{$func} = \&{'Algorithm::Diff::' . $func};
}
}
=head1 DESCRIPTION
This is a simple module to select the best available implementation of the
standard C<diff> algorithm, which works by effectively trying to solve the
Longest Common Subsequence (LCS) problem. This algorithm is described in:
I<A Fast Algorithm for Computing Longest Common Subsequences>, CACM, vol.20,
no.5, pp.350-353, May 1977.
However, it is algorithmically rather complicated to solve the LCS problem;
for arbitrary sequences, it is an NP-hard problem. Simply comparing two
strings together of lengths I<n> and I<m> is B<O(n x m)>. Consequently, this
means the algorithm necessarily has some tight loops, which, for a dynamic
language like Perl, can be slow.
In order to speed up processing, a fast (C/XS-based) implementation of the
algorithm's core loop was implemented. It can confer a noticable performance
advantage (benchmarks show a 54x speedup for the C<compact_diff> routine).
=head1 SYNOPSIS
use Algorithm::Diff::Any;
my $diff = Algorithm::Diff::Any->new(\@seq1, \@seq2);
For complete usage details, see the Object-Oriented interface description
for the L<Algorithm::Diff> module.
=head1 PURPOSE
The intent of this module is to provide single simple interface to the two
(presumably) compatible implementations of this module, namely,
L<Algorithm::Diff> and L<Algorithm::Diff::XS>.
If, for some reason, you need to determine what version of the module is
actually being included by C<Algorithm::Diff::Any>, then:
print 'Backend type: ', $Algorithm::Diff::Any::DRIVER, "\n";
In order to force use of one or the other, simply load the appropriate module:
use Algorithm::Diff::XS;
my $diff = Algorithm::Diff::XS->new();
# or
use Algorithm::Diff;
my $diff = Algorithm::Diff->new();
=head1 COMPATIBILITY
This module was tested under Perl 5.10.1, using Debian Linux. However, because
it's Pure Perl and doesn't do anything too obscure, it should be compatible
with any version of Perl that supports its prerequisite modules.
If you encounter any problems on a different version or architecture, please
contact the maintainer.
=head1 EXPORTABLE FUNCTIONS
The following functions are available for import into your namespace:
=over
=item * prepare
=item * LCS
=item * LCSidx
=item * LCS_length
=item * diff
=item * sdiff
=item * compact_diff
( run in 0.334 second using v1.01-cache-2.11-cpan-0068ddc7af1 )