Domanda

Is there something faster in time than this:

// say we alread have BitSet bs1 and bs2
BitSet bs3 = (BitSet) bs1.clone();
bs3.and(bs2);

Maybe convert to ints and add as numbers and then convert back to BitSet?

È stato utile?

Soluzione

The only alternative I can think of is

Bitset newBitset = new Bitset(bs1.size());
newBitset.or(bs1).and(bs2);

You'll need to time the two to see which is faster; my alternative may be slightly faster since you're not calling an overriding method and you're not doing any casting.

Altri suggerimenti

If you really need the speed, I would guess that practically nothing BitSet does will be nearly as fast as bitwise operations on integers -- &, |, etc. Of course, you don't have a number of operations on bit-wise-handled integers that you do in BitSet objects; you give that up when you decide to go to maximum speed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top