summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2020-01-25 16:24:11 +0000
committerdakkar <dakkar@thenautilus.net>2020-01-25 16:24:11 +0000
commit89eec0a86907a881410a5e5ac87cd8dc0268df3d (patch)
tree21398d7ab354c949aa6b35e4098f9a11c6eef6cc
parentsafer socket input? (diff)
downloadMaildirIndexer-89eec0a86907a881410a5e5ac87cd8dc0268df3d.tar.gz
MaildirIndexer-89eec0a86907a881410a5e5ac87cd8dc0268df3d.tar.bz2
MaildirIndexer-89eec0a86907a881410a5e5ac87cd8dc0268df3d.zip
numeric types, not-zero constant
-rw-r--r--lib/MaildirIndexer/Index/ByAddresses.rakumod20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/MaildirIndexer/Index/ByAddresses.rakumod b/lib/MaildirIndexer/Index/ByAddresses.rakumod
index 3e7dc9d..678254e 100644
--- a/lib/MaildirIndexer/Index/ByAddresses.rakumod
+++ b/lib/MaildirIndexer/Index/ByAddresses.rakumod
@@ -20,6 +20,8 @@ has Int $!total-count;
has Hash $!cached-p-given-mailbox .= new;
has Instant $!last-cached-at .= from-posix(0);
+constant $NOT-ZERO = 1e-15;
+
method dump() {
}
@@ -28,13 +30,13 @@ submethod account-for(Str @addresses,Str $mailbox,Int $step) {
$!count-by-mailbox{$mailbox} += $step;
for @addresses -> Str $addr {
- my $pair = ( $addr => $mailbox );
+ my Pair $pair = ( $addr => $mailbox );
$!known-addresses{$addr} += $step;
- my $count = $!count-by-address-and-mailbox{$pair} += $step;
+ my Numeric $count = $!count-by-address-and-mailbox{$pair} += $step;
if ($count) {
- my $a = 1e-15 + $count;
- my $b = 1 + $!count-by-mailbox{$mailbox};
+ my Numeric $a = $NOT-ZERO + $count;
+ my Numeric $b = 1 + $!count-by-mailbox{$mailbox};
$!p-address-given-mailbox{$pair} = $a / $b;
}
else {
@@ -45,10 +47,10 @@ submethod account-for(Str @addresses,Str $mailbox,Int $step) {
# update the cache every 10 seconds
if ((now - $!last-cached-at) > 10) {
for $!count-by-mailbox.keys -> Str $mailbox {
- my $p = $!count-by-mailbox{$mailbox} / $!total-count;
+ my Numeric $p = $!count-by-mailbox{$mailbox} / $!total-count;
for $!known-addresses.keys -> Str $addr {
- my $addr-p = $!p-address-given-mailbox{$addr => $mailbox} // 1e-15;
+ my $addr-p = $!p-address-given-mailbox{$addr => $mailbox} // $NOT-ZERO;
$p *= 1 - $addr-p;
}
@@ -88,13 +90,13 @@ method del-path(IO:D $file, Str:D $mailbox --> Nil) {
}
submethod predict-mailbox-given-addresses(@addresses) {
- my %prediction;
+ my Numeric %prediction;
for $!count-by-mailbox.keys -> Str $mailbox {
- my $p = $!cached-p-given-mailbox{$mailbox};
+ my Numeric $p = $!cached-p-given-mailbox{$mailbox} // $NOT-ZERO;
for @addresses -> Str $addr {
- my $addr-p = $!p-address-given-mailbox{$addr => $mailbox} // 1e-15;
+ my $addr-p = $!p-address-given-mailbox{$addr => $mailbox} // $NOT-ZERO;
$p *= $addr-p / ( 1- $addr-p );
}