Is there any particular reason why these are missing?
They do exist in BigInteger
, but due to the immutable design pattern of BigInteger
these are usually awfully slow. BitSet
is much nicer because it is mutable, but I really miss the shift
functions (<<
and >>>
for long
s). For BitSet
, an inplace shifting would also be useful, as well as cyclic rotation.
I have seen the reply to Shifting a Java BitSet (using get(off, len)
for shifting; however this requires copying).
Don't get me wrong. I know where to report bugs. I'm just wondering if there was a particular reason to omit them, e.g. some design pattern or such a concept. In particular as they are included in BigInteger
.
The BitSet class creates a special type of array that holds bit values. The BitSet array can increase in size as needed. This makes it similar to a vector of bits. This is a legacy class but it has been completely re-engineered in Java 2, version 1.4.
Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through nbits-1 . All bits are initially false .
Conceptually, a BitSet
is typically / often used for tracking a lot of settings, such that each bit in the set has a specific meaning. So a shift operation makes little sense in that context.
You've clearly found another useful purpose for a BitSet
, but it's outside the scope for which BitSet
was probably envisioned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With