← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/pan_genome_post_analysis
  Run on Fri Mar 27 11:43:32 2015
Reported on Fri Mar 27 11:45:28 2015

Filename/Users/ap13/perl5/lib/perl5/Array/Utils.pm
StatementsExecuted 8 statements in 275µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11124µs43µsArray::Utils::::BEGIN@91Array::Utils::BEGIN@91
0000s0sArray::Utils::::array_diffArray::Utils::array_diff
0000s0sArray::Utils::::array_minusArray::Utils::array_minus
0000s0sArray::Utils::::intersectArray::Utils::intersect
0000s0sArray::Utils::::uniqueArray::Utils::unique
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Array::Utils;
2
3=head1 NAME
4
5Array::Utils - small utils for array manipulation
6
7=head1 SYNOPSIS
8
9 use Array::Utils qw(:all);
10
11 my @a = qw( a b c d );
12 my @b = qw( c d e f );
13
14 # symmetric difference
15 my @diff = array_diff(@a, @b);
16
17 # intersection
18 my @isect = intersect(@a, @b);
19
20 # unique union
21 my @unique = unique(@a, @b);
22
23 # check if arrays contain same members
24 if ( !array_diff(@a, @b) ) {
25 # do something
26 }
27
28 # get items from array @a that are not in array @b
29 my @minus = array_minus( @a, @b );
30
31=head1 DESCRIPTION
32
33A small pure-perl module containing list manipulation routines. The module
34emerged because I was tired to include same utility routines in numerous projects.
35
36=head1 FUNCTIONS
37
38=over 4
39
40=item C<unique>
41
42Returns an array of unique items in the arguments list.
43
44=item C<intersect>
45
46Returns an intersection of two arrays passed as arguments, keeping the order of the
47second parameter. A nice side effect of this function can be exploited in situations as:
48
49 @atreides = qw( Leto Paul Alia 'Leto II' );
50 @mylist = qw( Alia Leto );
51 @mylist = intersect( @mylist, @atreides ); # and @mylist is ordered as Leto,Alia
52
53=item C<array_diff>
54
55Return symmetric difference of two arrays passed as arguments.
56
57=item C<array_minus>
58
59Returns the difference of the passed arrays A and B (only those
60array elements that exist in A and do not exist in B).
61If an empty array is returned, A is subset of B.
62
63Function was proposed by Laszlo Forro <salmonix@gmail.com>.
64
65=back
66
67=head1 BUGS
68
69None known yet
70
71=head1 AUTHOR
72
73Sergei A. Fedorov <zmij@cpan.org>
74
75I will be happy to have your feedback about the module.
76
77=head1 COPYRIGHT
78
79This module is Copyright (c) 2007 Sergei A. Fedorov.
80All rights reserved.
81
82You may distribute under the terms of either the GNU General Public
83License or the Artistic License, as specified in the Perl README file.
84
85=head1 WARRANTY
86
87This is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.
88
89=cut
90
912253µs262µs
# spent 43µs (24+19) within Array::Utils::BEGIN@91 which was called: # once (24µs+19µs) by Bio::Roary::AnnotateGroups::BEGIN@23 at line 91
use strict;
# spent 43µs making 1 call to Array::Utils::BEGIN@91 # spent 19µs making 1 call to strict::import
92
931500nsrequire Exporter;
9418µsour @ISA = qw(Exporter);
95
9612µsour %EXPORT_TAGS = (
97 all => [ qw(
98 &unique
99 &intersect
100 &array_diff
101 &array_minus
102 ) ],
103);
10412µsour @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
105
1061400nsour $VERSION = '0.5';
107
108sub unique(@) {
109 return keys %{ {map { $_ => undef } @_}};
110}
111
112sub intersect(\@\@) {
113 my %e = map { $_ => undef } @{$_[0]};
114 return grep { exists( $e{$_} ) } @{$_[1]};
115}
116
117sub array_diff(\@\@) {
118 my %e = map { $_ => undef } @{$_[1]};
119 return @{[ ( grep { (exists $e{$_}) ? ( delete $e{$_} ) : ( 1 ) } @{ $_[0] } ), keys %e ] };
120}
121
122sub array_minus(\@\@) {
123 my %e = map{ $_ => undef } @{$_[1]};
124 return grep( ! exists( $e{$_} ), @{$_[0]} );
125}
126
12718µs1;