This repository has been archived by the owner on Sep 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
slices_of_hamming.go
144 lines (130 loc) · 3.53 KB
/
slices_of_hamming.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// Package hamming distance calculations in Go
//
// https://github.com/steakknife/hamming
//
// Copyright © 2014, 2015, 2016, 2018 Barry Allard
//
// MIT license
//
package hamming
// 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 Int8s(b0, b1 []int8) int {
d := 0
for i, x := range b0 {
d += Int8(x, b1[i])
}
return d
}
// 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 Int16s(b0, b1 []int16) int {
d := 0
for i, x := range b0 {
d += Int16(x, b1[i])
}
return d
}
// 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 Int32s(b0, b1 []int32) int {
d := 0
for i, x := range b0 {
d += Int32(x, b1[i])
}
return d
}
// 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 Int64s(b0, b1 []int64) int {
d := 0
for i, x := range b0 {
d += Int64(x, b1[i])
}
return d
}
// 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 Ints(b0, b1 []int) int {
d := 0
for i, x := range b0 {
d += Int(x, b1[i])
}
return d
}
// 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 Uint8s(b0, b1 []uint8) int {
d := 0
for i, x := range b0 {
d += Uint8(x, b1[i])
}
return d
}
// 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 Uint16s(b0, b1 []uint16) int {
d := 0
for i, x := range b0 {
d += Uint16(x, b1[i])
}
return d
}
// 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 Uint32s(b0, b1 []uint32) int {
d := 0
for i, x := range b0 {
d += Uint32(x, b1[i])
}
return d
}
// 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 Uint64s(b0, b1 []uint64) int {
d := 0
for i, x := range b0 {
d += Uint64(x, b1[i])
}
return d
}
// 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)
func Uints(b0, b1 []uint) int {
d := 0
for i, x := range b0 {
d += Uint(x, b1[i])
}
return d
}
// 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 Bytes(b0, b1 []byte) int {
d := 0
for i, x := range b0 {
d += Byte(x, b1[i])
}
return d
}
// 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 Runes(b0, b1 []rune) int {
d := 0
for i, x := range b0 {
d += Rune(x, b1[i])
}
return d
}
// 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 Strings(b0, b1 string) int {
return Runes(runes(b0), runes(b1))
}
// runize string
func runes(s string) (r []rune) {
for _, ch := range s {
r = append(r, ch)
}
return
}