func (this *CentriodPriorityQueue) compare(centroid1 types.Centroid, centroid2 types.Centroid) int {
	count1 := centroid1.GetCount()
	count2 := centroid2.GetCount()
	if count1 > count2 {
		return 1
	} else if count1 < count2 {
		return -1
	}
	return 0
}
예제 #2
0
func (this *KHHCentroidCounter) Add(centroid types.Centroid) {
	this.count++
	count := this.AddLong(centroid.GetID(), 1)
	probed := this.frequentItems[centroid.GetID()]
	delete(this.frequentItems, centroid.GetID())

	/*for i := 0; i < centroid.GetIDs().Length(); i++ {
	    if probed != nil {
	        break;
	    }
	    if centroid.GetIDs().Get(int64(i)) {
	        delete(this.frequentItems, int64(i));
	        probed = this.frequentItems[int64(i)];
	    }
	}*/

	if probed == nil {
		this.countlist[centroid.GetID()] = count
		this.frequentItems[centroid.GetID()] = centroid
		this.priorityQueue.Enqueue(centroid)
	} else {
		this.priorityQueue.Remove(centroid.GetID())
		probed.UpdateVector(centroid.Centroid())
		probed.GetIDs().AddAll(centroid.GetIDs())
		this.frequentItems[probed.GetID()] = probed
		this.countlist[probed.GetID()] = count
		this.priorityQueue.Enqueue(probed)
	}

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