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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
topN取词时,之前的方法是遍历循环,每次都删除索引为topN的对象, 如果数据量大删除时会导致底层数据的多次移动
  • Loading branch information
eabcd committed Dec 11, 2019
commit d738c4224b84fa2b38c571c65fbf47d8e5d11190
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ public List<Keyword> analyze(String content,int topN){
}

Collections.sort(keywordList);

if(keywordList.size()>topN) {
int num=keywordList.size()-topN;
for(int i=0;i<num;i++) {
keywordList.remove(topN);
}
}
return keywordList;
return keywordList.size() > topN ? keywordList.subList(0, topN) : keywordList;
}

/**
Expand Down