@cryptotaxi247 / kubo / commits / e86bf92f3

Migrate hamming to gx from Godeps

License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

Jakub Sztandera committed May 18, 2016 at 21:59 UTC e86bf92f317d6c55ea7447c7bf1a7a282914f040
7 files changed +7 -298
Godeps/Godeps.json
-5
@@ -156,11 +156,6 @@
156 "ImportPath": "github.com/rs/cors",
157 "Rev": "5e4ce6bc0ecd3472f6f943666d84876691be2ced"
158 },
159 - {
160 - "ImportPath": "github.com/steakknife/hamming",
161 - "Comment": "0.0.10",
162 - "Rev": "8bad99011016569c05320e51be39c648679c5b73"
163 - },
159 {
160 "ImportPath": "github.com/syndtr/goleveldb/leveldb",
161 "Rev": "4875955338b0a434238a31165cb87255ab6e9e4a"
Godeps/_workspace/src/github.com/steakknife/hamming/MIT-LICENSE.txt deleted
-8
@@ -1,8 +0,0 @@
1 -The MIT License (MIT)
2 -Copyright © 2014, 2015 Barry Allard
3 -
4 -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 -
6 -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 -
8 -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Godeps/_workspace/src/github.com/steakknife/hamming/README.md deleted
-44
@@ -1,44 +0,0 @@
1 -# hamming distance calculations in Go
2 -
3 -Copyright © 2014, 2015 Barry Allard
4 -
5 -[MIT license](MIT-LICENSE.txt)
6 -
7 -## Usage
8 -
9 -```go
10 -import 'github.com/steakknife/hamming'
11 -
12 -// ...
13 -
14 -// hamming distance between values
15 -hamming.Byte(0xFF, 0x00) // 8
16 -hamming.Byte(0x00, 0x00) // 0
17 -
18 -// just count bits in a byte
19 -hamming.CountBitsByte(0xA5), // 4
20 -```
21 -
22 -See help in the [docs](https://godoc.org/github.com/steakknife/hamming)
23 -
24 -## Get
25 -
26 - go get -u github.com/steakknife/hamming # master is always stable
27 -
28 -## Source
29 -
30 -- On the web: https://github.com/steakknife/hamming
31 -
32 -- Git: `git clone https://github.com/steakknife/hamming`
33 -
34 -## Contact
35 -
36 -- [Feedback](mailto:barry.allard@gmail.com)
37 -
38 -- [Issues](https://github.com/steakknife/hamming/issues)
39 -
40 -## License
41 -
42 -[MIT license](MIT-LICENSE.txt)
43 -
44 -Copyright © 2014, 2015 Barry Allard
Godeps/_workspace/src/github.com/steakknife/hamming/hamming.go deleted
-97
@@ -1,97 +0,0 @@
1 -//
2 -// hamming distance calculations in Go
3 -//
4 -// https://github.com/steakknife/hamming
5 -//
6 -// Copyright © 2014, 2015 Barry Allard
7 -//
8 -// MIT license
9 -//
10 -//
11 -// Usage
12 -//
13 -// The functions are named (CountBits)?(Byte|Uint64)s?. The plural forms are for slices. The CountBits.+ forms are Population Count only, where the bare-type forms are Hamming distance.
14 -//
15 -// import 'github.com/steakknife/hamming'
16 -//
17 -// // ...
18 -//
19 -// // hamming distance between values
20 -// hamming.Byte(0xFF, 0x00) // 8
21 -// hamming.Byte(0x00, 0x00) // 0
22 -//
23 -// // just count bits in a byte
24 -// hamming.CountBitsByte(0xA5), // 4
25 -//
26 -package hamming
27 -
28 -// SSE4.x PopCnt is 10x slower
29 -// References: check out Hacker's Delight
30 -
31 -const (
32 - m1 uint64 = 0x5555555555555555 //binary: 0101...
33 - m2 uint64 = 0x3333333333333333 //binary: 00110011..
34 - m4 uint64 = 0x0f0f0f0f0f0f0f0f //binary: 4 zeros, 4 ones ...
35 - m8 uint64 = 0x00ff00ff00ff00ff //binary: 8 zeros, 8 ones ...
36 - m16 uint64 = 0x0000ffff0000ffff //binary: 16 zeros, 16 ones ...
37 - m32 uint64 = 0x00000000ffffffff //binary: 32 zeros, 32 ones
38 - hff uint64 = 0xffffffffffffffff //binary: all ones
39 - h01 uint64 = 0x0101010101010101 //the sum of 256 to the power of 0,1,2,3...
40 -)
41 -
42 -var table = [256]byte{0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8}
43 -
44 -// hamming distance of two uint64's
45 -func Uint64(x, y uint64) int {
46 - return CountBitsUint64(x ^ y)
47 -}
48 -
49 -// hamming distance of two uint64 buffers, of which the size of the first argument is used for both (panics if b1 is smaller than b0, does not compare b1 beyond length of b0)
50 -func Uint64s(b0, b1 []uint64) int {
51 - d := 0
52 - for i, x := range b0 {
53 - d += Uint64(x, b1[i])
54 - }
55 - return d
56 -}
57 -
58 -// hamming distance of two bytes
59 -func Byte(x, y byte) int {
60 - return CountBitsByte(x ^ y)
61 -}
62 -
63 -// hamming distance of two byte buffers, of which the size of the first argument is used for both (panics if b1 is smaller than b0, does not compare b1 beyond length of b0)
64 -func Bytes(b0, b1 []byte) int {
65 - d := 0
66 - for i, x := range b0 {
67 - d += Byte(x, b1[i])
68 - }
69 - return d
70 -}
71 -
72 -func CountBitsUint64(x uint64) int {
73 - x -= (x >> 1) & m1 // put count of each 2 bits into those 2 bits
74 - x = (x & m2) + ((x >> 2) & m2) // put count of each 4 bits into those 4 bits
75 - x = (x + (x >> 4)) & m4 // put count of each 8 bits into those 8 bits
76 - return int((x * h01) >> 56) // returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
77 -}
78 -
79 -func CountBitsUint64s(b []uint64) int {
80 - c := 0
81 - for _, x := range b {
82 - c += CountBitsUint64(x)
83 - }
84 - return c
85 -}
86 -
87 -func CountBitsByte(x byte) int {
88 - return int(table[x])
89 -}
90 -
91 -func CountBitsBytes(b []byte) int {
92 - c := 0
93 - for _, x := range b {
94 - c += CountBitsByte(x)
95 - }
96 - return c
97 -}
Godeps/_workspace/src/github.com/steakknife/hamming/hamming_test.go deleted
-143
@@ -1,143 +0,0 @@
1 -//
2 -// hamming distance calculations in Go
3 -//
4 -// https://github.com/steakknife/hamming
5 -//
6 -// Copyright © 2014, 2015 Barry Allard
7 -//
8 -// MIT license
9 -//
10 -package hamming
11 -
12 -import (
13 - "testing"
14 -)
15 -
16 -type testCountBitsUint64Case struct {
17 - x uint64
18 - n int
19 -}
20 -
21 -type testCountBitsByteCase struct {
22 - x byte
23 - n int
24 -}
25 -
26 -type testBytesCase struct {
27 - b0, b1 []byte
28 - n int
29 -}
30 -
31 -type testUint64sCase struct {
32 - b0, b1 []uint64
33 - n int
34 -}
35 -
36 -var testCountBitsByteCases = []testCountBitsByteCase{
37 - {0x00, 0},
38 - {0x01, 1},
39 - {0x02, 1},
40 - {0x03, 2},
41 - {0xaa, 4},
42 - {0x55, 4},
43 - {0x7f, 7},
44 - {0xff, 8},
45 -}
46 -
47 -var testCountBitsUint64Cases = []testCountBitsUint64Case{
48 - {0x00, 0},
49 - {0x01, 1},
50 - {0x02, 1},
51 - {0x03, 2},
52 - {0xaa, 4},
53 - {0x55, 4},
54 - {0x7f, 7},
55 - {0xff, 8},
56 - {0xffff, 16},
57 - {0xffffffff, 32},
58 - {0x1ffffffff, 33},
59 - {0x3ffffffff, 34},
60 - {0x7ffffffff, 35},
61 - {0xfffffffff, 36},
62 - {0x3fffffffffffffff, 62},
63 - {0x7fffffffffffffff, 63},
64 - {0xffffffffffffffff, 64},
65 -}
66 -
67 -var testBytesCases = []testBytesCase{
68 - {[]byte{}, []byte{}, 0},
69 - {[]byte{1}, []byte{0}, 1},
70 - {[]byte{1}, []byte{2}, 2},
71 - {[]byte{1, 0}, []byte{0, 1}, 2},
72 - {[]byte{1, 0}, []byte{0, 1}, 2},
73 -}
74 -
75 -var testUint64sCases = []testUint64sCase{
76 - {[]uint64{}, []uint64{}, 0},
77 - {[]uint64{1}, []uint64{0}, 1},
78 - {[]uint64{1}, []uint64{2}, 2},
79 - {[]uint64{1, 0}, []uint64{0, 1}, 2},
80 - {[]uint64{1, 0}, []uint64{0, 1}, 2},
81 -}
82 -
83 -func TestCountBitByte(t *testing.T) {
84 - for _, c := range testCountBitsByteCases {
85 - if actualN := CountBitsByte(c.x); actualN != c.n {
86 - t.Fatal("CountBitsByte(", c.x, ") = ", actualN, " != ", c.n)
87 - } else {
88 - t.Log("CountBitsByte(", c.x, ") == ", c.n)
89 - }
90 - }
91 -}
92 -
93 -func TestBytes(t *testing.T) {
94 - for _, c := range testBytesCases {
95 - if actualN := Bytes(c.b0, c.b1); actualN != c.n {
96 - t.Fatal("Bytes(", c.b0, ",", c.b1, ") = ", actualN, " != ", c.n)
97 - } else {
98 - t.Log("Bytes(", c.b0, ",", c.b1, ") == ", c.n)
99 - }
100 - }
101 -}
102 -
103 -func TestUint64s(t *testing.T) {
104 - for _, c := range testUint64sCases {
105 - if actualN := Uint64s(c.b0, c.b1); actualN != c.n {
106 - t.Fatal("Uint64s(", c.b0, ",", c.b1, ") = ", actualN, " != ", c.n)
107 - } else {
108 - t.Log("Uint64s(", c.b0, ",", c.b1, ") == ", c.n)
109 - }
110 - }
111 -}
112 -
113 -func TestCountBitUint64(t *testing.T) {
114 - for _, c := range testCountBitsUint64Cases {
115 - if actualN := CountBitsUint64(c.x); actualN != c.n {
116 - t.Fatal("CountBitsUint64(", c.x, ") = ", actualN, " != ", c.n)
117 - } else {
118 - t.Log("CountBitsUint64(", c.x, ") == ", c.n)
119 - }
120 - }
121 -}
122 -
123 -func BenchmarkCountBitsUint64(b *testing.B) {
124 - j := 0
125 - for i := 0; i < b.N; i++ {
126 - CountBitsUint64(testCountBitsUint64Cases[j].x)
127 - j++
128 - if j == len(testCountBitsUint64Cases) {
129 - j = 0
130 - }
131 - }
132 -}
133 -
134 -func BenchmarkCountBitsByte(b *testing.B) {
135 - j := 0
136 - for i := 0; i < b.N; i++ {
137 - CountBitsByte(testCountBitsByteCases[j].x)
138 - j++
139 - if j == len(testCountBitsByteCases) {
140 - j = 0
141 - }
142 - }
143 -}
blocks/bloom/filter.go
+1 -1
@@ -6,7 +6,7 @@ import (
6 "errors"
7 // Non crypto hash, because speed
8 "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mtchavez/jenkins"
9 - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/steakknife/hamming"
9 + "gx/ipfs/QmeWQMDa5dSdP4n8WDeoY5z8L2EKVqF4ZvK4VEHsLqXsGu/hamming"
10 "hash"
11 )
12
package.json
+6
@@ -75,6 +75,12 @@
75 "hash": "QmcyaFHbyiZfoX5GTpcqqCPYmbjYNAhRDekXSJPFHdYNSV",
76 "name": "go.uuid",
77 "version": "1.0.0"
78 + },
79 + {
80 + "author": "steakknife",
81 + "hash": "QmeWQMDa5dSdP4n8WDeoY5z8L2EKVqF4ZvK4VEHsLqXsGu",
82 + "name": "hamming",
83 + "version": "0.0.10"
84 }
85 ],
86 "gxVersion": "0.4.0",