Skip to content

Commit

Permalink
[ALS-6173] small hpds optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sikina committed Mar 27, 2024
1 parent 35797d0 commit 6df032b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,15 @@ public void setLoadingMap(List<KeyAndValue<V>> newMap) {
this.loadingMap= newMap ;
}

public List<KeyAndValue<V>> getValuesForKeys(Set<Integer> patientIds) {
public List<KeyAndValue<V>> getValuesForKeys(List<Integer> sortedPatientIds) {
List<KeyAndValue<V>> values = new ArrayList<>();
int x = 0;
for(Integer id : patientIds) {
for(Integer id : sortedPatientIds) {
while(x < sortedByKey.length && sortedByKey[x].key<id) {
x++;
}
while(x < sortedByKey.length && sortedByKey[x].key==id) {
if (x >= sortedByKey.length) { return values; }
while(sortedByKey[x].key==id) {
values.add(sortedByKey[x]);
x++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;

import edu.harvard.hms.dbmi.avillach.hpds.data.phenotype.KeyAndValue;
Expand Down Expand Up @@ -46,7 +41,8 @@ public void runQuery(Query query, AsyncResult asyncResult) throws NotEnoughMemor
query.setRequiredFields(new ArrayList<>());

// list patients involved
Set<Integer> patientIds = abstractProcessor.getPatientSubsetForQuery(query);
List<Integer> patientIds = new ArrayList<>(abstractProcessor.getPatientSubsetForQuery(query));
patientIds.sort(Integer::compareTo);

// get start time for the timeline
long startTime = Long.MAX_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ private void exportTimeData(Query query, AsyncResult result, TreeSet<Integer> id
pathList.addAll(query.getRequiredFields());
pathList.addAll(query.getCategoryFilters().keySet());
pathList.addAll(query.getNumericFilters().keySet());

addDataForConcepts(pathList, exportedConceptPaths, idList, result);

ArrayList<Integer> ids = new ArrayList<>(idList);
ids.sort(Integer::compareTo);

addDataForConcepts(pathList, exportedConceptPaths, ids, result);
}

private void addDataForConcepts(Collection<String> pathList, Set<String> exportedConceptPaths, TreeSet<Integer> idList, AsyncResult result) throws IOException {
private void addDataForConcepts(Collection<String> pathList, Set<String> exportedConceptPaths, List<Integer> idList, AsyncResult result) throws IOException {
for (String conceptPath : pathList) {
//skip concepts we may already have encountered
if(exportedConceptPaths.contains(conceptPath)) {
Expand Down

0 comments on commit 6df032b

Please sign in to comment.