Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Following up on Re: vec overflow? an adjustable example (mini vec tutorial)

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; my @ints = qw/ 0 0 0 1 1 2 9 11 11 20 22 22 55 /; #~ my $power = 8; my $repeat = 0; #~ my $power = 2; my $repeat = 14; #~ my $power = 1; my $repeat = 28; my $power = 3; my $repeat = 7; #~ my $power = 28; my $repeat = 8; ## (chr(0)x2**28)x8 my $max = 2**$power; my $maxminone = $max-1; my @seen_vecs = ( chr(0) x $max ) x $repeat;; @seen_vecs = '' unless@seen_vecs ; dd\@seen_vecs; print "\n(2**$power=($max)*8=(l@{[$max*8]}))x[$repeat]\n"; print "max bit \@v[$repeat][@{[$max*8]}]\n\n"; my @uniq ; for my $int( @ints ){ my $index = $int >> $power; my $offset = $int & $maxminone ; #~ my $vec = \vec( $seen_vecs[ $int >> $power ], $int & $maxminone + , 1);; my $vec = \vec( $seen_vecs[ $index ], $offset, 1);; next if $$vec ; ## skip if seen ## $seen...[$index]->get( $offset +); push @uniq, $int; $$vec=1; ## mark as seen ## $seen...[$index]->set( $offset +); printf "%3u@[%2u][%2u]= %s\n", $int , $index, $offset,unpack('b*', + $seen_vecs[ $index ]), ; printf " %s\n", (' ' x $offset ).'^'.$int; } dd({ints=>\@ints,uniq=>\@uniq,seen=>\@seen_vecs}); __END__

The @ in the output it produces is used for meaning of "@at", its not an actual array :) for example  0@[ 0][ 0] means the number zero is stored in the first(zero-th,0-th) seen_vecs string, and its the first bit of the string (0-th bit) ; neat how that works, id-zero is zero-th bit, is offset-th-ed-bit :)

[ "\0\0\0\0\0\0\0\0", "\0\0\0\0\0\0\0\0", "\0\0\0\0\0\0\0\0", "\0\0\0\0\0\0\0\0", "\0\0\0\0\0\0\0\0", "\0\0\0\0\0\0\0\0", "\0\0\0\0\0\0\0\0", ] (2**3=(8)*8=(l64))x[7] max bit @v[7][64] 0@[ 0][ 0]= 10000000000000000000000000000 ^0 1@[ 0][ 1]= 11000000000000000000000000000 ^1 2@[ 0][ 2]= 11100000000000000000000000000 ^2 9@[ 1][ 1]= 01000000000000000000000000000 ^9 11@[ 1][ 3]= 01010000000000000000000000000 ^11 20@[ 2][ 4]= 00001000000000000000000000000 ^20 22@[ 2][ 6]= 00001010000000000000000000000 ^22 55@[ 6][ 7]= 00000001000000000000000000000 ^55 { ints => [0, 0, 0, 1, 1, 2, 9, 11, 11, 20, 22, 22, 55], seen => [ "\a\0\0\0\0\0\0\0", "\n\0\0\0\0\0\0\0", "P\0\0\0\0\0\0\0", "\0\0\0\0\0\0\0\0", "\0\0\0\0\0\0\0\0", "\0\0\0\0\0\0\0\0", "\x80\0\0\0\0\0\0\0", ], uniq => [0, 1, 2, 9, 11, 20, 22, 55], }

This can help with the vec syntax :) Bit::Vector::Minimal - Object-oriented vec wrapper


In reply to Re^4: DBI::SQLite slowness ( mini vec tutorial ) by Anonymous Monk
in thread DBI::SQLite slowness by Endless

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, 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?
    Username:
    Password:

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others having a coffee break in the Monastery: (4)
    As of 2024-09-14 14:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The PerlMonks site front end has:





      Results (21 votes). Check out past polls.

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.