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; } } } } }
/** Collect documents from a bitset. */ private List<Document> collectDocuments(List<Document> l, BitSet bitset) { if (l == null) { l = Lists.newArrayListWithCapacity((int) bitset.cardinality()); } final BitSetIterator i = bitset.iterator(); for (int d = i.nextSetBit(); d >= 0; d = i.nextSetBit()) { l.add(documents.get(d)); } return l; }
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); } } }
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); }
@Override public void and(DocIdSetIterator it) throws IOException { final SparseFixedBitSet other = BitSetIterator.getSparseFixedBitSetOrNull(it); if (other != null) { // if we are merging with another SparseFixedBitSet, a quick win is // to clear up some blocks by only looking at their index. Then the set // is sparser and the leap-frog approach of the parent class is more // efficient. Since SparseFixedBitSet is supposed to be used for sparse // sets, the intersection of two SparseFixedBitSet is likely very sparse final int numCommonBlocks = Math.min(indices.length, other.indices.length); for (int i = 0; i < numCommonBlocks; ++i) { if ((indices[i] & other.indices[i]) == 0) { this.nonZeroLongCount -= Long.bitCount(this.indices[i]); this.indices[i] = 0; this.bits[i] = null; } } } super.and(it); }
@Override public void or(DocIdSetIterator it) throws IOException { { // specialize union with another SparseFixedBitSet final SparseFixedBitSet other = BitSetIterator.getSparseFixedBitSetOrNull(it); if (other != null) { assertUnpositioned(it); or(other); return; } } // We do not specialize the union with a FixedBitSet since FixedBitSets are // supposed to be used for dense data and sparse fixed bit sets for sparse // data, so a sparse set would likely get upgraded by DocIdSetBuilder before // being or'ed with a FixedBitSet if (it.cost() < indices.length) { // the default impl is good for sparse iterators super.or(it); } else { orDense(it); } }
@Override public IntIterator clone() { BitSetIterator newIt = new BitSetIterator(); newIt.pos = pos; return newIt; }