Skip to content

Commit c6ddac7

Browse files
authored
Merge pull request #3 from yourbasic/tip
Tip
2 parents 3d3d3d0 + 4b348f2 commit c6ddac7

3 files changed

Lines changed: 60 additions & 6 deletions

File tree

filter_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,60 @@ func TestFilter(t *testing.T) {
5858
}
5959
}
6060

61+
func TestFilterByte(t *testing.T) {
62+
s1 := []byte("asöldkgjaösldkgaösldkasldgjkaösldkgjöasgkdjg")
63+
s2 := []byte("elasödlnkgaölsdkfgaölsdkjfaölsdkgaölskgnaösl")
64+
s3 := []byte("aölsdgkaösldkgaösldkgjaölsdkjgaölsdkgjaösldk")
65+
for n := 0; n < 100; n++ {
66+
for p := 1; p <= 128; p *= 2 {
67+
filter := New(n, p)
68+
member := filter.TestByte(s1)
69+
if member {
70+
t.Errorf("TestByte(s1) = %v; want false\n", member)
71+
}
72+
count := filter.Count()
73+
if count != 0 {
74+
t.Errorf("Count() = %d; want 0\n", count)
75+
}
76+
77+
member = filter.AddByte(s1)
78+
if member {
79+
t.Errorf("AddByte(s1) = %v; want false\n", member)
80+
}
81+
count = filter.Count()
82+
if count != 1 {
83+
t.Errorf("Count() = %d; want 1\n", count)
84+
}
85+
member = filter.TestByte(s1)
86+
if !member {
87+
t.Errorf("TestByte(s1) = %v; want true\n", member)
88+
}
89+
member = filter.TestByte(s2)
90+
if member {
91+
t.Errorf("TestByte(s2) = %v; want false\n", member)
92+
}
93+
94+
member = filter.AddByte(s1)
95+
if !member {
96+
t.Errorf("AddByte(s1) = %v; want true\n", member)
97+
}
98+
count = filter.Count()
99+
if count != 1 {
100+
t.Errorf("Count() = %d; want 1\n", count)
101+
}
102+
103+
member = filter.AddByte(s3)
104+
if member {
105+
t.Errorf("AddByte(s3) = %v; want false\n", member)
106+
}
107+
count = filter.Count()
108+
if count != 2 {
109+
t.Errorf("Count() = %d; want 2\n", count)
110+
}
111+
}
112+
}
113+
}
114+
61115
func TestUnion(t *testing.T) {
62116
s1 := "asöldkgjaösldkgaösldkasldgjkaösldkgjöasgkdjg"
63117
s2 := "elasödlnkgaölsdkfgaölsdkjfaölsdkgaölskgnaösl"

hash.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type digest struct {
2222
h2 uint64
2323
}
2424

25-
func Uint64(b []byte) uint64 {
25+
func uint64byte(b []byte) uint64 {
2626
return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
2727
uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
2828
}
@@ -32,8 +32,8 @@ func (d *digest) bmix(p []byte) (tail []byte) {
3232
nblocks := len(p) / 16
3333
for i := 0; i < nblocks; i++ {
3434
j := 16 * i
35-
k1 := Uint64(p[j : j+8])
36-
k2 := Uint64(p[j+8 : j+16])
35+
k1 := uint64byte(p[j : j+8])
36+
k2 := uint64byte(p[j+8 : j+16])
3737
k1 *= c1
3838
k1 = (k1 << 31) | (k1 >> 33)
3939
k1 *= c2

hash_string.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type digestString struct {
1717
h2 uint64
1818
}
1919

20-
func Uint64String(b string) uint64 {
20+
func uint64String(b string) uint64 {
2121
return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
2222
uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
2323
}
@@ -27,8 +27,8 @@ func (d *digestString) bmixString(p string) (tail string) {
2727
nblocks := len(p) / 16
2828
for i := 0; i < nblocks; i++ {
2929
j := 16 * i
30-
k1 := Uint64String(p[j : j+8])
31-
k2 := Uint64String(p[j+8 : j+16])
30+
k1 := uint64String(p[j : j+8])
31+
k2 := uint64String(p[j+8 : j+16])
3232
k1 *= c1
3333
k1 = (k1 << 31) | (k1 >> 33)
3434
k1 *= c2

0 commit comments

Comments
 (0)