Skip to content

Commit

Permalink
Some additional safety checks, so that we don't skip any Diagnosis Keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
mh- committed Nov 9, 2020
1 parent 230e036 commit 03a76b9
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,31 +555,39 @@ public void onComplete() {
int dkListLen = diagnosisKeysList.size();
if ((rpiList != null) && (dkListLen != 0)) {
int desiredThreads = Runtime.getRuntime().availableProcessors();
if (desiredThreads < 1) {
desiredThreads = 1;
}
Log.d(TAG, "Matching: Trying to split into " + desiredThreads + " threads.");
if (desiredThreads > dkListLen) {
desiredThreads = dkListLen;
Log.d(TAG, "Matching: Reduced to " + desiredThreads + " threads, because of short list");
}
ArrayList<Pair<Integer, Integer>> ranges = new ArrayList<>();
int lastEndExclusive = 0;
for (int i = 1; i <= desiredThreads; i++) {
int newEndExclusive = dkListLen * i / desiredThreads;
int newEndExclusive = 0;
int i = 1;
while (newEndExclusive < dkListLen) {
newEndExclusive = dkListLen * i / desiredThreads;
if (newEndExclusive < lastEndExclusive) {
newEndExclusive = lastEndExclusive;
}
ranges.add(new Pair<>(lastEndExclusive, newEndExclusive));
Log.d(TAG, "Matching: Range " + lastEndExclusive + ".." + newEndExclusive);
lastEndExclusive = newEndExclusive;
if (newEndExclusive >= dkListLen) {
break;
if (newEndExclusive > dkListLen) {
newEndExclusive = dkListLen;
}
if (newEndExclusive > lastEndExclusive) {
ranges.add(new Pair<>(lastEndExclusive, newEndExclusive));
Log.d(TAG, "Matching: Range " + lastEndExclusive + ".." + newEndExclusive);
}
lastEndExclusive = newEndExclusive;
i++;
}
numMatchingThreads = ranges.size();

ArrayList<Observable<Matcher.ProgressAndMatchEntryAndDkAndDay>> observables = new ArrayList<>();
for (int i = 0; i < numMatchingThreads; i++) {
for (int threadNum = 0; threadNum < numMatchingThreads; threadNum++) {
Matcher matcher = new Matcher(rpiList,
diagnosisKeysList.subList(ranges.get(i).first, ranges.get(i).second), i);
diagnosisKeysList.subList(ranges.get(threadNum).first, ranges.get(threadNum).second), threadNum);
observables.add(
matcher.getMatchingObservable()
.subscribeOn(Schedulers.computation())
Expand Down

0 comments on commit 03a76b9

Please sign in to comment.