Pathologically Eclectic Rubbish Lister PerlMonks

### Re^4: DBI::SQLite slowness ( mini vec tutorial )

 on Sep 20, 2013 at 13:10 UTC ( #1055024=note: print w/replies, xml ) Need Help??

in reply to Re^3: DBI::SQLite slowness

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__

[download]

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],
}
[download]

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

Create A New User
Node Status?
node history
Node Type: note [id://1055024]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2017-08-21 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (317 votes). Check out past polls.

Notices?