Skip to content

runtime: hashmap iterator start position not random enough #8688

@rsc

Description

@rsc
Just got with all.bash at tip:

# GOMAXPROCS=2 runtime -cpu=1,2,4
--- FAIL: TestMapIterOrder-2 (0.00s)
    map_test.go:437: Map with n=9 elements had consistent iteration order: [0 1 2 3 4 5 6 7 8]
FAIL
FAIL    runtime 19.833s

To reproduce:
    go test -run MapIterOrder -cpu=$(perl -e 'print "1,"x300') -v
always fails at least once.

The hash function is picking the same hash bit for all 9 values (1 in 512 chance). Then
instead of having two buckets we'd have one bucket plus an overflow bucket.

Right now the iterator either picks a random bucket or picks a random offset within a
single bucket.
I think it should do both: pick a random bucket and pick a random offset, and start at
that offset (and wrap) in every bucket.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions