Algorithm-LCSS

 view release on metacpan or  search on metacpan

LCSS.pm  view on Meta::CPAN

    }
  return \@match;
}

sub CSS_Sorted {
    my $match = CSS(@_);
    if ( ref $_[0] eq 'ARRAY' ) {
       @$match = map{$_->[0]}sort{$b->[1]<=>$a->[1]}map{[$_,scalar(@$_)]}@$match
    }
    else {
       @$match = map{$_->[0]}sort{$b->[1]<=>$a->[1]}map{[$_,length($_)]}@$match
    }
  return $match;
}

sub LCSS {
    my $is_array = ref $_[0] eq 'ARRAY' ? 1 : 0;
    my $css = CSS(@_);
    my $index;
    my $length = 0;
    if ( $is_array ) {
        for( my $i = 0; $i < @$css; $i++ ) {
            next unless @{$css->[$i]}>$length;
            $index = $i;
            $length = @{$css->[$i]};
        }
    }
    else {
        for( my $i = 0; $i < @$css; $i++ ) {
            next unless length($css->[$i])>$length;
            $index = $i;
            $length = length($css->[$i]);
        }
    }
  return $css->[$index];
}

1;
__END__

=head1 NAME

LCSS.pm  view on Meta::CPAN

faster than String::LCSS.

If you pass the methods array refs you get back array (ref) format data. If
you pass strings you get a string or a ref to an array of strings.

=head1 METHODS

=head2 LCSS

Returns the longest common sub sequence. If there may be more than one (with
exactly the same length) and it matters use CSS instead.

    my $lcss_ary_ref = LCSS( \@SEQ1, \@SEQ2 );  # ref to array
    my $lcss_string  = LCSS( $STR1, $STR2 );    # string

=head2 CSS

Returns all the common sub sequences, unsorted.

    my $css_ary_ref = CSS( \@SEQ1, \@SEQ2 );  # ref to array of arrays
    my $css_str_ref = CSS( $STR1, $STR2 );    # ref to array of strings

html/LCSS.html  view on Meta::CPAN

<P>This module uses Algoritm::Diff to implement LCSS and is orders of magnitude
faster than String::LCSS.</P>
<P>If you pass the methods array refs you get back array (ref) format data. If
you pass strings you get a string or a ref to an array of strings.</P>
<P>
<HR>
<H1><A NAME="methods">METHODS</A></H1>
<P>
<H2><A NAME="lcss">LCSS</A></H2>
<P>Returns the longest common sub sequence. If there may be more than one (with
exactly the same length) and it matters use CSS instead.</P>
<PRE>
    my $lcss_ary_ref = LCSS( \@SEQ1, \@SEQ2 );  # ref to array
    my $lcss_string  = LCSS( $STR1, $STR2 );    # string</PRE>
<P>
<H2><A NAME="css">CSS</A></H2>
<P>Returns all the common sub sequences, unsorted.</P>
<PRE>
    my $css_ary_ref = CSS( \@SEQ1, \@SEQ2 );  # ref to array of arrays
    my $css_str_ref = CSS( $STR1, $STR2 );    # ref to array of strings</PRE>
<P>

misc/make_manifest.pl  view on Meta::CPAN

fix_line_endings($_) for @files;

# remove all the makefile/make rubbish
sub make_clean {
    my $root = shift;
    my ($dirs, $files) = recurse_tree( $root."blib/" );
    my @dirs  = @$dirs;
    my @files = @$files;
    unlink for @files;
    # need to do longest dir paths first - must be deepest
    rmdir for sort {length $b <=> length $a }@dirs;
    my @makefiles = grep { /makefile(?!\.PL)/i } <$root*>;
    unlink for ( @makefiles, $root.'&1', $root.'pm_to_blib', $root.'MANIFEST', $root.'manifest' );
    unlink <${root}pod2htm*>;
}

# recurse the directory tree
sub recurse_tree {
    my $root = shift;
    my @files;
    my @dirs = ($root);



( run in 0.722 second using v1.01-cache-2.11-cpan-65fba6d93b7 )