Skip to content

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

Closed
@setop

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions