dgryski / go-farm

go-farm: a pure-Go farmhash implementation
MIT License
245 stars 22 forks source link

Fingerprint64 on same bytes don't match Google Guava implementation #14

Closed nine9ths closed 5 years ago

nine9ths commented 5 years ago

When passing the same byte arrays to fingerprint64 in java and in go I'm getting different hashes.

This java code results in the hash 0a77beeabd04e23c

import com.google.common.hash.HashCode;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;

public class Fingerprint64Example {

    public static void main(String[] args) {

        byte[] bytes = {102, 111, 111, 102, 105, 108, 101, 110, 97, 109, 101, 61, 0, 116, 104, 101, 47, 102, 105, 108, 101, 44, 0, 59, 0};
        HashFunction hasher = Hashing.farmHashFingerprint64();
        HashCode hashCode = hasher.hashBytes(bytes);
        System.out.println(hashCode);
    }
}

This go code results in the hash 3ce204bdeabe770a

package main

import (
    "fmt"

    farm "github.com/dgryski/go-farm"
)

func main() {
    bytes := []byte{102, 111, 111, 102, 105, 108, 101, 110, 97, 109, 101, 61, 0, 116, 104, 101, 47, 102, 105, 108, 101, 44, 0, 59, 0}
    fmt.Printf("%x", farm.Fingerprint64(bytes))
}

Is this expected? Is there something I've overlooked?

dgryski commented 5 years ago

Guava's HashCode.toString() prints out the value in big-endian order: https://google.github.io/guava/releases/snapshot-jre/api/docs/com/google/common/hash/HashCode.html#toString--

My Go code is printing it little-endian, as does the C++ reference code.