hamming

package module
v0.0.0-...-c99c656 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2018 License: MIT Imports: 2 Imported by: 27

README

GoDoc Build Status

hamming distance calculations in Go

Copyright © 2014, 2015, 2016, 2018 Barry Allard

MIT license

Performance

$ go test -bench=.
BenchmarkCountBitsInt8PopCnt-4      	300000000	         4.30 ns/op
BenchmarkCountBitsInt16PopCnt-4     	300000000	         3.83 ns/op
BenchmarkCountBitsInt32PopCnt-4     	300000000	         3.64 ns/op
BenchmarkCountBitsInt64PopCnt-4     	500000000	         3.60 ns/op
BenchmarkCountBitsIntPopCnt-4       	300000000	         5.72 ns/op
BenchmarkCountBitsUint8PopCnt-4     	1000000000	         2.98 ns/op
BenchmarkCountBitsUint16PopCnt-4    	500000000	         3.23 ns/op
BenchmarkCountBitsUint32PopCnt-4    	500000000	         3.00 ns/op
BenchmarkCountBitsUint64PopCnt-4    	1000000000	         2.94 ns/op
BenchmarkCountBitsUintPopCnt-4      	300000000	         5.04 ns/op
BenchmarkCountBitsBytePopCnt-4      	300000000	         3.99 ns/op
BenchmarkCountBitsRunePopCnt-4      	300000000	         3.83 ns/op
BenchmarkCountBitsInt8-4            	2000000000	         0.74 ns/op
BenchmarkCountBitsInt16-4           	2000000000	         1.54 ns/op
BenchmarkCountBitsInt32-4           	1000000000	         2.63 ns/op
BenchmarkCountBitsInt64-4           	1000000000	         2.56 ns/op
BenchmarkCountBitsInt-4             	200000000	         7.23 ns/op
BenchmarkCountBitsUint16-4          	2000000000	         1.51 ns/op
BenchmarkCountBitsUint32-4          	500000000	         4.00 ns/op
BenchmarkCountBitsUint64-4          	1000000000	         2.64 ns/op
BenchmarkCountBitsUint64Alt-4       	200000000	         7.60 ns/op
BenchmarkCountBitsUint-4            	300000000	         5.48 ns/op
BenchmarkCountBitsUintReference-4   	100000000	        19.2 ns/op
BenchmarkCountBitsByte-4            	2000000000	         0.75 ns/op
BenchmarkCountBitsByteAlt-4         	1000000000	         2.37 ns/op
BenchmarkCountBitsRune-4            	500000000	         2.85 ns/op
PASS
ok  	_/Users/bmf/Projects/hamming	58.305s
$

Usage

import 'github.com/steakknife/hamming'

// ...

// hamming distance between values
hamming.Byte(0xFF, 0x00) // 8
hamming.Byte(0x00, 0x00) // 0

// just count bits in a byte
hamming.CountBitsByte(0xA5), // 4

See help in the docs

Get

go get -u github.com/steakknife/hamming  # master is always stable

Source

Contact

License

MIT license

Copyright © 2014, 2015, 2016 Barry Allard

Documentation

Overview

Package hamming distance calculations in Go

https://github.com/steakknife/hamming

MIT license

Usage

For functions named CountBits.+s?. The plural forms are for slices. The CountBits.+ forms are Population Count only, where the bare-type forms are Hamming distance (number of bits different) between two values.

Optimized assembly .+PopCnt forms are available on amd64, and operate just like the regular forms (Must check and guard on HasPopCnt() first before trying to call .+PopCnt functions).

import 'github.com/steakknife/hamming'

// ...

// hamming distance between values
hamming.Byte(0xFF, 0x00) // 8
hamming.Byte(0x00, 0x00) // 0

// just count bits in a byte
hamming.CountBitsByte(0xA5), // 4

Got rune? use int32 Got uint8? use byte

Package hamming distance calculations in Go

https://github.com/steakknife/hamming

MIT license

Package hamming distance calculations in Go

https://github.com/steakknife/hamming

MIT license

Package hamming distance calculations in Go

https://github.com/steakknife/hamming

MIT license

Package hamming distance calculations in Go

https://github.com/steakknife/hamming

MIT license

Package hamming distance calculations in Go

https://github.com/steakknife/hamming

MIT license

Package hamming distance calculations in Go

https://github.com/steakknife/hamming

MIT license

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Byte

func Byte(x, y byte) int

Byte hamming distance of two bytes

func Bytes

func Bytes(b0, b1 []byte) int

Bytes hamming distance of two byte buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func CountBitsByte

func CountBitsByte(x byte) int

