Golang hash/fnv.New32, New32a, New64 and New64a functions example

package hash/fnv

New32 returns a new 32-bit FNV-1 hash.Hash.

New32a returns a new 32-bit FNV-1a hash.Hash.

New64 returns a new 64-bit FNV-1 hash.Hash.

New64a returns a new 64-bit FNV-1a hash.Hash.

Golang hash/fnv.New32, New32a, New64 and New64a functions usage example

 package main

 import (
 "fmt"
 "hash/fnv"
 )

 func main() {

 hasher32 := fnv.New32()
 hasher32.Write([]byte("abcd"))
 fmt.Printf("Sum32 : %x\n", hasher32.Sum32())


 hasher32a := fnv.New32a()
 hasher32a.Write([]byte("abcd"))
 fmt.Printf("Sum32a : %x\n", hasher32a.Sum32())


 hasher64 := fnv.New64()
 hasher64.Write([]byte("abcd"))
 fmt.Printf("Sum64 : %x\n", hasher64.Sum64())


 hasher64a := fnv.New64a()
 hasher64a.Write([]byte("abcd"))
 fmt.Printf("Sum64a : %x\n", hasher64a.Sum64())


 }

Output :

Sum32 : b9de7375

Sum32a : ce3479bd

Sum64 : 2ed9327efb844f95

Sum64a : fc179f83ee0724dd

References :

http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vohashfunction

http://golang.org/pkg/hash/fnv/#New32

Advertisement