How to add a bit at the beginning of a BitSet buffer?

I use the BitSet buffer, where I have about 500 bits inside, and I want to add about 10 bits at the beginning of the buffer, I mean index 0, so the rest of the buffer should be shifted, but I don’t see a way to β€œadd” a bit of methods records, so if I already have a bit, it will be replaced, will not be added. Is there a way to do this, or do I need to copy everything to a temporary BitSet, add my 10 bits, and then add 500 bits?

Thanks:)

PD: Sorry, my bad Englishman also has no right to correct :)

+4
source share
1 answer

Cannot insert bits in front without copying.

Perhaps you could reorder the bits in a BitSet ? If you did this, it would mean that you are now adding bits to the end of the set, which can be done cheaply.

Alternatively, you can encapsulate Deque from BitSet s. Then inserting bits on the front panel can be done by inserting a new BitSet at the beginning of Deque .

+4
source

Source: https://habr.com/ru/post/1414014/


All Articles