Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

min (resp. max) calculation wrong if station has no negative (resp. positive) temperature #1

Closed
setop opened this issue Mar 5, 2024 · 2 comments · Fixed by #2
Closed

Comments

@setop
Copy link
Contributor

setop commented Mar 5, 2024

mins[$1] = $2 < mins[$1] ? $2 : mins[$1]

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
Copy link
Owner

benhoyt commented Mar 5, 2024

Yeah, good point. Would you like to propose a PR that does if (counts[$1]) ... or similar?

@shadowrun96
Copy link

shadowrun96 commented Jun 12, 2024

Great! why don't you show us your own fix and the benchmark results?
But yeah, I had a passing thought that you need to check against a range and not a single value, but I was too tired by the end of it, and moved on to finish the rest of the AWK book instead :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants