diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 11284e14dab..9dea866967f 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -156,11 +156,6 @@ "ImportPath": "github.com/rs/cors", "Rev": "5e4ce6bc0ecd3472f6f943666d84876691be2ced" }, - { - "ImportPath": "github.com/steakknife/hamming", - "Comment": "0.0.10", - "Rev": "8bad99011016569c05320e51be39c648679c5b73" - }, { "ImportPath": "github.com/syndtr/goleveldb/leveldb", "Rev": "4875955338b0a434238a31165cb87255ab6e9e4a" diff --git a/Godeps/_workspace/src/github.com/steakknife/hamming/MIT-LICENSE.txt b/Godeps/_workspace/src/github.com/steakknife/hamming/MIT-LICENSE.txt deleted file mode 100644 index ccf77fe465c..00000000000 --- a/Godeps/_workspace/src/github.com/steakknife/hamming/MIT-LICENSE.txt +++ /dev/null @@ -1,8 +0,0 @@ -The MIT License (MIT) -Copyright © 2014, 2015 Barry Allard - -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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -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. diff --git a/Godeps/_workspace/src/github.com/steakknife/hamming/README.md b/Godeps/_workspace/src/github.com/steakknife/hamming/README.md deleted file mode 100644 index c7a791a1d8f..00000000000 --- a/Godeps/_workspace/src/github.com/steakknife/hamming/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# hamming distance calculations in Go - -Copyright © 2014, 2015 Barry Allard - -[MIT license](MIT-LICENSE.txt) - -## Usage - -```go -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](https://godoc.org/github.com/steakknife/hamming) - -## Get - - go get -u github.com/steakknife/hamming # master is always stable - -## Source - -- On the web: https://github.com/steakknife/hamming - -- Git: `git clone https://github.com/steakknife/hamming` - -## Contact - -- [Feedback](mailto:barry.allard@gmail.com) - -- [Issues](https://github.com/steakknife/hamming/issues) - -## License - -[MIT license](MIT-LICENSE.txt) - -Copyright © 2014, 2015 Barry Allard diff --git a/Godeps/_workspace/src/github.com/steakknife/hamming/hamming.go b/Godeps/_workspace/src/github.com/steakknife/hamming/hamming.go deleted file mode 100644 index 311fcd9c5dc..00000000000 --- a/Godeps/_workspace/src/github.com/steakknife/hamming/hamming.go +++ /dev/null @@ -1,97 +0,0 @@ -// -// hamming distance calculations in Go -// -// https://github.com/steakknife/hamming -// -// Copyright © 2014, 2015 Barry Allard -// -// MIT license -// -// -// Usage -// -// 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. -// -// 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 -// -package hamming - -// SSE4.x PopCnt is 10x slower -// References: check out Hacker's Delight - -const ( - m1 uint64 = 0x5555555555555555 //binary: 0101... - m2 uint64 = 0x3333333333333333 //binary: 00110011.. - m4 uint64 = 0x0f0f0f0f0f0f0f0f //binary: 4 zeros, 4 ones ... - m8 uint64 = 0x00ff00ff00ff00ff //binary: 8 zeros, 8 ones ... - m16 uint64 = 0x0000ffff0000ffff //binary: 16 zeros, 16 ones ... - m32 uint64 = 0x00000000ffffffff //binary: 32 zeros, 32 ones - hff uint64 = 0xffffffffffffffff //binary: all ones - h01 uint64 = 0x0101010101010101 //the sum of 256 to the power of 0,1,2,3... -) - -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} - -// hamming distance of two uint64's -func Uint64(x, y uint64) int { - return CountBitsUint64(x ^ y) -} - -// 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) -func Uint64s(b0, b1 []uint64) int { - d := 0 - for i, x := range b0 { - d += Uint64(x, b1[i]) - } - return d -} - -// hamming distance of two bytes -func Byte(x, y byte) int { - return CountBitsByte(x ^ y) -} - -// 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) -func Bytes(b0, b1 []byte) int { - d := 0 - for i, x := range b0 { - d += Byte(x, b1[i]) - } - return d -} - -func CountBitsUint64(x uint64) int { - x -= (x >> 1) & m1 // put count of each 2 bits into those 2 bits - x = (x & m2) + ((x >> 2) & m2) // put count of each 4 bits into those 4 bits - x = (x + (x >> 4)) & m4 // put count of each 8 bits into those 8 bits - return int((x * h01) >> 56) // returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ... -} - -func CountBitsUint64s(b []uint64) int { - c := 0 - for _, x := range b { - c += CountBitsUint64(x) - } - return c -} - -func CountBitsByte(x byte) int { - return int(table[x]) -} - -func CountBitsBytes(b []byte) int { - c := 0 - for _, x := range b { - c += CountBitsByte(x) - } - return c -} diff --git a/Godeps/_workspace/src/github.com/steakknife/hamming/hamming_test.go b/Godeps/_workspace/src/github.com/steakknife/hamming/hamming_test.go deleted file mode 100644 index 44723d2d6ed..00000000000 --- a/Godeps/_workspace/src/github.com/steakknife/hamming/hamming_test.go +++ /dev/null @@ -1,143 +0,0 @@ -// -// hamming distance calculations in Go -// -// https://github.com/steakknife/hamming -// -// Copyright © 2014, 2015 Barry Allard -// -// MIT license -// -package hamming - -import ( - "testing" -) - -type testCountBitsUint64Case struct { - x uint64 - n int -} - -type testCountBitsByteCase struct { - x byte - n int -} - -type testBytesCase struct { - b0, b1 []byte - n int -} - -type testUint64sCase struct { - b0, b1 []uint64 - n int -} - -var testCountBitsByteCases = []testCountBitsByteCase{ - {0x00, 0}, - {0x01, 1}, - {0x02, 1}, - {0x03, 2}, - {0xaa, 4}, - {0x55, 4}, - {0x7f, 7}, - {0xff, 8}, -} - -var testCountBitsUint64Cases = []testCountBitsUint64Case{ - {0x00, 0}, - {0x01, 1}, - {0x02, 1}, - {0x03, 2}, - {0xaa, 4}, - {0x55, 4}, - {0x7f, 7}, - {0xff, 8}, - {0xffff, 16}, - {0xffffffff, 32}, - {0x1ffffffff, 33}, - {0x3ffffffff, 34}, - {0x7ffffffff, 35}, - {0xfffffffff, 36}, - {0x3fffffffffffffff, 62}, - {0x7fffffffffffffff, 63}, - {0xffffffffffffffff, 64}, -} - -var testBytesCases = []testBytesCase{ - {[]byte{}, []byte{}, 0}, - {[]byte{1}, []byte{0}, 1}, - {[]byte{1}, []byte{2}, 2}, - {[]byte{1, 0}, []byte{0, 1}, 2}, - {[]byte{1, 0}, []byte{0, 1}, 2}, -} - -var testUint64sCases = []testUint64sCase{ - {[]uint64{}, []uint64{}, 0}, - {[]uint64{1}, []uint64{0}, 1}, - {[]uint64{1}, []uint64{2}, 2}, - {[]uint64{1, 0}, []uint64{0, 1}, 2}, - {[]uint64{1, 0}, []uint64{0, 1}, 2}, -} - -func TestCountBitByte(t *testing.T) { - for _, c := range testCountBitsByteCases { - if actualN := CountBitsByte(c.x); actualN != c.n { - t.Fatal("CountBitsByte(", c.x, ") = ", actualN, " != ", c.n) - } else { - t.Log("CountBitsByte(", c.x, ") == ", c.n) - } - } -} - -func TestBytes(t *testing.T) { - for _, c := range testBytesCases { - if actualN := Bytes(c.b0, c.b1); actualN != c.n { - t.Fatal("Bytes(", c.b0, ",", c.b1, ") = ", actualN, " != ", c.n) - } else { - t.Log("Bytes(", c.b0, ",", c.b1, ") == ", c.n) - } - } -} - -func TestUint64s(t *testing.T) { - for _, c := range testUint64sCases { - if actualN := Uint64s(c.b0, c.b1); actualN != c.n { - t.Fatal("Uint64s(", c.b0, ",", c.b1, ") = ", actualN, " != ", c.n) - } else { - t.Log("Uint64s(", c.b0, ",", c.b1, ") == ", c.n) - } - } -} - -func TestCountBitUint64(t *testing.T) { - for _, c := range testCountBitsUint64Cases { - if actualN := CountBitsUint64(c.x); actualN != c.n { - t.Fatal("CountBitsUint64(", c.x, ") = ", actualN, " != ", c.n) - } else { - t.Log("CountBitsUint64(", c.x, ") == ", c.n) - } - } -} - -func BenchmarkCountBitsUint64(b *testing.B) { - j := 0 - for i := 0; i < b.N; i++ { - CountBitsUint64(testCountBitsUint64Cases[j].x) - j++ - if j == len(testCountBitsUint64Cases) { - j = 0 - } - } -} - -func BenchmarkCountBitsByte(b *testing.B) { - j := 0 - for i := 0; i < b.N; i++ { - CountBitsByte(testCountBitsByteCases[j].x) - j++ - if j == len(testCountBitsByteCases) { - j = 0 - } - } -} diff --git a/blocks/bloom/filter.go b/blocks/bloom/filter.go index 64a2db04286..6b1b7485459 100644 --- a/blocks/bloom/filter.go +++ b/blocks/bloom/filter.go @@ -6,7 +6,7 @@ import ( "errors" // Non crypto hash, because speed "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mtchavez/jenkins" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/steakknife/hamming" + "gx/ipfs/QmeWQMDa5dSdP4n8WDeoY5z8L2EKVqF4ZvK4VEHsLqXsGu/hamming" "hash" ) diff --git a/package.json b/package.json index b7a6d7f1e56..9b123e0df6f 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,12 @@ "hash": "QmcyaFHbyiZfoX5GTpcqqCPYmbjYNAhRDekXSJPFHdYNSV", "name": "go.uuid", "version": "1.0.0" + }, + { + "author": "steakknife", + "hash": "QmeWQMDa5dSdP4n8WDeoY5z8L2EKVqF4ZvK4VEHsLqXsGu", + "name": "hamming", + "version": "0.0.10" } ], "gxVersion": "0.4.0",