MCPcopy Create free account
hub / github.com/Youlor/unpacker / BitIntSet

Class BitIntSet

dexfixer/src/com/android/dx/util/BitIntSet.java:24–154  ·  view source on GitHub ↗

A set of integers, represented by a bit set

Source from the content-addressed store, hash-verified

22 * A set of integers, represented by a bit set
23 */
24public class BitIntSet implements IntSet {
25
26 /** also accessed in ListIntSet */
27 int[] bits;
28
29 /**
30 * Constructs an instance.
31 *
32 * @param max the maximum value of ints in this set.
33 */
34 public BitIntSet(int max) {
35 bits = Bits.makeBitSet(max);
36 }
37
38 /** {@inheritDoc} */
39 @Override
40 public void add(int value) {
41 ensureCapacity(value);
42 Bits.set(bits, value, true);
43 }
44
45 /**
46 * Ensures that the bit set has the capacity to represent the given value.
47 *
48 * @param value {@code >= 0;} value to represent
49 */
50 private void ensureCapacity(int value) {
51 if (value >= Bits.getMax(bits)) {
52 int[] newBits = Bits.makeBitSet(
53 Math.max(value + 1, 2 * Bits.getMax(bits)));
54 System.arraycopy(bits, 0, newBits, 0, bits.length);
55 bits = newBits;
56 }
57 }
58
59 /** {@inheritDoc} */
60 @Override
61 public void remove(int value) {
62 if (value < Bits.getMax(bits)) {
63 Bits.set(bits, value, false);
64 }
65 }
66
67 /** {@inheritDoc} */
68 @Override
69 public boolean has(int value) {
70 return (value < Bits.getMax(bits)) && Bits.get(bits, value);
71 }
72
73 /** {@inheritDoc} */
74 @Override
75 public void merge(IntSet other) {
76 if (other instanceof BitIntSet) {
77 BitIntSet o = (BitIntSet) other;
78 ensureCapacity(Bits.getMax(o.bits) + 1);
79 Bits.or(bits, o.bits);
80 } else if (other instanceof ListIntSet) {
81 ListIntSet o = (ListIntSet) other;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected