Using your sample dataset, this code finds 1187 (of the 1890) sources that cover the 3692056 keys in 61 seconds:

#! perl -slw use strict; use Data::Dump qw[ pp ]; my %sources; my( $key, $source ); while( <> ) { chomp; ( $key, $source ) = split( '\|' ); push @{ $sources{ $source } }, $key; } print 'Sources: ', scalar keys %sources; my @set; ## remove singly paired sources from hash to @set @{ $sources{ $source } } == 1 and push @set, $source and delete $sources{ $source } while $source = each %sources; print 'Sources: ', scalar keys %sources; print 'Set: ', scalar @set; ## index multiply paired sources by key my %keys; while( $source = each %sources ) { my $keysRef = $sources{ $source }; for( my $i = 0; $i < @{ $keysRef }; ++$i ) { push @{ $keys{ $keysRef->[ $i ] } }, $source; } } print 'Keys: ', scalar keys %keys; ## For each source, if every paired key is also paired with at least o +ne other source ## then this source is redundant. while( $source = each %sources ) { my $redundant = 1; my $keysRef = $sources{ $source }; KEY: for my $key ( @{ $keysRef } ) { for my $otherSource ( @{ $keys{ $key } } ) { next KEY if $otherSource ne $source; } $redundant = 0, last; } push @set, $source unless $redundant; } printf "Set contains %d sources\n", scalar @set; <STDIN>; pp \@set;

Outputs:

[10:46:45.31] C:\test>1096794.pl data_locks_keys.txt Sources: 1890 Sources: 1819 Set: 71 Keys: 3692056 Set contains 1187 sources ## hit enter here to dump those sources.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Contemplating some set comparison tasks by BrowserUk
in thread Contemplating some set comparison tasks by dwhite20899

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.