Skip to content

Instantly share code, notes, and snippets.

@seiflotfy
Created March 17, 2018 16:24
Show Gist options
  • Save seiflotfy/9333140c14b40cce9f718668277b2a27 to your computer and use it in GitHub Desktop.
Save seiflotfy/9333140c14b40cce9f718668277b2a27 to your computer and use it in GitHub Desktop.
HLL to TailCut
func TestHLLTC_Conversion(t *testing.T) {
hash = nopHash
defer func() {
hash = hashFunc
}()
// Populate HLL
hll := NewBeta() // []uint8
for i := range hll {
val := uint8(rand.Intn(50)) + 5 // for testing purposes make min register >= 5 will also work for 0
hll.insert(uint32(i), val)
}
// Moving hll to TLC
tlc := New()
// Make sure tlc is not using sparse
tlc.sparse = false
tlc.toNormal()
// Conversion time
// 1) Get min register value
min := uint8(math.MaxUint8)
for _, val := range hll {
if min > val {
min = val
}
}
// 2) set base to minimum
tlc.b = min
// 3) iterate through hll registers and insert
for i, val := range hll {
val = val - tlc.b
if val > 15 {
val = 15
}
tlc.regs.set(uint32(i), val)
}
fmt.Println("hll est:", hll.Estimate())
fmt.Println("tlc est:", tlc.Estimate())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment