File: _Engine.pm

package info (click to toggle)
liblist-compare-perl 0.55-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,012 kB
  • sloc: perl: 3,080; makefile: 2
file content (92 lines) | stat: -rw-r--r-- 2,409 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package List::Compare::Base::_Engine;
our $VERSION = 0.55;
# Holds subroutines used within
# List::Compare::Base::Accelerated and List::Compare::Functional
use Carp;
use List::Compare::Base::_Auxiliary qw(
    _equiv_engine
    _calculate_union_seen_only
    _calculate_seen_only
);
our @ISA = qw(Exporter);
our @EXPORT_OK = qw|
    _unique_all_engine
    _complement_all_engine
|;
use strict;
local $^W = 1;

sub _unique_all_engine {
    my $aref = shift;
    my $seenref = _calculate_seen_only($aref);

    my @all_uniques = ();
    for my $i (sort {$a <=> $b} keys %{$seenref}) {
        my %seen_in_all_others = ();
        for my $j (keys %{$seenref}) {
            unless ($i == $j) {
                for my $k (keys %{$seenref->{$j}}) {
                    $seen_in_all_others{$k}++;
                }
            }

        }
        my @these_uniques = ();
        for my $l (keys %{$seenref->{$i}}) {
            push @these_uniques, $l
                unless $seen_in_all_others{$l};
        }
        $all_uniques[$i]  = \@these_uniques;
    }
    return \@all_uniques;
}

sub _complement_all_engine {
    my ($aref, $unsortflag) = @_;
    my ($unionref, $seenref) = _calculate_union_seen_only($aref);
    my @union = $unsortflag ? keys %{$unionref} : sort(keys %{$unionref});

    # Calculate @xcomplement
    # Inputs:  $aref @union %seen
    my (@xcomplement);
    for (my $i = 0; $i <= $#{$aref}; $i++) {
        my @complementthis = ();
        foreach my $el (@union) {
            push(@complementthis, $el) unless (exists $seenref->{$i}->{$el});
        }
        $xcomplement[$i] = \@complementthis;
    }
    return \@xcomplement;
}

1;


__END__

=head1 NAME

List::Compare::Base::_Engine - Internal use only

=head1 VERSION

This document refers to version 0.55 of List::Compare::Base::_Engine.
This version was released August 16 2020.

=head1 SYNOPSIS

This module contains subroutines used within List::Compare and
List::Compare::Functional.  They are not intended to be publicly callable.

=head1 AUTHOR

James E. Keenan (jkeenan@cpan.org).  When sending correspondence, please
include 'List::Compare' or 'List-Compare' in your subject line.

Creation date:  May 20, 2002.  Last modification date:  August 16 2020.
Copyright (c) 2002-20 James E. Keenan.  United States.  All rights reserved.
This is free software and may be distributed under the same terms as Perl
itself.

=cut