Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

In a reply to Netflix (or on handling large amounts of data efficiently in perl), I suggested that Judy::1/Judy1(3) was a sparse bit vector which might be interesting as a replacement for vec(). Perl's built-in vec can also be used as a bit vector but it's not sparse - all bits between the zeroth to the highest ever set are instantiated inside a perl string. This is only convenient if your bit vector isn't too big in ram.

Example code

A simple perl bit vector

use constant MEGABYTE => 2 ** 20; my $vector = ''; # 5,000 bits. Set every 100th bit between 15 million and 20 million. for ( 15_000_000 .. 20_000_000 ) { if ( ! ( $_ % 100 ) ) { vec( $vector, $_, 1 ) = 1; } } printf "%0.1fM\n", length( $vector ) / MEGABYTE;

A simple Judy::1 bit vector

use constant KILOBYTE => 2 ** 10; use Judy::1 qw( Set MemUsed ); my $vec; # 5,000 bits. Set every 100th bit between 15 million and 20 million. for ( 15_000_000 .. 20_000_000 ) { if ( ! ( $_ % 100 ) ) { Set( $judy, $_ ); } } printf "%0.1fK\n", MemUsed( $judy ) / KILOBYTE;

Memory "benchmarks"

Tests using the entire range 0..20,000,000
Every bit2.3M618K
Tests using range 15,000,000..20,000,000
Every bit2.3M162K
Every 10th bit2.3M772K
Every 100th bit2.3M158K
Every 1000th bit2.3M65K

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

In reply to Compact and sparse bit vector by diotalevi

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (4)
    As of 2019-08-25 19:49 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found