-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Closed
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.release-blocker
Milestone
Description
The new hash/maphash package has a Reset method documented as:
Reset discards all bytes added to h. (The seed remains the same.)
Moreover, the Sum64 doc says:
Sum64 returns h's current 64-bit value, which depends on h's seed and the sequence of bytes added to h since the last call to Reset
So it appears it would be reasonable to expect this to print two times the same value:
package main
import (
"fmt"
"hash/maphash"
)
func main() {
h := new(maphash.Hash)
h.WriteString("hello")
fmt.Printf("%#x\n", h.Sum64())
h.Reset()
h.WriteString("hello")
fmt.Printf("%#x\n", h.Sum64())
}
But it doesn't:
$ gotip run hash.go
0xdf1aabcc36e56272
0x5a04b54a5a2174d6
This is because even if the seed remains the same and "all the previously added bytes are discarded", the internal state of the Hash is maintained, even after the h.Reset() call.
Is this the desired behaviour? If it is, the documentation should probably be amended to make it clear what to expect after a call to the Reset method.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.release-blocker