MCPcopy Create free account
hub / github.com/LFYSec/MScan / RegularBitSet

Class RegularBitSet

src/main/java/pascal/taie/util/collection/RegularBitSet.java:33–681  ·  view source on GitHub ↗

Regular bit set implementation. This implementation is very similar to java.util.Set which uses a long[] to store all the set bits.

Source from the content-addressed store, hash-verified

31 * a {@code long[]} to store all the set bits.
32 */
33public class RegularBitSet extends AbstractBitSet
34 implements Serializable {
35
36 /* Used to shift left or right for a partial word mask */
37 private static final long WORD_MASK = 0xffffffffffffffffL;
38
39 /**
40 * The internal field corresponding to the serialField "bits".
41 */
42 private long[] words;
43
44 /**
45 * The number of words in the logical size of this BitSet.
46 */
47 private int wordsInUse = 0;
48
49 /**
50 * Creates a new bit set. All bits are initially {@code false}.
51 */
52 public RegularBitSet() {
53 initWords(BITS_PER_WORD);
54 }
55
56 /**
57 * Creates a bit set whose initial size is large enough to explicitly
58 * represent bits with indices in the range {@code 0} through
59 * {@code nbits-1}. All bits are initially {@code false}.
60 *
61 * @param nbits the initial size of the bit set
62 * @throws NegativeArraySizeException if the specified initial size
63 * is negative
64 */
65 public RegularBitSet(int nbits) {
66 // nbits can't be negative; size 0 is OK
67 if (nbits < 0) {
68 throw new NegativeArraySizeException("nbits < 0: " + nbits);
69 }
70
71 initWords(nbits);
72 }
73
74 private void initWords(int nbits) {
75 words = new long[wordIndex(nbits - 1) + 1];
76 }
77
78 /**
79 * Every public method must preserve these invariants.
80 */
81 private void checkInvariants() {
82 assert (wordsInUse == 0 || words[wordsInUse - 1] != 0);
83 assert (wordsInUse >= 0 && wordsInUse <= words.length);
84 assert (wordsInUse == words.length || words[wordsInUse] == 0);
85 }
86
87 /**
88 * Sets the field wordsInUse to the logical size in words of the bit set.
89 * WARNING:This method assumes that the number of words actually in use is
90 * less than or equal to the current value of wordsInUse!

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected