Algorithm-LCSS
view release on metacpan or search on metacpan
3637383940414243444546474849505152535455565758596061626364656667686970717273747576
}
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
93949596979899100101102103104105106107108109110111112113faster 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
555657585960616263646566676869707172737475<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
<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
454647484950515253545556575859606162636465fix_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.387 second using v1.01-cache-2.11-cpan-95122f20152 )