-
Notifications
You must be signed in to change notification settings - Fork 4
/
Blob2CmtMerge.perl
executable file
·70 lines (57 loc) · 1.33 KB
/
Blob2CmtMerge.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
65
66
67
68
69
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];
}
my %b2c;
tie %b2c, "TokyoCabinet::HDB", "$ARGV[1]", TokyoCabinet::HDB::OWRITER | TokyoCabinet::HDB::OCREAT,
16777213, -1, -1, TokyoCabinet::TDB::TLARGE, 100000
or die "cant open $ARGV[1]\n";
my %b2c1;
my $lines = 0;
procBin ($ARGV[0]);
sub procBin {
my $fname = $_[0];
print "processing $fname\n";
open A, "gunzip -c $fname|";
binmode(A);
until (eof(A))
{
my $buffer;
my $nread = read (A, $buffer, 4, 0);
my $n = unpack 'L', $buffer;
#print "$nread;$n\n";
$nread = read (A, $buffer, 20, 0);
my $cmt = $buffer;
#print "".(toHex ($cmt))."\n";
my %vs = ();
for my $i (1..$n){
$nread = read (A, $buffer, 20, 0);
my $b = substr ($buffer, 0, 20);
$b2c1{$cmt}{$b}++;
}
$lines ++;
print STDERR "$lines done\n" if (!($lines%5000000));
}
}
$lines = 0;
while (<STDIN>){
chop();
my ($c, $bb) = split(/\;/, $_, -1);
my $cmt = fromHex ($c);
my $b = fromHex ($bb);
$b2c1{$b}{$cmt}++;
$lines ++;
print STDERR "$lines read\n" if (!($lines%5000000));
}
while (my ($k, $v) = each %b2c1){
my $vv = join "", (sort keys %{$v});
$b2c{$k} = $vv;
}
untie %b2c;