File: Utils.pm

package info (click to toggle)
munin 2.0.6-4%2Bdeb7u2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,944 kB
  • sloc: perl: 11,577; sh: 2,939; java: 1,880; makefile: 726; python: 272
file content (67 lines) | stat: -rw-r--r-- 895 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package Munin::Node::Utils;

# $Id$

use strict;
use warnings;

use Exporter ();
our @ISA = qw/Exporter/;
our @EXPORT_OK = qw/
	set_difference
	set_intersection
/;


### Set operations #############################################################

sub set_difference
{
    my ($A, $B) = @_;
    my %set;
    @set{@$A} = ();
    delete @set{@$B};
    return sort keys %set;
}


sub set_intersection
{
    my ($A, $B) = @_;
    my %set;
    @set{@$A} = (1) x @$A;
    return sort grep $set{$_}, @$B;
}


1;

__END__


=head1 NAME

Munin::Node::Utils - Various utility functions


=head1 SYNOPSIS

  use Munin::Node::Utils qw( ... );


=head1 SUBROUTINES

=over

=item B<set_difference(\@a, \@b)>

Returns the list of elements in arrayref \@a that are not in arrayref \@b.


=item B<set_intersection(\@a, \@b)>

Returns the list of elements common to arrayrefs \@a and \@b.


=cut
# vim: ts=4 : et