improved the efficiency of the isIn function as suggested by "John W. Krahn" <krahnj@acm.org>
This commit is contained in:
parent
aea57457bb
commit
84f741e806
1 changed files with 3 additions and 17 deletions
|
|
@ -98,23 +98,9 @@ An array to look for the value in.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub isIn {
|
sub isIn {
|
||||||
my ($i, @a, @b, @isect, %union, %isect, $e);
|
my $key = shift;
|
||||||
foreach $e (@_) {
|
$_ eq $key and return 1 for @_;
|
||||||
if ($a[0] eq "") {
|
return 0;
|
||||||
$a[0] = $e;
|
|
||||||
} else {
|
|
||||||
$b[$i] = $e;
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach $e (@a, @b) { $union{$e}++ && $isect{$e}++ }
|
|
||||||
@isect = keys %isect;
|
|
||||||
if (@isect) {
|
|
||||||
undef @isect;
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue