Skip to content

Commit

Permalink
Fix incorrect result when an empty bitset intersects with itself
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangt2333 committed Sep 21, 2024
1 parent b503389 commit 7411dda
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/pascal/taie/util/collection/RegularBitSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ public int previousClearBit(int fromIndex) {

@Override
public boolean intersects(IBitSet set) {
if (this.isEmpty() || set.isEmpty()) {
return false;
}
if (this == set) {
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/pascal/taie/util/collection/SparseBitSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ public int previousClearBit(int fromIndex) {

@Override
public boolean intersects(IBitSet set) {
if (this.isEmpty() || set.isEmpty()) {
return false;
}
if (this == set) {
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/pascal/taie/util/collection/IBitSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ void testClear() {
@Test
void testIntersects() {
IBitSet s1 = of();
assertFalse(s1.intersects(s1));
IBitSet s2 = of();
assertFalse(s1.intersects(s2));
assertFalse(s2.intersects(s1));
s2 = of(1, 233, 666);
assertFalse(s1.intersects(s2));
assertFalse(s2.intersects(s1));
Expand All @@ -83,6 +85,7 @@ void testIntersects() {
assertTrue(s2.intersects(s1));
s1.clear(666);
assertFalse(s1.intersects(s2));
assertFalse(s2.intersects(s1));
}

@Test
Expand Down

0 comments on commit 7411dda

Please sign in to comment.