Skip to content

Commit fc87f24

Browse files
go all in on IntHashMap and LongHashMap
1 parent 255489c commit fc87f24

File tree

6 files changed

+49
-37
lines changed

6 files changed

+49
-37
lines changed

GenotypeAssays/src/org/labkey/genotypeassays/GenotypeAssaysManager.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.labkey.api.assay.AssayProvider;
2525
import org.labkey.api.assay.AssayService;
2626
import org.labkey.api.collections.CaseInsensitiveHashMap;
27+
import org.labkey.api.collections.IntHashMap;
28+
import org.labkey.api.collections.IntHashSet;
2729
import org.labkey.api.data.ColumnInfo;
2830
import org.labkey.api.data.CompareType;
2931
import org.labkey.api.data.Container;
@@ -118,8 +120,8 @@ public Pair<List<Long>, List<Long>> cacheAnalyses(final ViewContext ctx, final E
118120
AssayProtocolSchema schema = ap.createProtocolSchema(u, ctx.getContainer(), protocol, null);
119121
final TableInfo assayDataTable = schema.getTable(AssayProtocolSchema.DATA_TABLE_NAME);
120122

121-
final Map<Integer, List<Map<String, Object>>> rowHash = new HashMap<>();
122-
final Map<Integer, Set<Integer>> toDeleteByAnalysis = new HashMap<>();
123+
final Map<Integer, List<Map<String, Object>>> rowHash = new IntHashMap<>();
124+
final Map<Integer, Set<Integer>> toDeleteByAnalysis = new IntHashMap<>();
123125

124126
TableSelector tsAlignments = new TableSelector(tableAlignments, cols.values(), new SimpleFilter(FieldKey.fromString("key"), Arrays.asList(pks), CompareType.IN), null);
125127
tsAlignments.forEach(new Selector.ForEachBlock<ResultSet>()
@@ -139,7 +141,7 @@ public void exec(ResultSet object) throws SQLException
139141
filter.addCondition(FieldKey.fromString("Run/assayType"), SBT_LINEAGE_ASSAY_TYPE);
140142

141143
TableSelector ts = new TableSelector(assayDataTable, PageFlowUtil.set("RowId"), filter, null);
142-
Set<Integer> existing = new HashSet<>(ts.getArrayList(Integer.class));
144+
Set<Integer> existing = new IntHashSet(ts.getArrayList(Integer.class));
143145
if (!existing.isEmpty())
144146
{
145147
Set<Integer> toDelete = toDeleteByAnalysis.containsKey(analysisId) ? toDeleteByAnalysis.get(analysisId) : new HashSet<Integer>();
@@ -196,8 +198,8 @@ public Pair<List<Long>, List<Long>> cacheHaplotypes(final ViewContext ctx, final
196198
fieldKeys.add(FieldKey.fromString("readset/subjectid"));
197199
fieldKeys.add(FieldKey.fromString("readset/sampledate"));
198200

199-
Set<Integer> analysisIds = new HashSet<>();
200-
final Map<Integer, List<JSONObject>> haploMap = new HashMap<>();
201+
Set<Integer> analysisIds = new IntHashSet();
202+
final Map<Integer, List<JSONObject>> haploMap = new IntHashMap<>();
201203
for (JSONObject row : JsonUtil.toJSONObjectList(data))
202204
{
203205
Integer analysisId = row.getInt("analysisId");
@@ -217,8 +219,8 @@ public Pair<List<Long>, List<Long>> cacheHaplotypes(final ViewContext ctx, final
217219
AssayProtocolSchema schema = ap.createProtocolSchema(u, ctx.getContainer(), protocol, null);
218220
final TableInfo assayDataTable = schema.getTable(AssayProtocolSchema.DATA_TABLE_NAME);
219221

220-
final Map<Integer, List<Map<String, Object>>> rowHash = new HashMap<>();
221-
final Map<Integer, Set<Integer>> toDeleteByAnalysis = new HashMap<>();
222+
final Map<Integer, List<Map<String, Object>>> rowHash = new IntHashMap<>();
223+
final Map<Integer, Set<Integer>> toDeleteByAnalysis = new IntHashMap<>();
222224

223225
TableSelector tsAlignments = new TableSelector(tableAnalyses, cols.values(), new SimpleFilter(FieldKey.fromString("rowid"), analysisIds, CompareType.IN), null);
224226
tsAlignments.forEach(new Selector.ForEachBlock<ResultSet>()
@@ -244,10 +246,10 @@ public void exec(ResultSet object) throws SQLException
244246
filter.addCondition(FieldKey.fromString("Run/assayType"), HAPLOTYPE_ASSAY_TYPE);
245247

246248
TableSelector ts = new TableSelector(assayDataTable, PageFlowUtil.set("RowId"), filter, null);
247-
Set<Integer> existing = new HashSet<>(ts.getArrayList(Integer.class));
249+
Set<Integer> existing = new IntHashSet(ts.getArrayList(Integer.class));
248250
if (!existing.isEmpty())
249251
{
250-
Set<Integer> toDelete = toDeleteByAnalysis.containsKey(analysisId) ? toDeleteByAnalysis.get(analysisId) : new HashSet<>();
252+
Set<Integer> toDelete = toDeleteByAnalysis.containsKey(analysisId) ? toDeleteByAnalysis.get(analysisId) : new IntHashSet();
251253
toDelete.addAll(existing);
252254
toDeleteByAnalysis.put(analysisId, toDelete);
253255
}

primeseq/src/org/labkey/primeseq/analysis/MethylationRateComparisonHandler.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import org.jetbrains.annotations.Nullable;
1616
import org.json.JSONArray;
1717
import org.json.JSONObject;
18+
import org.labkey.api.collections.IntHashMap;
19+
import org.labkey.api.collections.StringHashMap;
1820
import org.labkey.api.data.Container;
1921
import org.labkey.api.jbrowse.JBrowseService;
2022
import org.labkey.api.module.Module;
@@ -49,7 +51,6 @@
4951
import java.util.ArrayList;
5052
import java.util.Arrays;
5153
import java.util.Date;
52-
import java.util.HashMap;
5354
import java.util.LinkedHashSet;
5455
import java.util.List;
5556
import java.util.Map;
@@ -188,7 +189,7 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
188189
ctx.getLogger().info(groupNames.getString(i));
189190
}
190191

191-
Map<Integer, Integer> fileToGroupMap = new HashMap<>();
192+
Map<Integer, Integer> fileToGroupMap = new IntHashMap<>();
192193
JSONObject map = ctx.getParams().getJSONObject("fileToGroupMap");
193194
for (String id : map.keySet())
194195
{
@@ -201,7 +202,7 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
201202
String statisticalMethod = ctx.getParams().optString("statisticalMethod");
202203

203204
//build map of site rates
204-
Map<String, Map<Integer, Map<Integer, List<Double>>>> rateMap = new HashMap<>();
205+
Map<String, Map<Integer, Map<Integer, List<Double>>>> rateMap = new StringHashMap<>();
205206

206207
int i = 0;
207208
for (SequenceOutputFile o : inputFiles)
@@ -268,12 +269,12 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
268269

269270
if (!rateMap.containsKey(chr))
270271
{
271-
rateMap.put(chr, new HashMap<>());
272+
rateMap.put(chr, new IntHashMap<>());
272273
}
273274

274275
if (!rateMap.get(chr).containsKey(pos))
275276
{
276-
rateMap.get(chr).put(pos, new HashMap<>());
277+
rateMap.get(chr).put(pos, new IntHashMap<>());
277278
}
278279

279280
if (!rateMap.get(chr).get(pos).containsKey(groupNum))

primeseq/src/org/labkey/primeseq/pipeline/MhcMigrationPipelineJob.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.labkey.api.assay.AssayProvider;
66
import org.labkey.api.assay.AssayService;
77
import org.labkey.api.collections.CaseInsensitiveHashMap;
8+
import org.labkey.api.collections.IntHashMap;
9+
import org.labkey.api.collections.LongHashMap;
810
import org.labkey.api.data.CompareType;
911
import org.labkey.api.data.Container;
1012
import org.labkey.api.data.ContainerManager;
@@ -397,10 +399,11 @@ private void createAlignmentSummary() throws PipelineJobException
397399
continue;
398400
}
399401

400-
final Map<Integer, Integer> alignmentSummaryMap = new HashMap<>(srr.getRowCount().intValue());
402+
final Map<Integer, Integer> alignmentSummaryMap = new IntHashMap<>(srr.getRowCount().intValue());
401403
srr.getRowset().forEach(rs -> {
402404
CaseInsensitiveHashMap<Object> map = new CaseInsensitiveHashMap<>();
403-
Integer localId = analysisMap.get(rs.getValue("analysis_id"));
405+
Number analysisId = (Number)rs.getValue("analysis_id");
406+
Integer localId = analysisMap.get(analysisId.intValue());
404407
if (localId == null)
405408
{
406409
throw new RuntimeException("Unable to find analysis: " + rs.getValue("analysis_id"));
@@ -640,16 +643,16 @@ else if (r.getValue("dataid/Run/JobId/FilePath") != null)
640643

641644
//All of these map remote Id to local Id
642645
private final Map<Integer, Container> workbookMap = new TreeMap<>();
643-
private final Map<Integer, Integer> readsetMap = new HashMap<>();
644-
private final Map<Integer, Integer> readdataMap = new HashMap<>();
645-
private final Map<Integer, Integer> analysisMap = new HashMap<>();
646-
private final Map<Integer, Integer> analysisToFileMap = new HashMap<>(); //local analysis_id -> alignment file
647-
private final Map<Integer, String> analysisToJobPath = new HashMap<>();
648-
private final Map<Integer, Integer> libraryMap = new HashMap<>();
649-
private final Map<Integer, Integer> outputFileMap = new HashMap<>();
650-
private final Map<Integer, Integer> sequenceMap = new HashMap<>();
651-
private final Map<Long, Long> runIdMap = new HashMap<>(5000);
652-
private final Map<Integer, Integer> jobIdMap = new HashMap<>(5000);
646+
private final Map<Integer, Integer> readsetMap = new IntHashMap<>();
647+
private final Map<Integer, Integer> readdataMap = new IntHashMap<>();
648+
private final Map<Integer, Integer> analysisMap = new IntHashMap<>();
649+
private final Map<Integer, Integer> analysisToFileMap = new IntHashMap<>(); //local analysis_id -> alignment file
650+
private final Map<Integer, String> analysisToJobPath = new IntHashMap<>();
651+
private final Map<Integer, Integer> libraryMap = new IntHashMap<>();
652+
private final Map<Integer, Integer> outputFileMap = new IntHashMap<>();
653+
private final Map<Integer, Integer> sequenceMap = new IntHashMap<>();
654+
private final Map<Long, Long> runIdMap = new LongHashMap<>(5000);
655+
private final Map<Integer, Integer> jobIdMap = new IntHashMap<>(5000);
653656
private final Map<URI, Long> expDataMap = new HashMap<>(10000);
654657

655658
private void createLibraryMembers(Set<String> preExisting)

tcrdb/src/org/labkey/tcrdb/TCRdbController.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import org.labkey.api.action.ExportAction;
2727
import org.labkey.api.action.SimpleViewAction;
2828
import org.labkey.api.action.SpringActionController;
29+
import org.labkey.api.collections.IntHashMap;
30+
import org.labkey.api.collections.IntHashSet;
31+
import org.labkey.api.collections.StringHashMap;
2932
import org.labkey.api.data.ColumnInfo;
3033
import org.labkey.api.data.CompareType;
3134
import org.labkey.api.data.Container;
@@ -528,7 +531,7 @@ public void export(DownloadCloneMaterialsForm form, HttpServletResponse response
528531
}
529532

530533
StringBuilder fasta = new StringBuilder();
531-
Map<Integer, Set<String>> segmentsByLibrary = new HashMap<>();
534+
Map<Integer, Set<String>> segmentsByLibrary = new IntHashMap<>();
532535

533536
//find assay records
534537
SimpleFilter assayFilter = new SimpleFilter(FieldKey.fromString("rowId"), rowIds, CompareType.IN);
@@ -689,12 +692,12 @@ public void export(DownloadCloneMaterialsForm form, HttpServletResponse response
689692

690693
TableSelector ts = new TableSelector(assayData, cols.values(), assayFilter, null);
691694
Set<String> segmentsByName = new HashSet<>();
692-
Map<Integer, Set<String>> segmentsByLibrary = new HashMap<>();
695+
Map<Integer, Set<String>> segmentsByLibrary = new IntHashMap<>();
693696

694-
Map<Integer, Set<String>> clnaToCloneMap = new HashMap<>();
695-
Map<String, String> clnaToCDR3Map = new HashMap<>();
697+
Map<Integer, Set<String>> clnaToCloneMap = new IntHashMap<>();
698+
Map<String, String> clnaToCDR3Map = new StringHashMap<>();
696699
StringBuilder imputedSequences = new StringBuilder();
697-
Set<Integer> analyses = new HashSet<>();
700+
Set<Integer> analyses = new IntHashSet();
698701
final String[] segmentFields = new String[]{"vHit", "jHit", "cHit"};
699702
ts.forEachResults(rs -> {
700703
Integer libraryId = rs.getObject(FieldKey.fromString("libraryId/libraryId")) == null ? null : rs.getInt(FieldKey.fromString("libraryId/libraryId"));

tcrdb/src/org/labkey/tcrdb/pipeline/CellRangerVDJUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.labkey.api.assay.AssayProvider;
1010
import org.labkey.api.assay.AssayService;
1111
import org.labkey.api.collections.CaseInsensitiveHashMap;
12+
import org.labkey.api.collections.IntHashMap;
13+
import org.labkey.api.collections.StringHashMap;
1214
import org.labkey.api.data.Container;
1315
import org.labkey.api.data.SimpleFilter;
1416
import org.labkey.api.data.TableInfo;
@@ -125,8 +127,8 @@ public void importAssayData(PipelineJob job, AnalysisModel model, File vLoupeFil
125127
}
126128

127129
File cDNAFile = CellHashingService.get().getCDNAInfoFile(outDir);
128-
Map<String, CDNA_Library> htoNameToCDNAMap = new HashMap<>();
129-
Map<Integer, CDNA_Library> cDNAMap = new HashMap<>();
130+
Map<String, CDNA_Library> htoNameToCDNAMap = new StringHashMap<>();
131+
Map<Integer, CDNA_Library> cDNAMap = new IntHashMap<>();
130132
if (cDNAFile.exists())
131133
{
132134
try (CSVReader reader = new CSVReader(Readers.getReader(cDNAFile), '\t'))
@@ -277,7 +279,7 @@ else if ("Low Counts".equals(hto))
277279
}
278280

279281
Map<String, AssayModel> rows = new HashMap<>();
280-
Map<Integer, Set<String>> totalCellsBySample = new HashMap<>();
282+
Map<Integer, Set<String>> totalCellsBySample = new IntHashMap<>();
281283
Set<String> uniqueContigNames = new HashSet<>();
282284
_log.info("processing clonotype CSV: " + allCsv.getPath());
283285

tcrdb/src/org/labkey/tcrdb/pipeline/MiXCRAnalysis.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.labkey.api.assay.AssayProvider;
1313
import org.labkey.api.assay.AssayService;
1414
import org.labkey.api.collections.CaseInsensitiveHashMap;
15+
import org.labkey.api.collections.IntHashMap;
1516
import org.labkey.api.data.CompareType;
1617
import org.labkey.api.data.Container;
1718
import org.labkey.api.data.SimpleFilter;
@@ -290,11 +291,11 @@ public Output performAnalysisPerSampleRemote(Readset rs, File inputBam, Referenc
290291
String version = new MiXCRWrapper(getPipelineCtx().getLogger()).getVersionString();
291292

292293
//iterate selected species/loci:
293-
Map<Integer, Map<String, Map<String, List<File>>>> tables = new HashMap<>();
294+
Map<Integer, Map<String, Map<String, List<File>>>> tables = new IntHashMap<>();
294295
JSONArray libraries = getTcrDbs();
295296

296-
Map<Integer, Map<String, Map<String, Integer>>> totalReadsInExportedAlignments = new HashMap<>();
297-
Map<Integer, Map<String, Map<String, Integer>>> totalReadsInExportedClones = new HashMap<>();
297+
Map<Integer, Map<String, Map<String, Integer>>> totalReadsInExportedAlignments = new IntHashMap<>();
298+
Map<Integer, Map<String, Map<String, Integer>>> totalReadsInExportedClones = new IntHashMap<>();
298299

299300
for (JSONObject library : JsonUtil.toJSONObjectList(libraries))
300301
{

0 commit comments

Comments
 (0)