CountBitsByte count 1's in x

func CountBitsByteAlt

func CountBitsByteAlt(x byte) int

CountBitsByteAlt table-less, branch-free implementation

func CountBitsBytePopCnt

func CountBitsBytePopCnt(x byte) (ret int)

CountBitsBytePopCnt count 1's in x

func CountBitsBytes

func CountBitsBytes(b []byte) int

CountBitsBytes count 1's in b

func CountBitsBytesPopCnt

func CountBitsBytesPopCnt(x []byte) (ret int)

CountBitsBytesPopCnt count 1's in x

func CountBitsInt

func CountBitsInt(x int) int

CountBitsInt count 1's in x

func CountBitsInt16

func CountBitsInt16(x int16) int

CountBitsInt16 count 1's in x

func CountBitsInt16PopCnt

func CountBitsInt16PopCnt(x int16) (ret int)

CountBitsInt16PopCnt count 1's in x

func CountBitsInt16s

func CountBitsInt16s(b []int16) int

CountBitsInt16s count 1's in b

func CountBitsInt16sPopCnt

func CountBitsInt16sPopCnt(x []int16) (ret int)

CountBitsInt16sPopCnt count 1's in x

func CountBitsInt32

func CountBitsInt32(x int32) int

CountBitsInt32 count 1's in x

func CountBitsInt32PopCnt

func CountBitsInt32PopCnt(x int32) (ret int)

CountBitsInt32PopCnt count 1's in x

func CountBitsInt32s

func CountBitsInt32s(b []int32) int

CountBitsInt32s count 1's in b

func CountBitsInt32sPopCnt

func CountBitsInt32sPopCnt(x []int32) (ret int)

CountBitsInt32sPopCnt count 1's in x

func CountBitsInt64

func CountBitsInt64(x int64) int

CountBitsInt64 count 1's in x

func CountBitsInt64PopCnt

func CountBitsInt64PopCnt(x int64) (ret int)

CountBitsInt64PopCnt count 1's in x

func CountBitsInt64s

func CountBitsInt64s(b []int64) int

CountBitsInt64s count 1's in b

func CountBitsInt64sPopCnt

func CountBitsInt64sPopCnt(x []int64) (ret int)

CountBitsInt64sPopCnt count 1's in x

func CountBitsInt8

func CountBitsInt8(x int8) int

CountBitsInt8 count 1's in x

func CountBitsInt8PopCnt

func CountBitsInt8PopCnt(x int8) (ret int)

CountBitsInt8PopCnt count 1's in x

func CountBitsInt8s

func CountBitsInt8s(b []int8) int

CountBitsInt8s count 1's in b

func CountBitsInt8sPopCnt

func CountBitsInt8sPopCnt(x []int8) (ret int)

CountBitsInt8sPopCnt count 1's in x

func CountBitsIntPopCnt

func CountBitsIntPopCnt(x int) int

CountBitsIntPopCnt count 1's in x

func CountBitsInts

func CountBitsInts(b []int) int

CountBitsInts count 1's in b

func CountBitsIntsPopCnt

func CountBitsIntsPopCnt(x []int) int

CountBitsIntsPopCnt count 1's in x

func CountBitsRune

func CountBitsRune(x rune) int

CountBitsRune count 1's in x

func CountBitsRunePopCnt

func CountBitsRunePopCnt(x rune) (ret int)

CountBitsRunePopCnt count 1's in x

func CountBitsRunes

func CountBitsRunes(b []rune) int

CountBitsRunes count 1's in b

func CountBitsRunesPopCnt

func CountBitsRunesPopCnt(x []rune) (ret int)

CountBitsRunesPopCnt count 1's in x

func CountBitsString

func CountBitsString(s string) int

CountBitsString count 1's in s

func CountBitsStringPopCnt

func CountBitsStringPopCnt(s string) (ret int)

CountBitsStringPopCnt count 1's in s

func CountBitsUint

func CountBitsUint(x uint) int

CountBitsUint count 1's in x

func CountBitsUint16

func CountBitsUint16(x uint16) int

CountBitsUint16 count 1's in x

func CountBitsUint16PopCnt

func CountBitsUint16PopCnt(x uint16) (ret int)

CountBitsUint16PopCnt count 1's in x

func CountBitsUint16s

func CountBitsUint16s(b []uint16) int

CountBitsUint16s count 1's in b

func CountBitsUint16sPopCnt

func CountBitsUint16sPopCnt(x []uint16) (ret int)

CountBitsUint16sPopCnt count 1's in x

func CountBitsUint32

func CountBitsUint32(x uint32) int

CountBitsUint32 count 1's in x

