mirror of
https://github.com/LBRYFoundation/lbcutil.git
synced 2025-08-23 17:47:30 +00:00
This commit finishes the work started by @dajohi on bloom filters. - Rename the package from bloomfilter to bloom - Rename New function to NewFiler - Rename Load function to LoadFilter - Rename BloomFilter type to Filter - Rename Contains to Matches - Correct tx match handling to match all inputs and outputs instead of only the first one - Optimize murmur hash function by using constants - Optimize the merkle block creation and reduce num of memory allocations required - Make MsgFilterLoad concurrent safe as intended - Update various code consistency issues - Add a lot of comments - Improve tests - Make the code golint clean
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package bloom_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/conformal/btcutil/bloom"
|
|
)
|
|
|
|
// TestMurmurHash3 ensure the MurmurHash3 function produces the correct hash
|
|
// when given various seeds and data.
|
|
func TestMurmurHash3(t *testing.T) {
|
|
var tests = []struct {
|
|
seed uint32
|
|
data []byte
|
|
out uint32
|
|
}{
|
|
{0x00000000, []byte{}, 0x00000000},
|
|
{0xfba4c795, []byte{}, 0x6a396f08},
|
|
{0xffffffff, []byte{}, 0x81f16f39},
|
|
{0x00000000, []byte{0x00}, 0x514e28b7},
|
|
{0xfba4c795, []byte{0x00}, 0xea3f0b17},
|
|
{0x00000000, []byte{0xff}, 0xfd6cf10d},
|
|
{0x00000000, []byte{0x00, 0x11}, 0x16c6b7ab},
|
|
{0x00000000, []byte{0x00, 0x11, 0x22}, 0x8eb51c3d},
|
|
{0x00000000, []byte{0x00, 0x11, 0x22, 0x33}, 0xb4471bf8},
|
|
{0x00000000, []byte{0x00, 0x11, 0x22, 0x33, 0x44}, 0xe2301fa8},
|
|
{0x00000000, []byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55}, 0xfc2e4a15},
|
|
{0x00000000, []byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66}, 0xb074502c},
|
|
{0x00000000, []byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}, 0x8034d2a0},
|
|
{0x00000000, []byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}, 0xb4698def},
|
|
}
|
|
|
|
for i, test := range tests {
|
|
result := bloom.MurmurHash3(test.seed, test.data)
|
|
if result != test.out {
|
|
t.Errorf("MurmurHash3 test #%d failed: got %v want %v\n",
|
|
i, result, test.out)
|
|
continue
|
|
}
|
|
}
|
|
}
|