spaolacci / murmur3

Native MurmurHash3 Go implementation
BSD 3-Clause "New" or "Revised" License
947 stars 127 forks source link

Hash implementations don't implement hash.Hash interface #5

Closed taywrobel closed 7 years ago

taywrobel commented 9 years ago

The way that the hash functions are implemented - containing the hash.Hash instance, and the constructor, doesn't allow for them to be used in place of standard hash.Hash implementations.

I.e. if a program is designed to have swappable hash implementations, they will commonly take as a parameter of type (hashFunc func() hash.Hash)

However, since the objects return their own types - Hash32, Hash64 or Hash128, the New functions do not have a matching signature, and cannot be easily used in place of the other hash functions.

spaolacci commented 8 years ago

Objects do not return their own types but stdlib's hash.Hash32 and hash.Hash64 (unless you're referring to Hash128 for which there’s no stdlib equivalent).

hash.Hash is a subset of those more specialized hash.Hash32 and hash.Hash64 interfaces.

Producers would indeed process data through hash.Hash, while some endpoints might prefer e.g hash.Hash64.

All stdlib's hash constructors use the same approach (e.g Adler, FNV). Is there any specific usage you’re still having issues with?