/** * Ensures that the bit set has the capacity to represent the given value. * * @param value {@code >= 0;} value to represent */ private void ensureCapacity(int value) { if (value >= Bits.getMax(bits)) { int[] newBits = Bits.makeBitSet(Math.max(value + 1, 2 * Bits.getMax(bits))); System.arraycopy(bits, 0, newBits, 0, bits.length); bits = newBits; } }
/** @inheritDoc */ public void merge(IntSet other) { if (other instanceof BitIntSet) { BitIntSet o = (BitIntSet) other; ensureCapacity(Bits.getMax(o.bits) + 1); Bits.or(bits, o.bits); } else if (other instanceof ListIntSet) { ListIntSet o = (ListIntSet) other; int sz = o.ints.size(); if (sz > 0) { ensureCapacity(o.ints.get(sz - 1)); } for (int i = 0; i < o.ints.size(); i++) { Bits.set(bits, o.ints.get(i), true); } } else { IntIterator iter = other.iterator(); while (iter.hasNext()) { add(iter.next()); } } }
/** @inheritDoc */ public boolean has(int value) { return (value < Bits.getMax(bits)) && Bits.get(bits, value); }
/** @inheritDoc */ public void remove(int value) { if (value < Bits.getMax(bits)) { Bits.set(bits, value, false); } }