-
Notifications
You must be signed in to change notification settings - Fork 4
/
Blob2Author.perl
executable file
·68 lines (55 loc) · 1.49 KB
/
Blob2Author.perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl
use lib ("$ENV{HOME}/lookup", "$ENV{HOME}/lib64/perl5", "/home/audris/lib64/perl5","$ENV{HOME}/lib/perl5", "$ENV{HOME}/lib/x86_64-linux-gnu/perl", "$ENV{HOME}/share/perl5");
use strict;
use warnings;
use Error qw(:try);
use TokyoCabinet;
use Compress::LZF;
sub toHex {
return unpack "H*", $_[0];
}
sub fromHex {
return pack "H*", $_[0];
}
#BEGIN { $SIG{'__WARN__'} = sub { print STDERR $_[0]; } };
my $split = 32;
my (%c2ta);
my $ver = $ARGV[0];
for my $s (0..($split-1)){
tie %{$c2ta{$s}}, "TokyoCabinet::HDB", "/fast/c2taFull$ver.$s.tch", TokyoCabinet::HDB::OREADER| TokyoCabinet::HDB::ONOLCK,
16777213, -1, -1, TokyoCabinet::TDB::TLARGE, 100000
or die "cant open /fast/c2taFull$ver.$s.tch\n";
}
my $bp = "";
my ($bh, $ch) = ("","");
my %as = ();
while (<STDIN>){
chop();
($bh, $ch) = split(/\;/, $_, -1);
if ($bp ne "" && $bp ne $bh){
output (\%as);
%as = ();
}
my $c = fromHex ($ch);
my $s = (unpack "C", substr ($c, 0, 1)) % $split;
if (defined $c2ta{$s}{$c}){
my ($t, $a) = split (/;/, $c2ta{$s}{$c});
$as{$t}{"$ch;$a"}++;
}else{
print STDERR "no time for $ch in $bh\n";
}
$bp = $bh;
}
output (\%as);
sub output {
my $asp = $_[0];
my %as = %{$asp};
my $f = (sort { $a+0 <=> $b +0 } keys %as)[0];
my @aa = sort keys %{$as{$f}};
print STDERR "same time $bh;$ch;@aa\n" if $#aa>0;
my ($ch0, $au) = split (/;/, $aa[0], -1);
print "$bp;$f;$au;$ch0\n";
}
for my $s (0..($split-1)){
untie %{$c2ta{$s}};
};