We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I think there's a tricky "bug" here which can catch out the unwary, particularly those that didn't know about BitSet.cardinality().
The bit addresses for SET and FLIP : are they 0 based or 1 based ?
The 7th operation on TestCase 2 is SET 1 0, which implies it's 0 based.
The 4840th operation on TestCase 6 - with a BitSet size of 523 - is FLIP 2 523, which implies it's 1 based.
The BitSet automatically grows to a nice size for storage : so new BitSet(523) actually gives you a BitSet of 576 bits long - which means it works with either 0 based or 1 based, and you can set or flip bits at higher addresses than you should really be able to.
I initially didn't know about BitSet.cardinality(), so was manually counting the bits in the original range : which meant I looped over 0 -> 522 and so didn't picked up the flipped bit in test set 6.
Can I suggest the datasets be reviewed, so they are consistently 0 based ? In which case Test Case 6 (at least) is invalid ?
Java BitSet
You are viewing a single comment's thread. Return to all comments →
I think there's a tricky "bug" here which can catch out the unwary, particularly those that didn't know about BitSet.cardinality().
The bit addresses for SET and FLIP : are they 0 based or 1 based ?
The 7th operation on TestCase 2 is SET 1 0, which implies it's 0 based. The 4840th operation on TestCase 6 - with a BitSet size of 523 - is FLIP 2 523, which implies it's 1 based.
The BitSet automatically grows to a nice size for storage : so new BitSet(523) actually gives you a BitSet of 576 bits long - which means it works with either 0 based or 1 based, and you can set or flip bits at higher addresses than you should really be able to.
I initially didn't know about BitSet.cardinality(), so was manually counting the bits in the original range : which meant I looped over 0 -> 522 and so didn't picked up the flipped bit in test set 6.
Can I suggest the datasets be reviewed, so they are consistently 0 based ? In which case Test Case 6 (at least) is invalid ?