hashx

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package hashx implements allocation-free standard hashing functions

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CRC16

func CRC16(b []byte) (crc uint16)

CRC16 calculates a CRC-16 according to CCITT standards. It returns 0 on empty input.

Example
p := []byte("One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.")
fmt.Println(CRC16(p))
Output:

13678

func CRC16String

func CRC16String(s string) (crc uint16)

CRC16String calculates a CRC-16 from a string according to CCITT standards. It returns 0 on empty input.

Example
s := "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin."
fmt.Println(CRC16String(s))
Output:

13678

func Fnv32a

func Fnv32a(b []byte) uint32

Fnv32a calculates 32-bit FNV-1a hash. It returns 0 on empty input (nil or empty byte slice).

Example
p := []byte("One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.")
fmt.Println(Fnv32a(p))
Output:

1538131534

func Fnv32aString

func Fnv32aString(s string) uint32

Fnv32aString calculates 32-bit FNV-1a hash. It returns 0 on empty input (nil or empty strings).

Example
s := "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin."
fmt.Println(Fnv32aString(s))
Output:

1538131534

func Fnv64a

func Fnv64a(b []byte) uint64

Fnv64a calculates 64-bit FNV-1a hash. It returns 0 on empty input.

Example
p := []byte("One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.")
fmt.Println(Fnv64a(p))
Output:

15849972611371769326

func Fnv64aString

func Fnv64aString(s string) uint64

Fnv64aString calculates 64-bit FNV-1a hash. It returns 0 on empty input.

Example
s := "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin."
fmt.Println(Fnv64aString(s))
Output:

15849972611371769326

func MM128

func MM128(data []byte) (h1, h2 uint64)

MM128 calculates 128-bit murmur3 hash.

Example
p := []byte("One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.")
fmt.Println(MM128(p))
Output:

7376845339986439510 5610010571125513187

func MM128String

func MM128String(data string) (h1, h2 uint64)

MM128String calculates 128-bit murmur3 hash.

Example
s := "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin."
fmt.Println(MM128String(s))
Output:

7376845339986439510 5610010571125513187

func MM32

func MM32(data []byte) (h1 uint32)

MM32 calculates 32-bit murmur3 hash.

Example
p := []byte("One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.")
fmt.Println(MM32(p))
Output:

409351655

func MM32String

func MM32String(data string) (h1 uint32)

MM32String calculates 32-bit murmur3 hash.

Example
s := "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin."
fmt.Println(MM32String(s))
Output:

409351655

func MM64

func MM64(data []byte) uint64

MM64 calculates 64-bit murmur3 hash.

Example
p := []byte("One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.")
fmt.Println(MM64(p))
Output:

7376845339986439510

func MM64String

func MM64String(data string) uint64

MM64String calculates 64-bit murmur3 hash.

Example
s := "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin."
fmt.Println(MM64String(s))
Output:

7376845339986439510

func XX32

func XX32(input []byte, seed uint32) uint32

XX32 returns the 32bit xxHash value.

Example
p := []byte("One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.")
fmt.Println(XX32(p, 0))
Output:

119031159

func XX32String added in v0.9.1

func XX32String(input string, seed uint32) uint32

XX32String returns the 32bit xxHash value.

Example
s := "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin."
fmt.Println(XX32String(s, 0))
Output:

119031159

func XX64

func XX64(data []byte, seed uint64) uint64

XX64 returns the 64bit xxHash value.

Example
p := []byte("One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.")
fmt.Println(XX64(p, 0))
Output:

2399806787706828701

func XX64String added in v0.9.1

func XX64String(data string, seed uint64) uint64

XX64String returns the 64bit xxHash value.

Example
s := "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin."
fmt.Println(XX64String(s, 0))
Output:

2399806787706828701

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL