Skip to content

Commit

Permalink
Merge pull request #3 from yourbasic/tip
Browse files Browse the repository at this point in the history
Tip
  • Loading branch information
korthaj authored May 18, 2017
2 parents 3d3d3d0 + 4b348f2 commit c6ddac7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
54 changes: 54 additions & 0 deletions filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,60 @@ func TestFilter(t *testing.T) {
}
}

func TestFilterByte(t *testing.T) {
s1 := []byte("asöldkgjaösldkgaösldkasldgjkaösldkgjöasgkdjg")
s2 := []byte("elasödlnkgaölsdkfgaölsdkjfaölsdkgaölskgnaösl")
s3 := []byte("aölsdgkaösldkgaösldkgjaölsdkjgaölsdkgjaösldk")
for n := 0; n < 100; n++ {
for p := 1; p <= 128; p *= 2 {
filter := New(n, p)
member := filter.TestByte(s1)
if member {
t.Errorf("TestByte(s1) = %v; want false\n", member)
}
count := filter.Count()
if count != 0 {
t.Errorf("Count() = %d; want 0\n", count)
}

member = filter.AddByte(s1)
if member {
t.Errorf("AddByte(s1) = %v; want false\n", member)
}
count = filter.Count()
if count != 1 {
t.Errorf("Count() = %d; want 1\n", count)
}
member = filter.TestByte(s1)
if !member {
t.Errorf("TestByte(s1) = %v; want true\n", member)
}
member = filter.TestByte(s2)
if member {
t.Errorf("TestByte(s2) = %v; want false\n", member)
}

member = filter.AddByte(s1)
if !member {
t.Errorf("AddByte(s1) = %v; want true\n", member)
}
count = filter.Count()
if count != 1 {
t.Errorf("Count() = %d; want 1\n", count)
}

member = filter.AddByte(s3)
if member {
t.Errorf("AddByte(s3) = %v; want false\n", member)
}
count = filter.Count()
if count != 2 {
t.Errorf("Count() = %d; want 2\n", count)
}
}
}
}

func TestUnion(t *testing.T) {
s1 := "asöldkgjaösldkgaösldkasldgjkaösldkgjöasgkdjg"
s2 := "elasödlnkgaölsdkfgaölsdkjfaölsdkgaölskgnaösl"
Expand Down
6 changes: 3 additions & 3 deletions hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type digest struct {
h2 uint64
}

func Uint64(b []byte) uint64 {
func uint64byte(b []byte) uint64 {
return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
}
Expand All @@ -32,8 +32,8 @@ func (d *digest) bmix(p []byte) (tail []byte) {
nblocks := len(p) / 16
for i := 0; i < nblocks; i++ {
j := 16 * i
k1 := Uint64(p[j : j+8])
k2 := Uint64(p[j+8 : j+16])
k1 := uint64byte(p[j : j+8])
k2 := uint64byte(p[j+8 : j+16])
k1 *= c1
k1 = (k1 << 31) | (k1 >> 33)
k1 *= c2
Expand Down
6 changes: 3 additions & 3 deletions hash_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type digestString struct {
h2 uint64
}

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

0 comments on commit c6ddac7

Please sign in to comment.