func CountBitsUint32PopCnt

func CountBitsUint32PopCnt(x uint32) (ret int)

CountBitsUint32PopCnt count 1's in x

func CountBitsUint32s

func CountBitsUint32s(b []uint32) int

CountBitsUint32s count 1's in b

func CountBitsUint32sPopCnt

func CountBitsUint32sPopCnt(x []uint32) (ret int)

CountBitsUint32sPopCnt count 1's in x

func CountBitsUint64

func CountBitsUint64(x uint64) int

CountBitsUint64 count 1's in x

func CountBitsUint64Alt

func CountBitsUint64Alt(x uint64) int

CountBitsUint64Alt count 1's in x

func CountBitsUint64PopCnt

func CountBitsUint64PopCnt(x uint64) (ret int)

CountBitsUint64PopCnt count 1's in x

func CountBitsUint64s

func CountBitsUint64s(b []uint64) int

CountBitsUint64s count 1's in b

func CountBitsUint64sPopCnt

func CountBitsUint64sPopCnt(x []uint64) (ret int)

CountBitsUint64sPopCnt count 1's in x

func CountBitsUint8

func CountBitsUint8(x uint8) int

CountBitsUint8 count 1's in x

func CountBitsUint8PopCnt

func CountBitsUint8PopCnt(x uint8) (ret int)

CountBitsUint8PopCnt count 1's in x

func CountBitsUint8s

func CountBitsUint8s(b []uint8) int

CountBitsUint8s count 1's in b

func CountBitsUint8sPopCnt

func CountBitsUint8sPopCnt(x []uint8) (ret int)

CountBitsUint8sPopCnt count 1's in x

func CountBitsUintPopCnt

func CountBitsUintPopCnt(x uint) int

CountBitsUintPopCnt count 1's in x

func CountBitsUintReference

func CountBitsUintReference(x uint) int

CountBitsUintReference count 1's in x

func CountBitsUints

func CountBitsUints(b []uint) int

CountBitsUints count 1's in b

func CountBitsUintsPopCnt

func CountBitsUintsPopCnt(x []uint) int

CountBitsUintsPopCnt count 1's in x

func HasPopCnt

func HasPopCnt() (ret bool)

HasPopCnt returns true if *PopCnt functions are callable

func Int

func Int(x, y int) int

Int hamming distance of two ints

func Int16

func Int16(x, y int16) int

Int16 hamming distance of two int16's

func Int16s

func Int16s(b0, b1 []int16) int

Int16s hamming distance of two int16 buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func Int32

func Int32(x, y int32) int

Int32 hamming distance of two int32's

func Int32s

func Int32s(b0, b1 []int32) int

Int32s hamming distance of two int32 buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func Int64

func Int64(x, y int64) int

Int64 hamming distance of two int64's

func Int64s

func Int64s(b0, b1 []int64) int

Int64s hamming distance of two int64 buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func Int8

func Int8(x, y int8) int

Int8 hamming distance of two int8's

func Int8s

func Int8s(b0, b1 []int8) int

Int8s hamming distance of two int8 buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func Ints

func Ints(b0, b1 []int) int

Ints hamming distance of two int buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func Rune

func Rune(x, y rune) int

Rune hamming distance of two runes

func Runes

func Runes(b0, b1 []rune) int

Runes hamming distance of two rune buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func Strings

func Strings(b0, b1 string) int

Strings hamming distance of two strings, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func Uint

func Uint(x, y uint) int

Uint hamming distance of two uint's

func Uint16

func Uint16(x, y uint16) int

Uint16 hamming distance of two uint16's

func Uint16s

func Uint16s(b0, b1 []uint16) int

Uint16s hamming distance of two uint16 buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func Uint32

func Uint32(x, y uint32) int

Uint32 hamming distance of two uint32's

func Uint32s

func Uint32s(b0, b1 []uint32) int

Uint32s hamming distance of two uint32 buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func Uint64

func Uint64(x, y uint64) int

Uint64 hamming distance of two uint64's

func Uint64s

func Uint64s(b0, b1 []uint64) int

Uint64s hamming distance of two uint64 buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func Uint8

func Uint8(x, y uint8) int

Uint8 hamming distance of two uint8's

func Uint8s

func Uint8s(b0, b1 []uint8) int

Uint8s hamming distance of two uint8 buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

func Uints

func Uints(b0, b1 []uint) int

Uints hamming distance of two uint buffers, of which the size of b0 is used for both (panics if b1 < b0, does not compare b1 beyond length of b0)

Types

This section is empty.

Jump to

Keyboard shortcuts

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