Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func hash64(s string) hash.Hash64 {

func randStr(n int) string {
i := rand.Uint32()
return fmt.Sprintf("a%s %s", i, n)
return fmt.Sprintf("a%d %d", i, n)
}

func benchmark(precision uint8, n int) {
Expand Down
12 changes: 8 additions & 4 deletions hyperloglogplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,17 @@ func (h *HyperLogLogPlus) toNormal() {

// Add adds a new item to HyperLogLogPlus h.
func (h *HyperLogLogPlus) Add(item Hash64) {
x := item.Sum64()
h.AddUInt64(item.Sum64())
}

// Add adds a new item to HyperLogLogPlus h.
func (h *HyperLogLogPlus) AddUInt64(item uint64) {
if h.sparse {
h.tmpSet.Add(h.encodeHash(x))
h.tmpSet.Add(h.encodeHash(item))
h.maybeMerge()
} else {
i := eb64(x, 64, 64-h.p) // {x63,...,x64-p}
w := x<<h.p | 1<<(h.p-1) // {x63-p,...,x0}
i := eb64(item, 64, 64-h.p) // {x63,...,x64-p}
w := item<<h.p | 1<<(h.p-1) // {x63-p,...,x0}

zeroBits := clz64(w) + 1
if zeroBits > h.reg[i] {
Expand Down
2 changes: 1 addition & 1 deletion hyperloglogplus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestHLLPPAddNoSparse(t *testing.T) {
t.Error(n)
}

h.Add(fakeHash64(0xff03080000000000))
h.AddUInt64(fakeHash64(0xff03080000000000).Sum64())
n = h.reg[0xff03]
if n != 5 {
t.Error(n)
Expand Down