Java BitSet which allows easy Concatenation of BitSets

bitset, concatenation, java

Solution

Well there's no way to implement this terribly efficient (performance and memory that is) since there's no leftshift method.

What you can do is either use the obvious `nextSetBit` for loop - slow, but memory efficient.

The presumably faster method would be to use `toLongArray` on one, copy that correctly shifted into a large enough array, create a bitset from that and or it with the other. That way you don't do any bitshifting on single bits but instead work on wordsized chunks.

Problem

I have a need for a BitSet which allows easy concatenation of multiple BitSets create a new BitSet. The default implementation doesn't have such a method. Is there any an implementation in some external library that any of you know which allows easy concatenation? For example lets say I have a bitarray 11111 and another bit array 010101. I want functionality like appending. So after concatenating it would result in 11111010101.

Original source