/** * Creates a new <code>BitVectorDto</code> object that posesses the same characteristics as a * given <code>BitVector</code>. * * @param id the internal id to give to this BitVectorDto object. * @param v the <code>BitVector</code> from which data will be obtained. * @return a <code>BitVectorDto</code> based on the information (size, bits) found in the <code> * BitVector</code> <b>v</b>. */ public static BitVectorDto toDto(long id, BitVector v) { BitVectorDto d = new BitVectorDto(); d.setId(id); d.setSize(v.size()); d.setBits(v.getBits()); return d; }
/** * Multiplies the column {@link BitVector} by a <TT>BitMatrix</TT> and returns the result. The * result is <SPAN CLASS="MATH"><I>A</I>×<I>v</I></SPAN>, where <SPAN * CLASS="MATH"><I>A</I></SPAN> is the <TT>BitMatrix</TT>, and <SPAN CLASS="MATH"><I>v</I></SPAN> * is the {@link BitVector}. * * @param vect the vector to multiply * @return the result of the multiplication */ public BitVector multiply(BitVector vect) { BitVector res = new BitVector(r); for (int i = 0; i < r; i++) res.setBool(i, rows[i].scalarProduct(vect)); return res; }
@Test public void testGetBoolean() { final TransformationStrategy<Long> fixedLong = TransformationStrategies.fixedLong(); BitVector p = fixedLong.toBitVector(Long.valueOf(0)); for (int i = Long.SIZE; i-- != 0; ) assertFalse(p.getBoolean(i)); p = fixedLong.toBitVector(Long.valueOf(0xDEADBEEFDEADF00DL)); for (int i = Long.SIZE; i-- != 0; ) assertTrue(p.getBoolean(i) == ((0xDEADBEEFDEADF00DL & 1L << Long.SIZE - 1 - i) != 0)); }
@Test public void testGetLong() { final TransformationStrategy<Long> fixedLong = TransformationStrategies.fixedLong(); BitVector p = fixedLong.toBitVector(Long.valueOf(Long.reverse(0xDEADBEEFDEADF00DL))); for (int from = Long.SIZE; from-- != 0; ) for (int to = Long.SIZE; from < to--; ) assertTrue( p.getLong(from, to) == LongArrayBitVector.wrap(new long[] {0xDEADBEEFDEADF00DL}).getLong(from, to)); }
/** Asserts that the two HLLs are register-wise equal. */ private static void assertElementsEqual(final HLL hllA, final HLL hllB) { final BitVector bitVectorA = hllA.probabilisticStorage; final BitVector bitVectorB = hllB.probabilisticStorage; final LongIterator iterA = bitVectorA.registerIterator(); final LongIterator iterB = bitVectorB.registerIterator(); for (; iterA.hasNext() && iterB.hasNext(); ) { assertEquals(iterA.next(), iterB.next()); } assertFalse(iterA.hasNext()); assertFalse(iterB.hasNext()); }
private void dfsg_visit(TypeVariableBV var) { BitVector parents = var.parents(); for (BitSetIterator i = parents.iterator(); i.hasNext(); ) { TypeVariableBV parent = resolver.typeVariableForId(i.next()); if (!black.contains(parent)) { black.add(parent); dfsg_visit(parent); } } finished.add(0, var); }
private void dfsgt_visit(TypeVariableBV var) { current_tree.add(var); BitVector children = var.children(); for (BitSetIterator i = children.iterator(); i.hasNext(); ) { TypeVariableBV child = resolver.typeVariableForId(i.next()); if (!black.contains(child)) { black.add(child); dfsgt_visit(child); } } }
/** * Remove an object from this bit set. * * @param o the object to remove */ public void clear(T o) { int n = map.getMappedIndex(o); if (n == -1) { return; } vector.clear(n); }
/** Does this set contain a certain object? */ public boolean contains(T o) { int n = map.getMappedIndex(o); if (n == -1) { return false; } return vector.get(n); }
/** * Method copy. Copies the bits in the bit vector, but only assigns the object map. No need to * create a new object/bit bijection object. * * @throws IllegalArgumentException if other is null */ public void copyBits(BitSet<T> other) { if (other == null) { throw new IllegalArgumentException("other is null"); } vector.copyBits(other.vector); map = other.map; }
public StronglyConnectedComponentsBV(BitVector typeVariableList, TypeResolverBV resolver) throws TypeException { this.resolver = resolver; variables = typeVariableList; black = new TreeSet(); finished = new LinkedList(); for (BitSetIterator i = variables.iterator(); i.hasNext(); ) { TypeVariableBV var = resolver.typeVariableForId(i.next()); if (!black.contains(var)) { black.add(var); dfsg_visit(var); } } black = new TreeSet(); for (Iterator i = finished.iterator(); i.hasNext(); ) { TypeVariableBV var = (TypeVariableBV) i.next(); if (!black.contains(var)) { current_tree = new LinkedList(); forest.add(current_tree); black.add(var); dfsgt_visit(var); } } for (Iterator i = forest.iterator(); i.hasNext(); ) { LinkedList list = (LinkedList) i.next(); TypeVariableBV previous = null; StringBuffer s = null; if (DEBUG) { s = new StringBuffer("scc:\n"); } for (Iterator j = list.iterator(); j.hasNext(); ) { TypeVariableBV current = (TypeVariableBV) j.next(); if (DEBUG) { s.append(" " + current + "\n"); } if (previous == null) { previous = current; } else { try { previous = previous.union(current); } catch (TypeException e) { if (DEBUG) { G.v().out.println(s); } throw e; } } } } }
public static BitVector toBitVector(IntBag bag, BitVector out) { int[] data = bag.getData(); for (int i = 0, s = bag.size(); s > i; i++) { out.set(data[i]); } return out; }
/** Tests {@link HLL#clear()}. */ @Test public void clearTest() { final int regwidth = 5; final int log2m = 4 /*16 registers per counter*/; final int m = 1 << log2m; final HLL hll = new HLL( log2m, regwidth, 128 /*explicitThreshold, arbitrary, unused*/, 256 /*sparseThreshold, arbitrary, unused*/, HLLType.FULL); final BitVector bitVector = hll.probabilisticStorage; for (int i = 0; i < m; i++) bitVector.setRegister(i, i); hll.clear(); for (int i = 0; i < m; i++) { assertEquals(bitVector.getRegister(i), 0L /*default value of register*/); } }
/** * Shift data in chain.inBits into the selected scan chain on the chip. The previous data on the * chip is shifted out into chain.outBits. Should only be called by ChainNode. * * @param chain Root scan chain to shift data into * @param readEnable whether to set opcode's read-enable bit * @param writeEnable whether to set opcode's write-enable bit * @param irBadSeverity action when bits scanned out of IR are wrong * @see ChainNode * @see Infrastructure#SEVERITY_NOMESSAGE * @see Infrastructure#SEVERITY_WARNING * @see Infrastructure#SEVERITY_NONFATAL * @see Infrastructure#SEVERITY_FATAL */ void shift(ChainNode chain, boolean readEnable, boolean writeEnable, int irBadSeverity) { logOther("MockJTAG shift: opcode=" + chain.getOpcode() + "\n " + chain.getInBits()); int length = chain.getLength(); BitVector outBits = new BitVector(length, "MockJtag.shift().outBits"); BitVector outBitsExpected = chain.getOutBitsExpected(); for (int ibit = 0; ibit < length; ibit++) { if (outBitsExpected.isValid(ibit) == true) { /* need to handle shadowState carefully - for scanBB */ if (!writeEnable) { outBits.set(ibit, outBitsExpected.get(ibit)); } else { outBits.putIndiscriminate(ibit, chain.getShadowState().getIndiscriminate(ibit, 1)); } } else { outBits.clear(ibit); } } chain.getOutBits().putIndiscriminate(0, outBits); }
/** Tests the bounds on a register's value for a given raw input value. */ @Test public void registerValueTest() { final int log2m = 4 /*small enough to make testing easy (addRaw() shifts by one byte)*/; // register width 4 (the minimum size) { // scoped locally for sanity final int regwidth = 4; final HLL hll = new HLL( log2m, regwidth, 128 /*explicitThreshold, arbitrary, unused*/, 256 /*sparseThreshold, arbitrary, unused*/, HLLType.FULL); final BitVector bitVector = hll.probabilisticStorage; // lower-bounds of the register hll.addRaw(0x000000000000001L /*'j'=1*/); assertEquals(bitVector.getRegister(1 /*'j'*/), 0); hll.addRaw(0x0000000000000012L /*'j'=2*/); assertEquals(bitVector.getRegister(2 /*'j'*/), 1); hll.addRaw(0x0000000000000023L /*'j'=3*/); assertEquals(bitVector.getRegister(3 /*'j'*/), 2); hll.addRaw(0x0000000000000044L /*'j'=4*/); assertEquals(bitVector.getRegister(4 /*'j'*/), 3); hll.addRaw(0x0000000000000085L /*'j'=5*/); assertEquals(bitVector.getRegister(5 /*'j'*/), 4); // upper-bounds of the register // NOTE: bear in mind that BitVector itself does ensure that // overflow of a register is prevented hll.addRaw(0x0000000000010006L /*'j'=6*/); assertEquals(bitVector.getRegister(6 /*'j'*/), 13); hll.addRaw(0x0000000000020007L /*'j'=7*/); assertEquals(bitVector.getRegister(7 /*'j'*/), 14); hll.addRaw(0x0000000000040008L /*'j'=8*/); assertEquals(bitVector.getRegister(8 /*'j'*/), 15); hll.addRaw(0x0000000000080009L /*'j'=9*/); assertEquals(bitVector.getRegister(9 /*'j'*/), 15 /*overflow*/); // sanity checks to ensure that no other bits above the lowest-set // bit matters // NOTE: same as case 'j = 6' above hll.addRaw(0x000000000003000AL /*'j'=10*/); assertEquals(bitVector.getRegister(10 /*'j'*/), 13); hll.addRaw(0x000000000011000BL /*'j'=11*/); assertEquals(bitVector.getRegister(11 /*'j'*/), 13); } // register width 5 { // scoped locally for sanity final int regwidth = 5; final HLL hll = new HLL( log2m, regwidth, 128 /*explicitThreshold, arbitrary, unused*/, 256 /*sparseThreshold, arbitrary, unused*/, HLLType.FULL); final BitVector bitVector = hll.probabilisticStorage; // lower-bounds of the register hll.addRaw(0x0000000000000001L /*'j'=1*/); assertEquals(bitVector.getRegister(1 /*'j'*/), 0); hll.addRaw(0x0000000000000012L /*'j'=2*/); assertEquals(bitVector.getRegister(2 /*'j'*/), 1); hll.addRaw(0x0000000000000023L /*'j'=3*/); assertEquals(bitVector.getRegister(3 /*'j'*/), 2); hll.addRaw(0x0000000000000044L /*'j'=4*/); assertEquals(bitVector.getRegister(4 /*'j'*/), 3); hll.addRaw(0x0000000000000085L /*'j'=5*/); assertEquals(bitVector.getRegister(5 /*'j'*/), 4); // upper-bounds of the register // NOTE: bear in mind that BitVector itself does ensure that // overflow of a register is prevented hll.addRaw(0x0000000100000006L /*'j'=6*/); assertEquals(bitVector.getRegister(6 /*'j'*/), 29); hll.addRaw(0x0000000200000007L /*'j'=7*/); assertEquals(bitVector.getRegister(7 /*'j'*/), 30); hll.addRaw(0x0000000400000008L /*'j'=8*/); assertEquals(bitVector.getRegister(8 /*'j'*/), 31); hll.addRaw(0x0000000800000009L /*'j'=9*/); assertEquals(bitVector.getRegister(9 /*'j'*/), 31 /*overflow*/); } }
/** @return a String representation */ @Override public String toString() { return vector.toString(); }
/** Add an object to this bit set. */ public void add(T o) { int n = map.getMappedIndex(o); vector.set(n); }
/** * Does this object hold the same bits as other? * * @throws IllegalArgumentException if other is null */ public boolean sameBits(BitSet<?> other) { if (other == null) { throw new IllegalArgumentException("other is null"); } return vector.equals(other.vector); }
public static IntBag toIntBag(BitVector bs, IntBag out) { return bs.toIntBag(out); }
/** Set all the bits to 1. */ public void setAll() { vector.setAll(); }
/** Set all the bits to 0. */ public void clearAll() { vector.clearAll(); }
public int length() { return vector.length(); }
public int size() { return vector.populationCount(); }
/** * Perform the difference of two bit sets * * @param other the other bitset in the operation * @throws IllegalArgumentException if other is null */ public void difference(BitSet<T> other) { if (other == null) { throw new IllegalArgumentException("other is null"); } vector.and(BitVector.not(other.vector)); }
/** Add all bits in BitVector B to this bit set */ public void addAll(BitVector B) { vector.or(B); }
/** * Perform intersection of two bitsets * * @param other the other bitset in the operation * @throws IllegalArgumentException if other is null */ public void intersect(BitSet<?> other) { if (other == null) { throw new IllegalArgumentException("other is null"); } vector.and(other.vector); }
/** * Add all elements in bitset B to this bit set * * @throws IllegalArgumentException if B is null */ public void addAll(BitSet<?> B) { if (B == null) { throw new IllegalArgumentException("B is null"); } vector.or(B.vector); }