You could turn this:
        if( grep( $_, @{ $sets[ $set ] } ) == @{ $sets[ $set ] } ) {
into a use of all from List::MoreUtils:
if( all { $_ } @{ $sets[ $set ] } ) {
(Note that the overhead of a function in this module is larger than the overhead of a plain grep.)

But I think may get a better result by inverting the boolean, and thus setting the boolean for each item before you start, and clearing its value. Testing if an array contains no true value at all, might be faster than testing if enough of them are true. Anyway, I don't expect you can even double the speed this way...

Also, you might reconsider using vec and storing an array of booleans into a single string (of bits). That way testing every item in a set is simply a matter of a single test on a string, instead of testing each item in a whole array.


In reply to Re: Better algorithm or data structure? by bart
in thread Better algorithm or data structure? by BrowserUk

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.