distance

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: BSD-3-Clause Imports: 0 Imported by: 0

README

Distance

GoDoc Build Status

Distance is a Go package with functions to calculate Hamming distance between two byte slices or unsigned integers, population (1 bite) count of byte slices or unsigned integers, and to XOR two byte slices.

Benchmarks

Benchmarks on MacBook Pro 15'' (Mid 2014):

BenchmarkPopCountUint64-8       2000000000           0.32 ns/op        0 B/op          0 allocs/op
BenchmarkPopCount8Bytes-8       200000000            7.06 ns/op        0 B/op          0 allocs/op
BenchmarkXOR8Bytes-8            100000000           11.1 ns/op         0 B/op          0 allocs/op
BenchmarkHamming1Byte-8         200000000            6.83 ns/op        0 B/op          0 allocs/op
BenchmarkHamming8Bytes-8        100000000           10.0 ns/op         0 B/op          0 allocs/op
BenchmarkHamming16Bytes-8       100000000           13.5 ns/op         0 B/op          0 allocs/op
BenchmarkHamming32Bytes-8       100000000           19.9 ns/op         0 B/op          0 allocs/op
BenchmarkHamming33Bytes-8       100000000           19.0 ns/op         0 B/op          0 allocs/op
BenchmarkHamming64Bytes-8       50000000            33.8 ns/op         0 B/op          0 allocs/op
BenchmarkHamming128Bytes-8      20000000            59.7 ns/op         0 B/op          0 allocs/op
BenchmarkHamming1KBytes-8        5000000           395 ns/op           0 B/op          0 allocs/op
BenchmarkHamming10KBytes-8        500000          3724 ns/op           0 B/op          0 allocs/op
BenchmarkHamming1MByte-8            3000        389581 ns/op           0 B/op          0 allocs/op

License

Source files are distributed under the BSD-style license found in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hamming

func Hamming(a, b []byte) (c uint64)

Hamming calculates the Hamming distance between two byte slices. Length of both slices can be arbitrary, but the distance will not be calculated on the remaining part of the longer slice.

func PopCount

func PopCount(buf []byte) (c uint64)

PopCount counts the number of 1 bite in the byte slice.

func PopCountUint16

func PopCountUint16(v uint16) uint16

PopCountUint16 counts the number of 1 bite in uint16 integer.

func PopCountUint32

func PopCountUint32(v uint32) uint32

PopCountUint32 counts the number of 1 bite in uint32 integer.

func PopCountUint64

func PopCountUint64(v uint64) uint64

PopCountUint64 counts the number of 1 bite in uint64 integer.

func PopCountUint8

func PopCountUint8(v uint8) uint8

PopCountUint8 counts the number of 1 bite in uint8 integer.

func XOR

func XOR(a, b []byte) []byte

XOR calculates the difference byte slice between two byte slices. Length of both slices can be arbitrary, but the difference will not be calculated on the remaining part of the longer slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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