X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FPrefix.pm;h=1e74d63dbc2f8a4f141d2ca646da4650cc2dc42d;hb=refs%2Fheads%2Fnewusers;hp=2572cb8794f5a2b801ab97d904fd30cadcc4309f;hpb=7b9256ceade8b18b48f848c9ac659c2de7322b0b;p=spider.git diff --git a/perl/Prefix.pm b/perl/Prefix.pm index 2572cb87..1e74d63d 100644 --- a/perl/Prefix.pm +++ b/perl/Prefix.pm @@ -3,7 +3,7 @@ # # Copyright (c) - Dirk Koopman G1TLH # -# $Id$ +# # package Prefix; @@ -72,7 +72,10 @@ sub load # tie the main prefix database eval {$db = tie(%pre, "DB_File", undef, O_RDWR|O_CREAT, 0664, $DB_BTREE);}; my $out = "$@($!)" if !$db || $@ ; - eval {do "$main::data/prefix_data.pl" if !$out; }; + my $fn = localdata("prefix_data.pl"); + die "Prefix.pm: cannot find $fn, have you run /spider/perl/create_prefix.pl?" unless -e $fn; + + eval {do $fn if !$out; }; $out .= $@ if $@; $lru = LRU->newbase('Prefix', $lrusize); @@ -88,7 +91,7 @@ sub store { my ($k, $l); my $fh = new IO::File; - my $fn = "$main::data/prefix_data.pl"; + my $fn = localdata("prefix_data.pl"); confess "Prefix system not started" if !$db; @@ -170,6 +173,7 @@ sub next sub lru_put { my ($call, $ref) = @_; + $call =~ s/^=//; my @s = USDB::get($call); if (@s) { @@ -245,12 +249,26 @@ sub extract LM: foreach $call (split /,/, $calls) { - # first check if the whole thing succeeds either because it is cached - # or because it simply is a stored prefix as callsign (or even a prefix) $matchtotal++; $call =~ s/-\d+$//; # ignore SSIDs - my $p = $lru->get($call); my @nout; + my $ecall = "=$call"; + + # first check if this is a call (by prefixing it with an = sign) + my $p = $lru->get($ecall); + if ($p) { + $hits++; + if (isdbg('prefix')) { + my $percent = sprintf "%.1f", $hits * 100 / $misses; + dbg("Prefix Exact Cache Hit: $call Hits: $hits/$misses of $matchtotal = $percent\%"); + } + push @out, @$p; + next; + } + + # then check if the whole thing succeeds either because it is cached + # or because it simply is a stored prefix as callsign (or even a prefix) + $p = $lru->get($call); if ($p) { $hits++; if (isdbg('prefix')) { @@ -259,26 +277,37 @@ LM: foreach $call (split /,/, $calls) { } push @out, @$p; next; + } + + # is it in the USDB, force a matchprefix to match? + my @s = USDB::get($call); + if (@s) { + @nout = get($call); + @nout = matchprefix($call) unless @nout; + $nout[0] = $ecall if @nout; } else { - - # is it in the USDB, force a matchprefix to match? - my @s = USDB::get($call); - if (@s) { - @nout = get($call); - @nout = matchprefix($call) unless @nout; - $nout[0] = $call if @nout; - } else { - @nout = get($call); - } - # now store it - if (@nout && $nout[0] eq $call) { - $misses++; - lru_put($call, \@nout); - dbg("got exact prefix: $nout[0]") if isdbg('prefix'); - push @out, @nout; - next; - } + # try a straight get for an exact callsign + @nout = get($ecall); + } + + # now store the exact prefix if it has been found + if (@nout && $nout[0] eq $ecall) { + $misses++; + $nout[0] = $call; + lru_put("=$call", \@nout); + dbg("got exact prefix: $nout[0]") if isdbg('prefix'); + push @out, @nout; + next; + } + + # now try a non-exact call/prefix + if ((@nout = get($call)) && $nout[0] eq $call) { + $misses++; + lru_put($call, \@nout); + dbg("got exact prefix: $nout[0]") if isdbg('prefix'); + push @out, @nout; + next; } # now split the call into parts if required @@ -416,7 +445,7 @@ L1: for ($n = 0; $n < @parts; $n++) { } # we are a pirate! - @nout = matchprefix('Q'); + @nout = matchprefix('QQ'); $misses++; lru_put($call, \@nout); push @out, @nout;