有没有一种有效的方法可以从排序的多重集(TreeMultiset)中获取 n 个较高的条目?
为了说明我的意思,我发布了我效率低下的解决方案:
public SortedMultiset<DataTuple> headMultiset(int upperBound, BoundType boundType){
int i=0;
DataTuple act= this.coreData.firstEntry().getElement();
Iterator<DataTuple> itr = this.coreData.iterator();
while(i<=upperBound){
act = itr.next();
i+=this.coreData.count(act);
}
return headMultiset(act, boundType);
}
在这个例子中,DataSet 可以看作是 Object,而 this.coreData 是下属的 TreeMultiset。
我对这个话题真的很陌生,所以各种评论将不胜感激。