List of usage examples for java.util BitSet and
public void and(BitSet set)
From source file:BitOps.java
public static void main(String args[]) { BitSet set = new BitSet(); set.set(1);/*from www. ja va2 s. c om*/ set.set(2); set.set(3); set.set(4); set.set(5); System.out.println(set); BitSet set2 = new BitSet(); set2.set(1); set2.set(3); set2.set(5); set2.set(7); BitSet set3 = (BitSet) set.clone(); set3.and(set2); System.out.println(set3); set3 = (BitSet) set.clone(); set3.or(set2); System.out.println(set3); set3 = (BitSet) set.clone(); set3.xor(set2); System.out.println(set3); set3 = (BitSet) set.clone(); set3.andNot(set2); System.out.println(set3); set3.andNot(null); }
From source file:MainClass.java
public static void main(String args[]) { BitSet bites = new BitSet(); bites.set(0);// w ww.ja va 2 s . c o m bites.set(1); bites.set(2); bites.set(3); System.out.println(bites); bites.and(bites); System.out.println(bites); bites.or(bites); System.out.println(bites); bites.xor(bites); System.out.println(bites); bites.andNot(bites); System.out.println(bites); }
From source file:MainClass.java
public static void main(String args[]) { BitSet bits1 = new BitSet(16); BitSet bits2 = new BitSet(16); // set some bits for (int i = 0; i < 16; i++) { if ((i % 2) == 0) bits1.set(i);//from ww w. j a v a 2 s .c om if ((i % 5) != 0) bits2.set(i); } System.out.println("Initial pattern in bits1: "); System.out.println(bits1); System.out.println("\nInitial pattern in bits2: "); System.out.println(bits2); // AND bits bits2.and(bits1); System.out.println("\nbits2 AND bits1: "); System.out.println(bits2); // OR bits bits2.or(bits1); System.out.println("\nbits2 OR bits1: "); System.out.println(bits2); // XOR bits bits2.xor(bits1); System.out.println("\nbits2 XOR bits1: "); System.out.println(bits2); }
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); BitSet bitset2 = new BitSet(8); // assign values to bitset1 bitset1.set(0);//from w w w. java 2 s .co m bitset1.set(1); bitset1.set(2); // assign values to bitset2 bitset2.set(2); bitset2.set(4); bitset2.set(6); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); // perform and operation between two bitsets bitset1.and(bitset2); // print the new bitset1 System.out.println(bitset1); }
From source file:Main.java
/** * very inefficient, but Java wonderful bitset has no subset op * perhaps using bit iterator would be faster, I can't be bothered. * @param x/*from w ww . j a v a2s . c om*/ * @param y * @return */ public static boolean isSubSet(BitSet x, BitSet y) { y = (BitSet) y.clone(); y.and(x); return y.equals(x); }
From source file:ca.phon.ipa.features.FeatureSet.java
/** * Produces a new FeatureSet based on the set-intersection * of the two given FeatureSets.// w ww. j a va 2s . c o m * * @param fs1 * @param fs2 * * @return fs1 INTERSECT fs2 */ public static FeatureSet intersect(FeatureSet fs1, FeatureSet fs2) { BitSet bs = (BitSet) fs1.features.clone(); bs.and(fs2.features); return new FeatureSet(bs); }
From source file:fingerprints.helper.BloomFilter.java
/** * * @param other/* www. j av a 2s . c o m*/ * @return */ public int intersect(BloomFilter<T> other) { BitSet intersection = (BitSet) this.bitSet.clone(); intersection.and(other.bitSet); return (intersection.cardinality() / bitSetSize); }
From source file:android.databinding.tool.expr.ExprModelTest.java
private void assertFlags(Expr a, Expr... exprs) { BitSet bitSet = a.getShouldReadFlags(); for (Expr expr : exprs) { BitSet clone = (BitSet) bitSet.clone(); clone.and(expr.getInvalidFlags()); assertEquals("should read flags of " + a.getUniqueKey() + " should include " + expr.getUniqueKey(), expr.getInvalidFlags(), clone); }//from w ww . j a v a 2 s. c om BitSet composite = new BitSet(); for (Expr expr : exprs) { composite.or(expr.getInvalidFlags()); } assertEquals("composite flags should match", composite, bitSet); }
From source file:model.DecomposableModel.java
/** * Export a dot file representing the graph * /* ww w.ja va 2s .c om*/ * @see {@linkplain http://www.graphviz.org/content/dot-language} * @param file * the file to save the representation to * @param variableNames * the names of the variables */ public void exportDOTCG(File file, String[] variableNames) { // String[] simplVar = Arrays.copyOf(variableNames, // variableNames.length); // for(int i=0;i<simplVar.length;i++){ // simplVar[i] = simplVar[i].replaceAll("[%()]",""); // } try { PrintWriter out = new PrintWriter(new FileOutputStream(file), true); out.println("graph G{"); for (CliqueGraphEdge edge : graph.cg.edgeSet()) { BitSet source = graph.cg.getEdgeSource(edge); BitSet target = graph.cg.getEdgeTarget(edge); BitSet inter = (BitSet) source.clone(); inter.and(target); if (variableNames == null) { out.println(graph.cg.getEdgeSource(edge) + "--" + graph.cg.getEdgeTarget(edge)); } else { out.print("\""); for (int v = source.nextSetBit(0); v >= 0; v = source.nextSetBit(v + 1)) { out.print(variableNames[v] + ";"); } out.print("\"--\""); for (int v = target.nextSetBit(0); v >= 0; v = target.nextSetBit(v + 1)) { out.print(variableNames[v] + ";"); } out.print("\" [label = \""); for (int v = inter.nextSetBit(0); v >= 0; v = inter.nextSetBit(v + 1)) { out.print(variableNames[v] + ";"); } out.println("\"]"); } } out.println("}"); out.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } }
From source file:de.hpi.petrinet.PetriNet.java
protected Map<Node, Set<Node>> deriveDominators(boolean reverse) { int initIndex = reverse ? this.getNodes().indexOf(this.getFinalPlace()) : this.getNodes().indexOf(this.getInitialPlace()); int size = this.getNodes().size(); final BitSet[] dom = new BitSet[size]; final BitSet ALL = new BitSet(size); for (Node n : this.getNodes()) ALL.set(this.getNodes().indexOf(n)); for (Node n : this.getNodes()) { int index = this.getNodes().indexOf(n); BitSet curDoms = new BitSet(size); dom[index] = curDoms;//from w ww . j a v a 2 s . c o m if (index != initIndex) curDoms.or(ALL); else curDoms.set(initIndex); } boolean changed = true; /* * While we change the dom relation for a node */ while (changed) { changed = false; for (Node n : this.getNodes()) { int index = this.getNodes().indexOf(n); if (index == initIndex) continue; final BitSet old = dom[index]; final BitSet curDoms = new BitSet(size); curDoms.or(old); Collection<Node> predecessors = reverse ? n.getSucceedingNodes() : n.getPrecedingNodes(); for (Node p : predecessors) { int index2 = this.getNodes().indexOf(p); curDoms.and(dom[index2]); } curDoms.set(index); if (!curDoms.equals(old)) { changed = true; dom[index] = curDoms; } } } Map<Node, Set<Node>> dominators = new HashMap<Node, Set<Node>>(); for (Node n : this.getNodes()) { int index = this.getNodes().indexOf(n); dominators.put(n, new HashSet<Node>()); for (int i = 0; i < size; i++) if (dom[index].get(i)) dominators.get(n).add(this.getNodes().get(i)); } return dominators; }