Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

topN取词时,之前的方法是遍历循环,每次都删除索引为topN的对象, 如果数据量大删除时会导致底层数据的多次移动 #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

echohlne
Copy link

topN取词时,之前的方法是遍历循环,每次都删除索引为topN的对象, 如果数据量大删除时会导致底层数据的多次移动

@112292454
Copy link

112292454 commented Mar 24, 2023

作者这个写法雀实迷惑……而且上面的排序现在java8也会报错
sublist好像只是截取一个视图,没有释放其余不要的词的空间吧,还是新开一个list,把top的add进去好一点?
不过这东西五年了()估摸也没人看

                keywordList.sort(Keyword::compareTo);
		List<Keyword> res=new ArrayList<>();
		topN=Math.min(topN,keywordList.size());
		for (int i = 0; i < topN; i++) {
			res.add(keywordList.get(i));
		}
	@Override
	public int compareTo(Keyword o){
		return Double.compare(o.tfidfvalue,this.tfidfvalue);
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants