/** this = this XOR other */ public void xor(FixedBitSet other) { xor(other.bits, other.numWords); }
/** Does in-place XOR of the bits provided by the iterator. */ public void xor(DocIdSetIterator iter) throws IOException { checkUnpositioned(iter); if (BitSetIterator.getFixedBitSetOrNull(iter) != null) { final FixedBitSet bits = BitSetIterator.getFixedBitSetOrNull(iter); xor(bits); } else { int doc; while ((doc = iter.nextDoc()) < numBits) { flip(doc); } } }
/** this = this XOR other */ public void xor(FixedBitSet other) { xor(other.bits, other.numWords); }
/** this = this XOR other */ public void xor(FixedBitSet other) { xor(other.bits, other.numWords); }
/** this = this XOR other */ public void xor(FixedBitSet other) { xor(other.bits, other.numWords); }
@Override /** * Implements binding using exclusive OR. */ public void bind(Vector other) { IncompatibleVectorsException.checkVectorsCompatible(this, other); if (!BINARY_BINDING_WITH_PERMUTE) { BinaryVector binaryOther = (BinaryVector) other; this.bitSet.xor(binaryOther.bitSet); } else { bind(other, 1); } }
/** * Returns the highest value shared by all dimensions. */ protected synchronized int getMaximumSharedWeight() { int thismaximum = 0; tempSet.xor(tempSet); // Reset tempset to zeros. for (int x = votingRecord.size() - 1; x >= 0; x--) { tempSet.or(votingRecord.get(x)); if (tempSet.cardinality() == dimension) { thismaximum += (int) Math.pow(2, x); tempSet.xor(tempSet); } } return thismaximum; }
public synchronized void selectedDecrement(int floor) { tempSet.set(0, dimension); for (int q = floor; q < votingRecord.size(); q++) { votingRecord.get(q).xor(tempSet); tempSet.and(votingRecord.get(q)); } }
/** * Decrement every dimension. Assumes at least one count in each dimension * i.e: no underflow check currently - will wreak havoc with zero counts */ public synchronized void decrement() { tempSet.set(0, dimension); for (int q = 0; q < votingRecord.size(); q++) { votingRecord.get(q).xor(tempSet); tempSet.and(votingRecord.get(q)); } }
/** * Sets {@link #tempSet} to be a bitset with a "1" in the position of every dimension * in the {@link #votingRecord} that exactly matches the target number. */ private synchronized void setTempSetToExactMatches(int target) { if (target == 0) { tempSet.set(0, dimension); tempSet.xor(votingRecord.get(0)); for (int x = 1; x < votingRecord.size(); x++) tempSet.andNot(votingRecord.get(x)); } else { String inbinary = reverse(Integer.toBinaryString(target)); tempSet.xor(tempSet); try { tempSet.xor(votingRecord.get(inbinary.indexOf("1"))); //this requires error checking, it is throwing an index out of bounds exception } catch (Exception e) { e.printStackTrace(); } for (int q =0; q < votingRecord.size(); q++) { if (q < inbinary.length() && inbinary.charAt(q) == '1') tempSet.and(votingRecord.get(q)); else tempSet.andNot(votingRecord.get(q)); } } }
/** * Implements binding using permutations and XOR. */ public void bind(Vector other, int direction) { IncompatibleVectorsException.checkVectorsCompatible(this, other); BinaryVector binaryOther = (BinaryVector) other.copy(); if (direction > 0) { //as per Kanerva 2009: bind(A,B) = perm+(A) XOR B = C //this also functions as the left inverse: left inverse (A,C) = perm+(A) XOR C = B this.permute(PermutationUtils.getShiftPermutation(VectorType.BINARY, dimension, 1)); //perm+(A) this.bitSet.xor(binaryOther.bitSet); //perm+(A) XOR B } else { //as per Kanerva 2009: right inverse(C,B) = perm-(C XOR B) = perm-(perm+(A)) = A this.bitSet.xor(binaryOther.bitSet); //C XOR B this.permute(PermutationUtils.getShiftPermutation(VectorType.BINARY, dimension, -1)); //perm-(C XOR B) = A } }
this.bitSet.xor(this.bitSet);
/** Does in-place XOR of the bits provided by the iterator. */ public void xor(DocIdSetIterator iter) throws IOException { checkUnpositioned(iter); if (BitSetIterator.getFixedBitSetOrNull(iter) != null) { final FixedBitSet bits = BitSetIterator.getFixedBitSetOrNull(iter); xor(bits); } else { int doc; while ((doc = iter.nextDoc()) < numBits) { flip(doc); } } }
/** Does in-place XOR of the bits provided by the iterator. */ public void xor(DocIdSetIterator iter) throws IOException { assertUnpositioned(iter); if (BitSetIterator.getFixedBitSetOrNull(iter) != null) { final FixedBitSet bits = BitSetIterator.getFixedBitSetOrNull(iter); xor(bits); } else { int doc; while ((doc = iter.nextDoc()) < numBits) { flip(doc); } } }
/** Does in-place XOR of the bits provided by the iterator. */ public void xor(DocIdSetIterator iter) throws IOException { assertUnpositioned(iter); if (BitSetIterator.getFixedBitSetOrNull(iter) != null) { final FixedBitSet bits = BitSetIterator.getFixedBitSetOrNull(iter); xor(bits); } else { int doc; while ((doc = iter.nextDoc()) < numBits) { flip(doc); } } }
FixedBitSet commonGround = (FixedBitSet) vector.clone(); commonGround.xor(subvector);
/** * An attempt at modeling the intersection between two binary vectors, by randomizing the * dimensions that are not common */ public static BinaryVector intersection(BinaryVector vector, BinaryVector vector2) { FixedBitSet intersection = (FixedBitSet) vector.getCoordinates().clone(); FixedBitSet uncommonGround = (FixedBitSet) vector.getCoordinates().clone(); java.util.Random random = new java.util.Random(); random.setSeed((long) 23); //for consistency across experiments //everything different uncommonGround.xor(vector2.getCoordinates()); //to introduce random noise for (int x =0; x < vector.getDimension(); x++) { // if (x == 0) System.err.print(cnt+"/"+ numchanges+".."+"loop..."); double change = random.nextDouble(); if (uncommonGround.get(x) && change > 0.5) { intersection.flip(x); } } BinaryVector intersectionVector = (BinaryVector) VectorFactory.createZeroVector(VectorType.BINARY, vector.getDimension()); intersectionVector.setCoordinates(intersection); return intersectionVector; }