func (sk *Sketch) Merge(other *Sketch) error {
	if other == nil {
		return nil
	}
	cpOther := other.Clone()
	if sk.p != cpOther.p {
		return errors.New("precisions must be equal")
	}
	if sk.sparse && other.sparse {
		for k := range other.tmpSet {
			sk.tmpSet.add(k)
		}
		for iter := other.sparseList.Iter(); iter.HasNext(); {
			sk.tmpSet.add(iter.Next())
		}
		sk.maybeToNormal()
		return nil
	}
	if sk.sparse {
		sk.toNormal()
	}
	if cpOther.sparse {
		for k := range cpOther.tmpSet {
			i, r := decodeHash(k, cpOther.p, pp)
			sk.insert(i, r)
		}
		for iter := cpOther.sparseList.Iter(); iter.HasNext(); {
			i, r := decodeHash(iter.Next(), cpOther.p, pp)
			sk.insert(i, r)
		}
	} else {
		if sk.b < cpOther.b {
			sk.regs.rebase(cpOther.b - sk.b)
			sk.b = cpOther.b
		} else {
			cpOther.regs.rebase(sk.b - cpOther.b)
			cpOther.b = sk.b
		}
		for i, v := range cpOther.regs.tailcuts {
			v1 := v.get(0)
			if v1 > sk.regs.get(uint32(i)*2) {
				sk.regs.set(uint32(i)*2, v1)
			}
			v2 := v.get(1)
			if v2 > sk.regs.get(1+uint32(i)*2) {
				sk.regs.set(1+uint32(i)*2, v2)
			}
		}
	}
	return nil
}
Merge takes another Sketch and combines it with Sketch h.
If Sketch h is using the sparse Sketch, it will be converted
to the normal Sketch.
package hyperloglog
import (
	"encoding/binary"
	"errors"
	"fmt"
	"math"
	"sort"
)
const (
	capacity = uint8(16)
	pp       = uint8(25)
	mp       = uint32(1) << pp
	version  = 1
)
type Sketch struct {
	sparse     bool
	p          uint8
	b          uint8
	m          uint32
	alpha      float64
	tmpSet     set
	sparseList *compressedList
	regs       *registers
}
func New() *Sketch {
	return New14()
}
func New14() *Sketch {
	sk, _ := new(14)
	return sk
}
func New16() *Sketch {
	sk, _ := new(16)
	return sk
}
func new(precision uint8) (*Sketch, error) {
	if precision < 4 || precision > 18 {
		return nil, fmt.Errorf("p has to be >= 4 and <= 18")
	}
	m := uint32(math.Pow(2, float64(precision)))
	return &Sketch{
		m:          m,
		p:          precision,
		alpha:      alpha(float64(m)),
		sparse:     true,
		tmpSet:     set{},
		sparseList: newCompressedList(int(m)),
	}, nil
}
func (sk *Sketch) Clone() *Sketch {
	return &Sketch{
		b:          sk.b,
		p:          sk.p,
		m:          sk.m,
		alpha:      sk.alpha,
		sparse:     sk.sparse,
		tmpSet:     sk.tmpSet.Clone(),
		sparseList: sk.sparseList.Clone(),
		regs:       sk.regs.clone(),
	}
}
func (sk *Sketch) maybeToNormal() {
	if uint32(len(sk.tmpSet))*100 > sk.m {
		sk.mergeSparse()
		if uint32(sk.sparseList.Len()) > sk.m {
			sk.toNormal()
		}
	}
}