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

fusionToList方法存在bug,因为Set是无序集合 #1

Open
shileiyuan86 opened this issue Mar 7, 2022 · 1 comment
Open

fusionToList方法存在bug,因为Set是无序集合 #1

shileiyuan86 opened this issue Mar 7, 2022 · 1 comment

Comments

@shileiyuan86
Copy link

fusionToList方法存在bug,Set是无序集合,里面异常数据索引有可能不是按照正常顺序存放的。所以在for循环中不会与datas索引一样按顺序取数据。
@OverRide
public double[] fusionToList(int sensitivity, double[] datas) {
Set set = oc(sensitivity, datas);
double[] doubles = new double[datas.length - set.size()];
Iterator iterator = set.iterator();
Integer next = iterator.hasNext() ? iterator.next() : null;
int index = 0;
for (int i = 0; i < datas.length; i++) {
if (next != null && next.equals(i)) {
next = iterator.hasNext() ? iterator.next() : null;
continue;
}
doubles[index++] = datas[i];
}
return doubles;
}

@shileiyuan86
Copy link
Author

可以这样,可不用考虑索引顺序影响:
Set set = oc(sensitivity, datas);
double[] doubles = new double[datas.length - set.size()];
int index = 0;
for (int i = 0; i < datas.length; i++) {
if (!set.contains(i)) {
doubles[index++] = datas[i];
}
}
return doubles;

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

No branches or pull requests

1 participant