BitSet Range Flip And Intersects Checks
Toggle half-open slot ranges in BitSet with set(from, to), flip(from, to), and clear(from, to), then test schedule overlap via intersects.
Code
import java.util.BitSet;
public class SlotBitmapRanges {
public static void main(String[] args) {
BitSet shiftA = new BitSet();
// Half-open [from, to): sets bits 2, 3, 4, 5
shiftA.set(2, 6);
BitSet shiftB = new BitSet();
shiftB.set(5, 9); // overlaps shiftA at slot 5
System.out.println("shiftA=" + shiftA + " intersects B=" + shiftA.intersects(shiftB));
// flip(from, to) toggles [4, 7): turns off 4,5 and turns on 6
shiftA.flip(4, 7);
System.out.println("after flip(4,7)=" + shiftA + " intersects B=" + shiftA.intersects(shiftB));
// clear(from, to) vacates [6, 8); length() is highestSetBit + 1
shiftA.clear(6, 8);
System.out.println("after clear(6,8)=" + shiftA
+ " cardinality=" + shiftA.cardinality()
+ " length=" + shiftA.length());
}
}Inside the implementation — BitSet Range Flip And Intersects Checks
The code’s whole job belongs to the class SlotBitmapRanges and the function main.
Watch out for
- All referenced identifiers come natively from the core runtime with nothing fetched.
Using it
Signature: public static void main(String[] args)
The demo output is labeled (shiftA=, after flip(4,7)=, after clear(6,8)=); each label names the call that printed it.
Key statements
shiftB.set(5, 9); // overlaps shiftA at slot 5
System.out.println("shiftA=" + shiftA + " intersects B=" + shiftA.intersects(shiftB));
+ " cardinality=" + shiftA.cardinality()
+ " length=" + shiftA.length());
BitSet shiftA = new BitSet();
Interactive Tools for This Topic
SemVer Range CheckerCheck whether a semantic version satisfies an npm-style range such as caret, tilde, comparison sets, wildcards, or hyphen ranges.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
FAQ
- What does BitSet Range Flip And Intersects Checks print when run?
- Run it as a complete program — the output lines carry labels such as `shiftA=`, `after flip(4,7)=`, `after clear(6,8)=`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.