forked from deephaven/deephaven-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct floating point ChunkHasher (deephaven#5778)
This adds documentation and a new hashCode method to the `io.deephaven.util.compare` package that is consistent with Deephaven equality. Specifically, this ensures that the floating points values -0.0 and 0.0 hash to the same value. Testing was added around aggregation keys, join keys, aggregations, min/max formulas, and sort results. Of note is that unique and distinct aggregations currently rely on `io.deephaven.chunk.WritableChunk#sort()`, which treats -0.0 < 0.0. This effects the encounter order returned by these aggregations, and could be seen as inconsistent with our stated goals of treating -0.0 == 0.0. This does not affect the consistency of the sort operation. It is hard to be confident that the testing coverage around this issue is fully complete; that said, this does make us much more consistent in the tested operations wrt Deephaven equality. This is a prerequisite for deephaven#5605 Fixes deephaven#3768
- Loading branch information
1 parent
90b9283
commit 2ea2363
Showing
33 changed files
with
1,956 additions
and
168 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
Util/src/main/java/io/deephaven/util/compare/BooleanComparisons.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending | ||
// | ||
package io.deephaven.util.compare; | ||
|
||
public class BooleanComparisons { | ||
|
||
/** | ||
* Compares two booleans with {@code false} before {@code true}. | ||
* | ||
* @param lhs the first value | ||
* @param rhs the second value | ||
* @return the value {@code 0} if {@code lhs} is equal to {@code rhs}; a value less than {@code 0} if {@code lhs} is | ||
* less than {@code rhs}; and a value greater than {@code 0} if {@code lhs} is greater than {@code rhs} | ||
*/ | ||
public static int compare(boolean lhs, boolean rhs) { | ||
return Boolean.compare(lhs, rhs); | ||
} | ||
|
||
/** | ||
* Compare two booleans for equality consistent with {@link #compare(boolean, boolean)}; that is | ||
* {@code compare(lhs, rhs) == 0 ⇒ eq(lhs, rhs)} and {@code compare(lhs, rhs) != 0 ⇒ !eq(lhs, rhs)}. | ||
* | ||
* <p> | ||
* Logically equivalent to {@code compare(lhs, rhs) == 0}. | ||
* | ||
* @param lhs the first value | ||
* @param rhs the second value | ||
* @return {@code true} if the values are equal, {@code false} otherwise | ||
*/ | ||
public static boolean eq(boolean lhs, boolean rhs) { | ||
return lhs == rhs; | ||
} | ||
|
||
/** | ||
* Returns a hash code for a {@code boolean} value consistent with {@link #eq(boolean, boolean)}; that is, | ||
* {@code eq(x, y) ⇒ hashCode(x) == hashCode(y)}. | ||
* | ||
* @param x the value to hash | ||
* @return a hash code value for a {@code boolean} value | ||
*/ | ||
public static int hashCode(boolean x) { | ||
return Boolean.hashCode(x); | ||
} | ||
|
||
/** | ||
* Logically equivalent to {@code compare(lhs, rhs) > 0}. | ||
* | ||
* @param lhs the first value | ||
* @param rhs the second value | ||
* @return {@code true} iff {@code lhs} is greater than {@code rhs} | ||
*/ | ||
public static boolean gt(boolean lhs, boolean rhs) { | ||
return compare(lhs, rhs) > 0; | ||
} | ||
|
||
/** | ||
* Logically equivalent to {@code compare(lhs, rhs) < 0}. | ||
* | ||
* @param lhs the first value | ||
* @param rhs the second value | ||
* @return {@code true} iff {@code lhs} is less than {@code rhs} | ||
*/ | ||
public static boolean lt(boolean lhs, boolean rhs) { | ||
return compare(lhs, rhs) < 0; | ||
} | ||
|
||
/** | ||
* Logically equivalent to {@code compare(lhs, rhs) >= 0}. | ||
* | ||
* @param lhs the first value | ||
* @param rhs the second value | ||
* @return {@code true} iff {@code lhs} is greater than or equal to {@code rhs} | ||
*/ | ||
public static boolean geq(boolean lhs, boolean rhs) { | ||
return compare(lhs, rhs) >= 0; | ||
} | ||
|
||
/** | ||
* Logically equivalent to {@code compare(lhs, rhs) <= 0}. | ||
* | ||
* @param lhs the first value | ||
* @param rhs the second value | ||
* @return {@code true} iff {@code lhs} is less than or equal to {@code rhs} | ||
*/ | ||
public static boolean leq(boolean lhs, boolean rhs) { | ||
return compare(lhs, rhs) <= 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.