min (resp. max) calculation wrong if station has no negative (resp. positive) temperature
setop opened this issue · 2 comments
setop commented
Line 6 in fafba32
In this statement, if station has never been encountered,mins[$1]
is initialized to 0. If station has no negative value, min stays at zero, producing wrong result. Same for maxs.
$ wget https://github.com/benhoyt/go-1brc/raw/master/1brc.awk
$ cat << EOF > m.txt
A;1
A;4
A;2
EOF
$ gawk -F\; -f 1brc.awk m.txt
{A=0.0/2.3/4.0} # wrong, min is 1
Any valid solution must test if a station already has an entry or not.
BTW, nice post. I enjoyed reading about optimizing go code using profiling.
benhoyt commented
Yeah, good point. Would you like to propose a PR that does if (counts[$1]) ...
or similar?