Skip to content

Commit

Permalink
remove wrong rehash function
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiling-J committed Oct 27, 2024
1 parent 25d3ce5 commit c4b1967
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 2 additions & 7 deletions internal/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,11 @@ func (s *CountMinSketch) EnsureCapacity(size uint) {
}

func spread(h uint64) uint64 {
h ^= h >> 17
h *= 0xed5ad4bb
h ^= h >> 11
h *= 0xac4c1b51
h ^= h >> 15
return h
}

func rehash(h uint64) uint64 {
h *= 0x31848bab
h ^= h >> 14
h *= 0x94d049bb133111eb
h ^= h >> 31
return h
}
13 changes: 13 additions & 0 deletions internal/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ func TestSketch_ResetFreq(t *testing.T) {

}

func TestSketch_Small(t *testing.T) {
sketch := NewCountMinSketch()
sketch.EnsureCapacity(512)
hasher := NewHasher[uint64](nil)
for i := 0; i < 605; i++ {
fmt.Printf("add %d:", i)
h := hasher.hash(uint64(i))
sketch.Add(h)
require.Equal(t, 1, int(sketch.Estimate(h)), i)

}
}

func TestSketch_ResetAddition(t *testing.T) {
sketch := NewCountMinSketch()
sketch.EnsureCapacity(100)
Expand Down

0 comments on commit c4b1967

Please sign in to comment.