Skip to content

Commit

Permalink
Improve SortedRangeSet hash quality
Browse files Browse the repository at this point in the history
  • Loading branch information
Tal Ben-Moshe authored and findepi committed Mar 19, 2024
1 parent d3b901f commit e7a5b0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,9 @@ public int hashCode()
if (hash == 0) {
hash = Objects.hash(type, Arrays.hashCode(inclusive));
for (int position = 0; position < sortedRanges.getPositionCount(); position++) {
if (sortedRanges.isNull(position)) {
hash = hash * 31;
boolean positionIsNull = sortedRanges.isNull(position);
hash = hash * 31 + Boolean.hashCode(positionIsNull);
if (positionIsNull) {
continue;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,13 @@ public void testExpandRangesForDenseType()
}
}

@Test
public void testRangeSetHashcode()
{
assertThat(ValueSet.ofRanges(Range.lessThan(INTEGER, 0L)).hashCode()).isNotEqualTo(ValueSet.ofRanges(Range.greaterThan(INTEGER, 0L)).hashCode());
assertThat(ValueSet.ofRanges(Range.lessThan(INTEGER, 1L)).hashCode()).isNotEqualTo(ValueSet.ofRanges(Range.range(INTEGER, 0L, false, 1L, false)).hashCode());
}

private void assertUnion(SortedRangeSet first, SortedRangeSet second, SortedRangeSet expected)
{
assertThat(first.union(second)).isEqualTo(expected);
Expand Down

0 comments on commit e7a5b0d

Please sign in to comment.