Ejemplo n.º 1
0
func (this *KHHCountMinSketch) GetTop() []int64 {
	if this.topcent != nil {
		return this.topcent
	}
	this.topcent = []int64{}
	this.counts = []int64{}
	for !this.priorityQueue.IsEmpty() {
		tmp := this.priorityQueue.Poll()
		this.topcent = append(this.topcent, tmp)
		this.counts = append(this.counts, this.countlist[utils.HashCode(tmp)])
	}
	return this.topcent
}
Ejemplo n.º 2
0
func (this *KHHCountMinSketch) Add(e int64) {
	count := this.AddLong(utils.HashCode(e), 1)
	if _, ok := this.items[utils.HashCode(e)]; !ok {
		this.countlist[utils.HashCode(e)] = count
		this.priorityQueue.Enqueue(e)
		this.items[utils.HashCode(e)] = e
	} else {
		this.priorityQueue.Dequeue()
		this.items[utils.HashCode(e)] = e
		this.countlist[utils.HashCode(e)] = count
		this.priorityQueue.Enqueue(e)
	}

	if this.priorityQueue.Size() > this.k {
		removed := this.priorityQueue.Poll()
		delete(this.items, removed)
	}
}