diff --git a/debug/gdebug/gdebug_version.go b/debug/gdebug/gdebug_version.go index 54c11215d..5c883f68d 100644 --- a/debug/gdebug/gdebug_version.go +++ b/debug/gdebug/gdebug_version.go @@ -24,7 +24,7 @@ func BinVersion() string { if binaryVersion == "" { binaryContent, _ := ioutil.ReadFile(selfPath) binaryVersion = strconv.FormatInt( - int64(ghash.BKDRHash(binaryContent)), + int64(ghash.BKDR(binaryContent)), 36, ) } diff --git a/encoding/ghash/ghash.go b/encoding/ghash/ghash.go index 10650fc29..de7d1573d 100644 --- a/encoding/ghash/ghash.go +++ b/encoding/ghash/ghash.go @@ -6,205 +6,3 @@ // Package ghash provides some classic hash functions(uint32/uint64) in go. package ghash - -// BKDRHash implements the classic BKDR hash algorithm for 32 bits. -func BKDRHash(str []byte) uint32 { - var ( - seed uint32 = 131 // 31 131 1313 13131 131313 etc.. - hash uint32 = 0 - ) - for i := 0; i < len(str); i++ { - hash = hash*seed + uint32(str[i]) - } - return hash -} - -// BKDRHash64 implements the classic BKDR hash algorithm for 64 bits. -func BKDRHash64(str []byte) uint64 { - var ( - seed uint64 = 131 // 31 131 1313 13131 131313 etc.. - hash uint64 = 0 - ) - for i := 0; i < len(str); i++ { - hash = hash*seed + uint64(str[i]) - } - return hash -} - -// SDBMHash implements the classic SDBM hash algorithm for 32 bits. -func SDBMHash(str []byte) uint32 { - var hash uint32 = 0 - for i := 0; i < len(str); i++ { - // equivalent to: hash = 65599*hash + uint32(str[i]); - hash = uint32(str[i]) + (hash << 6) + (hash << 16) - hash - } - return hash -} - -// SDBMHash64 implements the classic SDBM hash algorithm for 64 bits. -func SDBMHash64(str []byte) uint64 { - var hash uint64 = 0 - for i := 0; i < len(str); i++ { - // equivalent to: hash = 65599*hash + uint32(str[i]) - hash = uint64(str[i]) + (hash << 6) + (hash << 16) - hash - } - return hash -} - -// RSHash implements the classic RS hash algorithm for 32 bits. -func RSHash(str []byte) uint32 { - var ( - b uint32 = 378551 - a uint32 = 63689 - hash uint32 = 0 - ) - for i := 0; i < len(str); i++ { - hash = hash*a + uint32(str[i]) - a *= b - } - return hash -} - -// RSHash64 implements the classic RS hash algorithm for 64 bits. -func RSHash64(str []byte) uint64 { - var ( - b uint64 = 378551 - a uint64 = 63689 - hash uint64 = 0 - ) - for i := 0; i < len(str); i++ { - hash = hash*a + uint64(str[i]) - a *= b - } - return hash -} - -// JSHash implements the classic JS hash algorithm for 32 bits. -func JSHash(str []byte) uint32 { - var hash uint32 = 1315423911 - for i := 0; i < len(str); i++ { - hash ^= (hash << 5) + uint32(str[i]) + (hash >> 2) - } - return hash -} - -// JSHash64 implements the classic JS hash algorithm for 64 bits. -func JSHash64(str []byte) uint64 { - var hash uint64 = 1315423911 - for i := 0; i < len(str); i++ { - hash ^= (hash << 5) + uint64(str[i]) + (hash >> 2) - } - return hash -} - -// PJWHash implements the classic PJW hash algorithm for 32 bits. -func PJWHash(str []byte) uint32 { - var ( - BitsInUnsignedInt uint32 = 4 * 8 - ThreeQuarters uint32 = (BitsInUnsignedInt * 3) / 4 - OneEighth uint32 = BitsInUnsignedInt / 8 - HighBits uint32 = (0xFFFFFFFF) << (BitsInUnsignedInt - OneEighth) - hash uint32 = 0 - test uint32 = 0 - ) - for i := 0; i < len(str); i++ { - hash = (hash << OneEighth) + uint32(str[i]) - if test = hash & HighBits; test != 0 { - hash = (hash ^ (test >> ThreeQuarters)) & (^HighBits + 1) - } - } - return hash -} - -// PJWHash64 implements the classic PJW hash algorithm for 64 bits. -func PJWHash64(str []byte) uint64 { - var ( - BitsInUnsignedInt uint64 = 4 * 8 - ThreeQuarters uint64 = (BitsInUnsignedInt * 3) / 4 - OneEighth uint64 = BitsInUnsignedInt / 8 - HighBits uint64 = (0xFFFFFFFFFFFFFFFF) << (BitsInUnsignedInt - OneEighth) - hash uint64 = 0 - test uint64 = 0 - ) - for i := 0; i < len(str); i++ { - hash = (hash << OneEighth) + uint64(str[i]) - if test = hash & HighBits; test != 0 { - hash = (hash ^ (test >> ThreeQuarters)) & (^HighBits + 1) - } - } - return hash -} - -// ELFHash implements the classic ELF hash algorithm for 32 bits. -func ELFHash(str []byte) uint32 { - var hash uint32 = 0 - var x uint32 = 0 - for i := 0; i < len(str); i++ { - hash = (hash << 4) + uint32(str[i]) - if x = hash & 0xF0000000; x != 0 { - hash ^= x >> 24 - hash &= ^x + 1 - } - } - return hash -} - -// ELFHash64 implements the classic ELF hash algorithm for 64 bits. -func ELFHash64(str []byte) uint64 { - var ( - hash uint64 = 0 - x uint64 = 0 - ) - for i := 0; i < len(str); i++ { - hash = (hash << 4) + uint64(str[i]) - if x = hash & 0xF000000000000000; x != 0 { - hash ^= x >> 24 - hash &= ^x + 1 - } - } - return hash -} - -// DJBHash implements the classic DJB hash algorithm for 32 bits. -func DJBHash(str []byte) uint32 { - var hash uint32 = 5381 - for i := 0; i < len(str); i++ { - hash += (hash << 5) + uint32(str[i]) - } - return hash -} - -// DJBHash64 implements the classic DJB hash algorithm for 64 bits. -func DJBHash64(str []byte) uint64 { - var hash uint64 = 5381 - for i := 0; i < len(str); i++ { - hash += (hash << 5) + uint64(str[i]) - } - return hash -} - -// APHash implements the classic AP hash algorithm for 32 bits. -func APHash(str []byte) uint32 { - var hash uint32 = 0 - for i := 0; i < len(str); i++ { - if (i & 1) == 0 { - hash ^= (hash << 7) ^ uint32(str[i]) ^ (hash >> 3) - } else { - hash ^= ^((hash << 11) ^ uint32(str[i]) ^ (hash >> 5)) + 1 - } - } - return hash -} - -// APHash64 implements the classic AP hash algorithm for 64 bits. -func APHash64(str []byte) uint64 { - var hash uint64 = 0 - for i := 0; i < len(str); i++ { - if (i & 1) == 0 { - hash ^= (hash << 7) ^ uint64(str[i]) ^ (hash >> 3) - } else { - hash ^= ^((hash << 11) ^ uint64(str[i]) ^ (hash >> 5)) + 1 - } - } - return hash -} diff --git a/encoding/ghash/ghash_ap.go b/encoding/ghash/ghash_ap.go new file mode 100644 index 000000000..099fd2b3a --- /dev/null +++ b/encoding/ghash/ghash_ap.go @@ -0,0 +1,33 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package ghash + +// AP implements the classic AP hash algorithm for 32 bits. +func AP(str []byte) uint32 { + var hash uint32 = 0 + for i := 0; i < len(str); i++ { + if (i & 1) == 0 { + hash ^= (hash << 7) ^ uint32(str[i]) ^ (hash >> 3) + } else { + hash ^= ^((hash << 11) ^ uint32(str[i]) ^ (hash >> 5)) + 1 + } + } + return hash +} + +// AP64 implements the classic AP hash algorithm for 64 bits. +func AP64(str []byte) uint64 { + var hash uint64 = 0 + for i := 0; i < len(str); i++ { + if (i & 1) == 0 { + hash ^= (hash << 7) ^ uint64(str[i]) ^ (hash >> 3) + } else { + hash ^= ^((hash << 11) ^ uint64(str[i]) ^ (hash >> 5)) + 1 + } + } + return hash +} diff --git a/encoding/ghash/ghash_bkdr.go b/encoding/ghash/ghash_bkdr.go new file mode 100644 index 000000000..2f4cc9694 --- /dev/null +++ b/encoding/ghash/ghash_bkdr.go @@ -0,0 +1,31 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package ghash + +// BKDR implements the classic BKDR hash algorithm for 32 bits. +func BKDR(str []byte) uint32 { + var ( + seed uint32 = 131 // 31 131 1313 13131 131313 etc.. + hash uint32 = 0 + ) + for i := 0; i < len(str); i++ { + hash = hash*seed + uint32(str[i]) + } + return hash +} + +// BKDR64 implements the classic BKDR hash algorithm for 64 bits. +func BKDR64(str []byte) uint64 { + var ( + seed uint64 = 131 // 31 131 1313 13131 131313 etc.. + hash uint64 = 0 + ) + for i := 0; i < len(str); i++ { + hash = hash*seed + uint64(str[i]) + } + return hash +} diff --git a/encoding/ghash/ghash_djb.go b/encoding/ghash/ghash_djb.go new file mode 100644 index 000000000..da5f06464 --- /dev/null +++ b/encoding/ghash/ghash_djb.go @@ -0,0 +1,25 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package ghash + +// DJB implements the classic DJB hash algorithm for 32 bits. +func DJB(str []byte) uint32 { + var hash uint32 = 5381 + for i := 0; i < len(str); i++ { + hash += (hash << 5) + uint32(str[i]) + } + return hash +} + +// DJB64 implements the classic DJB hash algorithm for 64 bits. +func DJB64(str []byte) uint64 { + var hash uint64 = 5381 + for i := 0; i < len(str); i++ { + hash += (hash << 5) + uint64(str[i]) + } + return hash +} diff --git a/encoding/ghash/ghash_elf.go b/encoding/ghash/ghash_elf.go new file mode 100644 index 000000000..d46713a91 --- /dev/null +++ b/encoding/ghash/ghash_elf.go @@ -0,0 +1,37 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package ghash + +// ELF implements the classic ELF hash algorithm for 32 bits. +func ELF(str []byte) uint32 { + var hash uint32 = 0 + var x uint32 = 0 + for i := 0; i < len(str); i++ { + hash = (hash << 4) + uint32(str[i]) + if x = hash & 0xF0000000; x != 0 { + hash ^= x >> 24 + hash &= ^x + 1 + } + } + return hash +} + +// ELF64 implements the classic ELF hash algorithm for 64 bits. +func ELF64(str []byte) uint64 { + var ( + hash uint64 = 0 + x uint64 = 0 + ) + for i := 0; i < len(str); i++ { + hash = (hash << 4) + uint64(str[i]) + if x = hash & 0xF000000000000000; x != 0 { + hash ^= x >> 24 + hash &= ^x + 1 + } + } + return hash +} diff --git a/encoding/ghash/ghash_jshash.go b/encoding/ghash/ghash_jshash.go new file mode 100644 index 000000000..91220c712 --- /dev/null +++ b/encoding/ghash/ghash_jshash.go @@ -0,0 +1,25 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package ghash + +// JS implements the classic JS hash algorithm for 32 bits. +func JS(str []byte) uint32 { + var hash uint32 = 1315423911 + for i := 0; i < len(str); i++ { + hash ^= (hash << 5) + uint32(str[i]) + (hash >> 2) + } + return hash +} + +// JS64 implements the classic JS hash algorithm for 64 bits. +func JS64(str []byte) uint64 { + var hash uint64 = 1315423911 + for i := 0; i < len(str); i++ { + hash ^= (hash << 5) + uint64(str[i]) + (hash >> 2) + } + return hash +} diff --git a/encoding/ghash/ghash_pjw.go b/encoding/ghash/ghash_pjw.go new file mode 100644 index 000000000..39d2813e4 --- /dev/null +++ b/encoding/ghash/ghash_pjw.go @@ -0,0 +1,45 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package ghash + +// PJW implements the classic PJW hash algorithm for 32 bits. +func PJW(str []byte) uint32 { + var ( + BitsInUnsignedInt uint32 = 4 * 8 + ThreeQuarters uint32 = (BitsInUnsignedInt * 3) / 4 + OneEighth uint32 = BitsInUnsignedInt / 8 + HighBits uint32 = (0xFFFFFFFF) << (BitsInUnsignedInt - OneEighth) + hash uint32 = 0 + test uint32 = 0 + ) + for i := 0; i < len(str); i++ { + hash = (hash << OneEighth) + uint32(str[i]) + if test = hash & HighBits; test != 0 { + hash = (hash ^ (test >> ThreeQuarters)) & (^HighBits + 1) + } + } + return hash +} + +// PJW64 implements the classic PJW hash algorithm for 64 bits. +func PJW64(str []byte) uint64 { + var ( + BitsInUnsignedInt uint64 = 4 * 8 + ThreeQuarters uint64 = (BitsInUnsignedInt * 3) / 4 + OneEighth uint64 = BitsInUnsignedInt / 8 + HighBits uint64 = (0xFFFFFFFFFFFFFFFF) << (BitsInUnsignedInt - OneEighth) + hash uint64 = 0 + test uint64 = 0 + ) + for i := 0; i < len(str); i++ { + hash = (hash << OneEighth) + uint64(str[i]) + if test = hash & HighBits; test != 0 { + hash = (hash ^ (test >> ThreeQuarters)) & (^HighBits + 1) + } + } + return hash +} diff --git a/encoding/ghash/ghash_rs.go b/encoding/ghash/ghash_rs.go new file mode 100644 index 000000000..e9e955636 --- /dev/null +++ b/encoding/ghash/ghash_rs.go @@ -0,0 +1,35 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package ghash + +// RS implements the classic RS hash algorithm for 32 bits. +func RS(str []byte) uint32 { + var ( + b uint32 = 378551 + a uint32 = 63689 + hash uint32 = 0 + ) + for i := 0; i < len(str); i++ { + hash = hash*a + uint32(str[i]) + a *= b + } + return hash +} + +// RS64 implements the classic RS hash algorithm for 64 bits. +func RS64(str []byte) uint64 { + var ( + b uint64 = 378551 + a uint64 = 63689 + hash uint64 = 0 + ) + for i := 0; i < len(str); i++ { + hash = hash*a + uint64(str[i]) + a *= b + } + return hash +} diff --git a/encoding/ghash/ghash_sdbm.go b/encoding/ghash/ghash_sdbm.go new file mode 100644 index 000000000..0f2fa6bf9 --- /dev/null +++ b/encoding/ghash/ghash_sdbm.go @@ -0,0 +1,27 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package ghash + +// SDBM implements the classic SDBM hash algorithm for 32 bits. +func SDBM(str []byte) uint32 { + var hash uint32 = 0 + for i := 0; i < len(str); i++ { + // equivalent to: hash = 65599*hash + uint32(str[i]); + hash = uint32(str[i]) + (hash << 6) + (hash << 16) - hash + } + return hash +} + +// SDBM64 implements the classic SDBM hash algorithm for 64 bits. +func SDBM64(str []byte) uint64 { + var hash uint64 = 0 + for i := 0; i < len(str); i++ { + // equivalent to: hash = 65599*hash + uint32(str[i]) + hash = uint64(str[i]) + (hash << 6) + (hash << 16) - hash + } + return hash +} diff --git a/encoding/ghash/ghash_z_bench_test.go b/encoding/ghash/ghash_z_bench_test.go index ee8dd8d68..c3dd424de 100644 --- a/encoding/ghash/ghash_z_bench_test.go +++ b/encoding/ghash/ghash_z_bench_test.go @@ -18,98 +18,98 @@ var ( str = []byte("This is the test string for hash.") ) -func BenchmarkBKDRHash(b *testing.B) { +func Benchmark_BKDR(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.BKDRHash(str) + ghash.BKDR(str) } } -func BenchmarkBKDRHash64(b *testing.B) { +func Benchmark_BKDR64(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.BKDRHash64(str) + ghash.BKDR64(str) } } -func BenchmarkSDBMHash(b *testing.B) { +func Benchmark_SDBM(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.SDBMHash(str) + ghash.SDBM(str) } } -func BenchmarkSDBMHash64(b *testing.B) { +func Benchmark_SDBM64(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.SDBMHash64(str) + ghash.SDBM64(str) } } -func BenchmarkRSHash(b *testing.B) { +func Benchmark_RS(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.RSHash(str) + ghash.RS(str) } } -func BenchmarkSRSHash64(b *testing.B) { +func Benchmark_SRS64(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.RSHash64(str) + ghash.RS64(str) } } -func BenchmarkJSHash(b *testing.B) { +func Benchmark_JS(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.JSHash(str) + ghash.JS(str) } } -func BenchmarkJSHash64(b *testing.B) { +func Benchmark_JS64(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.JSHash64(str) + ghash.JS64(str) } } -func BenchmarkPJWHash(b *testing.B) { +func Benchmark_PJW(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.PJWHash(str) + ghash.PJW(str) } } -func BenchmarkPJWHash64(b *testing.B) { +func Benchmark_PJW64(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.PJWHash64(str) + ghash.PJW64(str) } } -func BenchmarkELFHash(b *testing.B) { +func Benchmark_ELF(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.ELFHash(str) + ghash.ELF(str) } } -func BenchmarkELFHash64(b *testing.B) { +func Benchmark_ELF64(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.ELFHash64(str) + ghash.ELF64(str) } } -func BenchmarkDJBHash(b *testing.B) { +func Benchmark_DJB(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.DJBHash(str) + ghash.DJB(str) } } -func BenchmarkDJBHash64(b *testing.B) { +func Benchmark_DJB64(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.DJBHash64(str) + ghash.DJB64(str) } } -func BenchmarkAPHash(b *testing.B) { +func Benchmark_AP(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.APHash(str) + ghash.AP(str) } } -func BenchmarkAPHash64(b *testing.B) { +func Benchmark_AP64(b *testing.B) { for i := 0; i < b.N; i++ { - ghash.APHash64(str) + ghash.AP64(str) } } diff --git a/encoding/ghash/ghash_z_unit_test.go b/encoding/ghash/ghash_z_unit_test.go index 3da11ffcc..dce018914 100755 --- a/encoding/ghash/ghash_z_unit_test.go +++ b/encoding/ghash/ghash_z_unit_test.go @@ -17,130 +17,106 @@ var ( strBasic = []byte("This is the test string for hash.") ) -func Test_BKDRHash(t *testing.T) { - var x uint32 = 200645773 +func Test_BKDR(t *testing.T) { gtest.C(t, func(t *gtest.T) { - j := ghash.BKDRHash(strBasic) + x := uint32(200645773) + j := ghash.BKDR(strBasic) + t.Assert(j, x) + }) + gtest.C(t, func(t *gtest.T) { + x := 4214762819217104013 + j := ghash.BKDR64(strBasic) t.Assert(j, x) }) } -func Test_BKDRHash64(t *testing.T) { - var x uint64 = 4214762819217104013 +func Test_SDBM(t *testing.T) { gtest.C(t, func(t *gtest.T) { - j := ghash.BKDRHash64(strBasic) + x := uint32(1069170245) + j := ghash.SDBM(strBasic) + t.Assert(j, x) + }) + gtest.C(t, func(t *gtest.T) { + x := uint64(9881052176572890693) + j := ghash.SDBM64(strBasic) t.Assert(j, x) }) } -func Test_SDBMHash(t *testing.T) { - var x uint32 = 1069170245 +func Test_RS(t *testing.T) { gtest.C(t, func(t *gtest.T) { - j := ghash.SDBMHash(strBasic) + x := uint32(1944033799) + j := ghash.RS(strBasic) + t.Assert(j, x) + }) + gtest.C(t, func(t *gtest.T) { + x := uint64(13439708950444349959) + j := ghash.RS64(strBasic) t.Assert(j, x) }) } -func Test_SDBMHash64(t *testing.T) { - var x uint64 = 9881052176572890693 +func Test_JS(t *testing.T) { gtest.C(t, func(t *gtest.T) { - j := ghash.SDBMHash64(strBasic) + x := uint32(498688898) + j := ghash.JS(strBasic) + t.Assert(j, x) + }) + gtest.C(t, func(t *gtest.T) { + x := uint64(13410163655098759877) + j := ghash.JS64(strBasic) t.Assert(j, x) }) } -func Test_RSHash(t *testing.T) { - var x uint32 = 1944033799 +func Test_PJW(t *testing.T) { gtest.C(t, func(t *gtest.T) { - j := ghash.RSHash(strBasic) + x := uint32(7244206) + j := ghash.PJW(strBasic) + t.Assert(j, x) + }) + gtest.C(t, func(t *gtest.T) { + x := uint64(31150) + j := ghash.PJW64(strBasic) t.Assert(j, x) }) } -func Test_RSHash64(t *testing.T) { - var x uint64 = 13439708950444349959 +func Test_ELF(t *testing.T) { gtest.C(t, func(t *gtest.T) { - j := ghash.RSHash64(strBasic) + x := uint32(7244206) + j := ghash.ELF(strBasic) + t.Assert(j, x) + }) + gtest.C(t, func(t *gtest.T) { + x := uint64(31150) + j := ghash.ELF64(strBasic) t.Assert(j, x) }) } -func Test_JSHash(t *testing.T) { - var x uint32 = 498688898 +func Test_DJB(t *testing.T) { gtest.C(t, func(t *gtest.T) { - j := ghash.JSHash(strBasic) + x := uint32(959862602) + j := ghash.DJB(strBasic) + t.Assert(j, x) + }) + gtest.C(t, func(t *gtest.T) { + x := uint64(2519720351310960458) + j := ghash.DJB64(strBasic) t.Assert(j, x) }) } -func Test_JSHash64(t *testing.T) { - var x uint64 = 13410163655098759877 +func Test_AP(t *testing.T) { gtest.C(t, func(t *gtest.T) { - j := ghash.JSHash64(strBasic) - t.Assert(j, x) - }) -} - -func Test_PJWHash(t *testing.T) { - var x uint32 = 7244206 - gtest.C(t, func(t *gtest.T) { - j := ghash.PJWHash(strBasic) - t.Assert(j, x) - }) -} - -func Test_PJWHash64(t *testing.T) { - var x uint64 = 31150 - gtest.C(t, func(t *gtest.T) { - j := ghash.PJWHash64(strBasic) - t.Assert(j, x) - }) -} - -func Test_ELFHash(t *testing.T) { - var x uint32 = 7244206 - gtest.C(t, func(t *gtest.T) { - j := ghash.ELFHash(strBasic) - t.Assert(j, x) - }) -} - -func Test_ELFHash64(t *testing.T) { - var x uint64 = 31150 - gtest.C(t, func(t *gtest.T) { - j := ghash.ELFHash64(strBasic) - t.Assert(j, x) - }) -} - -func Test_DJBHash(t *testing.T) { - var x uint32 = 959862602 - gtest.C(t, func(t *gtest.T) { - j := ghash.DJBHash(strBasic) - t.Assert(j, x) - }) -} - -func Test_DJBHash64(t *testing.T) { - var x uint64 = 2519720351310960458 - gtest.C(t, func(t *gtest.T) { - j := ghash.DJBHash64(strBasic) - t.Assert(j, x) - }) -} - -func Test_APHash(t *testing.T) { - var x uint32 = 3998202516 - gtest.C(t, func(t *gtest.T) { - j := ghash.APHash(strBasic) - t.Assert(j, x) - }) -} - -func Test_APHash64(t *testing.T) { - var x uint64 = 2531023058543352243 - gtest.C(t, func(t *gtest.T) { - j := ghash.APHash64(strBasic) + x := uint32(3998202516) + j := ghash.AP(strBasic) + t.Assert(j, x) + }) + gtest.C(t, func(t *gtest.T) { + x := uint64(2531023058543352243) + j := ghash.AP64(strBasic) t.Assert(j, x) }) }