/** * {@inheritDoc} */ public Key subtract(Key otherKey) { /* * 0 - 0 => 0 * 0 - 1 => 0 * 1 - 0 => 1 * 1 - 1 => 0 * a and !b */ BitSetKey other = (BitSetKey) otherKey; int len = Math.max(bits.length, other.bits.length); long[] newBits = new long[len]; int numBits = 0; for (int i = 0; i < len; i++) { long w1 = i < bits.length ? bits[i] : 0; long w2 = i < other.bits.length ? other.bits[i] : 0; newBits[i] = w1 & ~w2; numBits += bitCount(newBits[i]); } return new BitSetKey(newBits, numBits); }
/** * {@inheritDoc} */ public String toString() { StringBuilder buf = new StringBuilder("w="); buf.append(names.length); int i = nextSetBit(0); while (i >= 0) { buf.append(", ").append(i).append("="); buf.append(BitSetENTCacheImpl.this.getName(i)); i = nextSetBit(i + 1); } return buf.toString(); }
/** * {@inheritDoc} */ public Key subtract(Key otherKey) { /* * 0 - 0 => 0 * 0 - 1 => 0 * 1 - 0 => 1 * 1 - 1 => 0 * a and !b */ BitSetKey other = (BitSetKey) otherKey; int len = Math.max(bits.length, other.bits.length); long[] newBits = new long[len]; int numBits = 0; for (int i = 0; i < len; i++) { long w1 = i < bits.length ? bits[i] : 0; long w2 = i < other.bits.length ? other.bits[i] : 0; newBits[i] = w1 & ~w2; numBits += bitCount(newBits[i]); } return new BitSetKey(newBits, numBits); }
/** * Creates a new bit set key. * @param bits the array of bits * @param numBits the number of bits that are '1' in the given bits */ private BitSetKey(long[] bits, int numBits) { this.bits = bits; names = new Name[numBits]; int i = nextSetBit(0); int j = 0; while (i >= 0) { names[j++] = BitSetENTCacheImpl.this.getName(i); i = nextSetBit(i + 1); } hashCode = calcHashCode(); }
/** * Creates a new bit set key. * @param names the node type names * @param maxBit the approximative number of the greatest bit */ public BitSetKey(Name[] names, int maxBit) { this.names = names; bits = new long[maxBit / BPW + 1]; for (int i = 0; i < names.length; i++) { int n = getBitNumber(names[i]); bits[n / BPW] |= OR_MASK[n % BPW]; } hashCode = calcHashCode(); }
/** * Creates a new bit set key. * @param bits the array of bits * @param numBits the number of bits that are '1' in the given bits */ private BitSetKey(long[] bits, int numBits) { this.bits = bits; names = new Name[numBits]; int i = nextSetBit(0); int j = 0; while (i >= 0) { names[j++] = BitSetENTCacheImpl.this.getName(i); i = nextSetBit(i + 1); } hashCode = calcHashCode(); }
/** * Creates a new bit set key. * @param names the node type names * @param maxBit the approximative number of the greatest bit */ public BitSetKey(Name[] names, int maxBit) { this.names = names; bits = new long[maxBit / BPW + 1]; for (int i = 0; i < names.length; i++) { int n = getBitNumber(names[i]); bits[n / BPW] |= OR_MASK[n % BPW]; } hashCode = calcHashCode(); }
/** * {@inheritDoc} */ public String toString() { StringBuilder buf = new StringBuilder("w="); buf.append(names.length); int i = nextSetBit(0); while (i >= 0) { buf.append(", ").append(i).append("="); buf.append(BitSetENTCacheImpl.this.getName(i)); i = nextSetBit(i + 1); } return buf.toString(); }
/** * {@inheritDoc} */ public Key getKey(Name[] ntNames) { return new BitSetKey(ntNames, nameIndex.size() + ntNames.length); }
/** * {@inheritDoc} */ public Key getKey(Name[] ntNames) { return new BitSetKey(ntNames, nameIndex.size() + ntNames.length); }