Skip to content

Commit

Permalink
Change Double in IcedHashMap to IcedDouble (#16037)
Browse files Browse the repository at this point in the history
  • Loading branch information
maurever authored Jan 26, 2024
1 parent 393f2e3 commit 5620485
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import water.rapids.vals.ValFrame;
import water.rapids.ast.AstPrimitive;
import water.rapids.ast.AstRoot;
import water.util.IcedDouble;
import water.util.IcedHashMap;
import water.util.MathUtils;

Expand Down Expand Up @@ -171,14 +172,14 @@ private static class NumMatchTask extends MRTask<CatMatchTask> {
double[] _sortedValues;
double _noMatch;
int _startIndex;
IcedHashMap<Double, Integer> _mapping;
IcedHashMap<Double, Integer> _matchesIndexes;
IcedHashMap<IcedDouble, Integer> _mapping;
IcedHashMap<IcedDouble, Integer> _matchesIndexes;

NumMatchTask(double[] values, double noMatch, int startIndex) {
_mapping = new IcedHashMap<>();
for (int i = 0; i < values.length; i++) {
double value = values[i];
if (!_mapping.containsKey(value)) _mapping.put(values[i], i);
if (!_mapping.containsKey(new IcedDouble(value))) _mapping.put(new IcedDouble(values[i]), i);
}
_sortedValues = values.clone();
Arrays.sort(_sortedValues);
Expand Down Expand Up @@ -209,16 +210,17 @@ private static double in(Map<String, Integer> matchesIndexes, String[] sortedMat
return match >= 0 ? applyStartIndex(mapping.get(s), startIndex) : noMatch;
}

private static double in(Map<Double, Integer> matchesIndexes, double[] sortedMatches, IcedHashMap<Double, Integer> mapping, double d, double noMatch, int startIndex) {
Integer mapResult = matchesIndexes.get(d);
private static double in(Map<IcedDouble, Integer> matchesIndexes, double[] sortedMatches, IcedHashMap<IcedDouble, Integer> mapping, double d, double noMatch, int startIndex) {
IcedDouble id = new IcedDouble(d);
Integer mapResult = matchesIndexes.get(id);
int match;
if (mapResult == null){
match = binarySearchDoublesUlp(sortedMatches, 0, sortedMatches.length, d);
matchesIndexes.put(d, match);
matchesIndexes.put(id, match);
} else {
match = mapResult;
}
return match >= 0 ? applyStartIndex(mapping.get(d), startIndex) : noMatch;
return match >= 0 ? applyStartIndex(mapping.get(id).doubleValue(), startIndex) : noMatch;
}

private static double applyStartIndex(double value, int startIndex) {
Expand Down

0 comments on commit 5620485

Please sign in to comment.