Java Code Examples for java.util.BitSet#clear()

The following examples show how to use java.util.BitSet#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: B6296240.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    String[] malformedIPv4s = {"192.168.1.220..."};
    BitSet expectedExceptions = new BitSet(malformedIPv4s.length);
    expectedExceptions.clear();

    for (int i = 0; i < malformedIPv4s.length; i++) {
        try {
            InetAddress.getAllByName(malformedIPv4s[i]);
        } catch (UnknownHostException e) {
            expectedExceptions.set(i);
        }
    }

    for (int i = 0; i < malformedIPv4s.length; i++) {
        if (!expectedExceptions.get(i)) {
            System.out.println("getAllByName(\"" + malformedIPv4s[i] + "\") should throw exception.");
        }
    }

    if (expectedExceptions.cardinality() != malformedIPv4s.length) {
        throw new RuntimeException("Failed: some expected UnknownHostExceptions are not thrown.");
    }
}
 
Example 2
Source File: ConcurrentSkipListSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void mutateSet(NavigableSet<Integer> set, int min, int max, BitSet bs) {
    int size = set.size();
    int rangeSize = max - min + 1;

    // Remove a bunch of entries directly
    for (int i = 0, n = rangeSize / 2; i < n; i++) {
        remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs);
    }

    // Remove a bunch of entries with iterator
    for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
        if (rnd.nextBoolean()) {
            bs.clear(it.next());
            it.remove();
        }
    }

    // Add entries till we're back to original size
    while (set.size() < size) {
        int element = min + rnd.nextInt(rangeSize);
        assertTrue(element >= min && element <= max);
        put(set, element, bs);
    }
}
 
Example 3
Source File: FDTreeElement.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
/**
	 * Checks, whether the dependent attribute ends in the current tree element.
	 * 
	 * @param rhs
	 *            the i'th dependent attribute.
	 * @return true, if the tree element does not have any children with the
	 *         same dependent attribute. false, otherwise.
	 */
/*	public boolean isLastNodeOf(int rhs) {
		if (!this.hasRhsAttribute(rhs))
			return false;
		
		// Check all children for the rhs
		for (int attr = 0; attr < this.maxAttributeNumber; attr++)
			if ((this.children[attr] != null) && (this.children[attr].hasRhsAttribute(rhs)))
				return false;
		
		return true;
	}
*/
	// FUDEBS
	protected void addOneSmallerGeneralizations(BitSet currentLhs, int maxCurrentLhsAttribute, int rhs, FDTree tree) {
		for (int lhsAttribute = currentLhs.nextSetBit(0); lhsAttribute != maxCurrentLhsAttribute; lhsAttribute = currentLhs.nextSetBit(lhsAttribute + 1)) {
			currentLhs.clear(lhsAttribute);
			tree.addGeneralization(currentLhs, rhs);
			currentLhs.set(lhsAttribute);
		}
	}
 
Example 4
Source File: MultiRunStatementsFinder.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
protected void flowThrough(BitSet in, Unit unit,
			BitSet out)
	{
		out.clear();
		out.or(in);
		
		if (!out.get(indexOf(unit))){
			out.set(indexOf(unit));
//			System.out.println("add to out: "+unit);
		}
		else{
			multiRunStatements.add(unit);
		}
		
//		System.out.println("in: "+in);
//		System.out.println("out: "+out);
		
	}
 
Example 5
Source File: FDTreeTest.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteGeneralizations() {
	fdtree = new FDTree(4, -1);
	BitSet lhs = new BitSet();
	lhs.set(0);
	lhs.set(1);
	
	this.fdtree.addFunctionalDependency(lhs, 3);
	lhs.clear(1);
	lhs.set(2);
	this.fdtree.addFunctionalDependency(lhs, 3);
	
	//lhs.set(1);
	//this.fdtree.deleteGeneralizations(lhs, 3, 0);
	//assertTrue(this.fdtree.isEmpty());
}
 
Example 6
Source File: FDTreeElement.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
protected void addToIndex(Int2ObjectOpenHashMap<ArrayList<ElementLhsPair>> level2elements, int level, BitSet lhs) {
	level2elements.get(level).add(new ElementLhsPair(this, (BitSet) lhs.clone()));
	if (this.children != null) {
		for (int childAttr = 0; childAttr < this.numAttributes; childAttr++) {
			FDTreeElement element = this.children[childAttr];
			if (element != null) {
				lhs.set(childAttr);
				element.addToIndex(level2elements, level + 1, lhs);
				lhs.clear(childAttr);
			}
		}
	}
}
 
Example 7
Source File: Selection.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Deselects the specified indexes.
 *
 * @param indexes The indexes to deselect.
 */
public void deselect(int[] indexes) {
    BitSet newSel = (BitSet) mSelection.clone();
    for (int element : indexes) {
        newSel.clear(element);
        if (mAnchor == element) {
            mAnchor = -1;
        }
    }
    if (mAnchor == -1) {
        int index = newSel.nextSetBit(0);
        mAnchor = index < mSize ? index : -1;
    }
    applySelectionChange(newSel);
}
 
Example 8
Source File: FDEP.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
protected void fetchBitSets(Set<BitSet> posCoverTree, FDTreeElement negCoverSubtree, BitSet activePath) {
	posCoverTree.add((BitSet) activePath.clone());
	
	if (negCoverSubtree.getChildren() != null) {
		for (int attr = 0; attr < this.numAttributes; attr++) {
			if (negCoverSubtree.getChildren()[attr] != null) {
				activePath.set(attr);
				this.fetchBitSets(posCoverTree, negCoverSubtree.getChildren()[attr], activePath);
				activePath.clear(attr);
			}
		}
	}
}
 
Example 9
Source File: MethodAnalyzer.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
private void setPostRegisterTypeAndPropagateChanges(@Nonnull AnalyzedInstruction analyzedInstruction,
                                                    int registerNumber, @Nonnull RegisterType registerType) {

    BitSet changedInstructions = new BitSet(analyzedInstructions.size());

    if (!analyzedInstruction.setPostRegisterType(registerNumber, registerType)) {
        return;
    }

    propagateRegisterToSuccessors(analyzedInstruction, registerNumber, changedInstructions);

    //Using a for loop inside the while loop optimizes for the common case of the successors of an instruction
    //occurring after the instruction. Any successors that occur prior to the instruction will be picked up on
    //the next iteration of the while loop.
    //This could also be done recursively, but in large methods it would likely cause very deep recursion,
    //which requires the user to specify a larger stack size. This isn't really a problem, but it is slightly
    //annoying.
    while (!changedInstructions.isEmpty()) {
        for (int instructionIndex=changedInstructions.nextSetBit(0);
                 instructionIndex>=0;
                 instructionIndex=changedInstructions.nextSetBit(instructionIndex+1)) {

            changedInstructions.clear(instructionIndex);

            propagateRegisterToSuccessors(analyzedInstructions.valueAt(instructionIndex), registerNumber,
                    changedInstructions);
        }
    }

    if (registerType.category == RegisterType.LONG_LO) {
        checkWidePair(registerNumber, analyzedInstruction);
        setPostRegisterTypeAndPropagateChanges(analyzedInstruction, registerNumber+1, RegisterType.LONG_HI_TYPE);
    } else if (registerType.category == RegisterType.DOUBLE_LO) {
        checkWidePair(registerNumber, analyzedInstruction);
        setPostRegisterTypeAndPropagateChanges(analyzedInstruction, registerNumber+1, RegisterType.DOUBLE_HI_TYPE);
    }
}
 
Example 10
Source File: CodeListSet.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Retains only the elements of the given collection in this set.
 *
 * @param  c  the collection containing elements to retain in this set.
 * @return {@code true} if this set changed as a result of this method call.
 */
@Override
public boolean retainAll(final Collection<?> c) {
    if (c instanceof CodeListSet) {
        boolean changed = (values != (values &= mask((CodeListSet<?>) c)));
        /*
         * Code below this point is for the rare cases
         * where there is more than 64 code list elements.
         */
        final BitSet s = supplementary;
        if (s != null) {
            final BitSet os = ((CodeListSet<?>) c).supplementary;
            if (os == null) {
                changed |= !s.isEmpty();
                s.clear();
            } else if (changed) {
                // Avoid the cost of computing cardinality.
                s.and(os);
            } else {
                final int cardinality = s.cardinality();
                s.and(os);
                changed = (cardinality != s.cardinality());
            }
        }
        return changed;
    }
    return super.retainAll(c);
}
 
Example 11
Source File: RegionMaker.java    From jadx with Apache License 2.0 5 votes vote down vote up
@Nullable
private BlockNode getOneIntersectionBlock(BlockNode out, BitSet caseBlocks, BitSet fallThroughSet) {
	BitSet caseExits = BlockUtils.copyBlocksBitSet(mth, fallThroughSet);
	caseExits.clear(out.getId());
	caseExits.and(caseBlocks);
	return BlockUtils.bitSetToOneBlock(mth, caseExits);
}
 
Example 12
Source File: UScript.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
/**
 * Sets code point c's Script_Extensions as script code integers into the output BitSet.
 * <ul>
 * <li>If c does have Script_Extensions, then the return value is
 * the negative number of Script_Extensions codes (= -set.cardinality());
 * in this case, the Script property value
 * (normally Common or Inherited) is not included in the set.
 * <li>If c does not have Script_Extensions, then the one Script code is put into the set
 * and also returned.
 * <li>If c is not a valid code point, then the one {@link #UNKNOWN} code is put into the set
 * and also returned.
 * </ul>
 * In other words, if the return value is non-negative, it is c's single Script code
 * and the set contains exactly this Script code.
 * If the return value is -n, then the set contains c's n&gt;=2 Script_Extensions script codes.
 *
 * <p>Some characters are commonly used in multiple scripts.
 * For more information, see UAX #24: http://www.unicode.org/reports/tr24/.
 *
 * @param c code point
 * @param set set of script code integers; will be cleared, then bits are set
 *            corresponding to c's Script_Extensions
 * @return negative number of script codes in c's Script_Extensions,
 *         or the non-negative single Script value
 * @stable ICU 49
 */
public static final int getScriptExtensions(int c, BitSet set) {
    set.clear();
    int scriptX=UCharacterProperty.INSTANCE.getAdditional(c, 0)&UCharacterProperty.SCRIPT_X_MASK;
    if(scriptX<UCharacterProperty.SCRIPT_X_WITH_COMMON) {
        set.set(scriptX);
        return scriptX;
    }

    char[] scriptExtensions=UCharacterProperty.INSTANCE.m_scriptExtensions_;
    int scx=scriptX&UCharacterProperty.SCRIPT_MASK_;  // index into scriptExtensions
    if(scriptX>=UCharacterProperty.SCRIPT_X_WITH_OTHER) {
        scx=scriptExtensions[scx+1];
    }
    int length=0;
    int sx;
    do {
        sx=scriptExtensions[scx++];
        set.set(sx&0x7fff);
        ++length;
    } while(sx<0x8000);
    // length==set.cardinality()
    return -length;
}
 
Example 13
Source File: TaneAlgorithmFilterTreeEnd.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private void computeDependencies(int l) throws AlgorithmExecutionException {
    initializeCplusForLevel();

    // iterate through the combinations of the level
    for (BitSet X : level1.keySet()) {
        // Build the intersection between X and C_plus(X)
        BitSet C_plus = level1.get(X).getRhsCandidates();
        BitSet intersection = (BitSet) X.clone();
        intersection.and(C_plus);

        // clone of X for usage in the following loop
        BitSet Xclone = (BitSet) X.clone();

        // iterate through all elements (A) of the intersection
        for (int A = intersection.nextSetBit(0); A >= 0; A = intersection.nextSetBit(A + 1)) {
            Xclone.clear(A);

            // check if X\A -> A is valid
            StrippedPartition spXwithoutA = level0.get(Xclone).getPartition();
            StrippedPartition spX = level1.get(X).getPartition();

            if (spX.getError() == spXwithoutA.getError()) {
                // add fd to FDTree. Filter the tree at the end of the algorithm.
                dependencies.addFunctionalDependency(Xclone, A);


                // remove A from C_plus(X)
                level1.get(X).getRhsCandidates().clear(A);

                // remove all B in R\X from C_plus(X)
                BitSet RwithoutX = new BitSet();
                // set to R
                RwithoutX.set(1, numberAttributes + 1);
                // remove X
                RwithoutX.andNot(X);

                for (int i = RwithoutX.nextSetBit(0); i >= 0; i = RwithoutX.nextSetBit(i + 1)) {
                    level1.get(X).getRhsCandidates().clear(i);
                }

            }
            Xclone.set(A);
        }
    }
}
 
Example 14
Source File: TransitiveSetTraverser.java    From hollow with Apache License 2.0 4 votes vote down vote up
@Override
public void foundReference(BitSet referencerClosureMatches, int referencerOrdinal, BitSet referencedClosureMatches, int referencedOrdinal) {
    referencedClosureMatches.clear(referencedOrdinal);
}
 
Example 15
Source File: Validator.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public ValidationResult call() throws Exception {
	ValidationResult result = new ValidationResult();
	
	FDTreeElement element = this.elementLhsPair.getElement();
	BitSet lhs = this.elementLhsPair.getLhs();
	BitSet rhs = element.getFds();
	
	int rhsSize = rhs.cardinality();
	if (rhsSize == 0)
		return result;
	result.validations = result.validations + rhsSize;
	
	if (Validator.this.level == 0) {
		// Check if rhs is unique
		for (int rhsAttr = rhs.nextSetBit(0); rhsAttr >= 0; rhsAttr = rhs.nextSetBit(rhsAttr + 1)) {
			if (!Validator.this.plis.get(rhsAttr).isConstant(Validator.this.numRecords)) {
				element.removeFd(rhsAttr);
				result.invalidFDs.add(new FD(lhs, rhsAttr));
			}
			result.intersections++;
		}
	}
	else if (Validator.this.level == 1) {
		// Check if lhs from plis refines rhs
		int lhsAttribute = lhs.nextSetBit(0);
		for (int rhsAttr = rhs.nextSetBit(0); rhsAttr >= 0; rhsAttr = rhs.nextSetBit(rhsAttr + 1)) {
			if (!Validator.this.plis.get(lhsAttribute).refines(Validator.this.compressedRecords, rhsAttr)) {
				element.removeFd(rhsAttr);
				result.invalidFDs.add(new FD(lhs, rhsAttr));
			}
			result.intersections++;
		}
	}
	else {
		// Check if lhs from plis plus remaining inverted plis refines rhs
		int firstLhsAttr = lhs.nextSetBit(0);
		
		lhs.clear(firstLhsAttr);
		BitSet validRhs = Validator.this.plis.get(firstLhsAttr).refines(Validator.this.compressedRecords, lhs, rhs, result.comparisonSuggestions);
		lhs.set(firstLhsAttr);
		
		result.intersections++;
		
		rhs.andNot(validRhs); // Now contains all invalid FDs
		element.setFds(validRhs); // Sets the valid FDs in the FD tree
		
		for (int rhsAttr = rhs.nextSetBit(0); rhsAttr >= 0; rhsAttr = rhs.nextSetBit(rhsAttr + 1))
			result.invalidFDs.add(new FD(lhs, rhsAttr));
	}
	return result;
}
 
Example 16
Source File: FDTreeElement.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
protected void maximizeNegativeRecursive(PositionListIndex currentPli, BitSet currentLhs, int numAttributes, int[][] rhsPlis, FDTree invalidFds) {
	PositionListIndex[] childPlis = new PositionListIndex[numAttributes];
	
	// Traverse the tree depth-first, left-first; generate plis for children and pass them over; store the child plis locally to reuse them for the checking afterwards
	if (this.children != null) {
		for (int attr = 0; attr < numAttributes; attr++) {
			if (this.children[attr] != null) {
				childPlis[attr] = currentPli.intersect(rhsPlis[attr]);
				
				currentLhs.set(attr);
				this.children[attr].maximizeNegativeRecursive(childPlis[attr], currentLhs, numAttributes, rhsPlis, invalidFds);
				currentLhs.clear(attr);
			}
		}
	}
	
	// On the way back, check all rhs-FDs that all their possible supersets are valid FDs; check with refines or, if available, with previously calculated plis
	//     which supersets to consider: add all attributes A with A notIn lhs and A notequal rhs; 
	//         for newLhs->rhs check that no FdOrSpecialization exists, because it is invalid then; this check might be slower than the FD check on high levels but faster on low levels in particular in the root! this check is faster on the negative cover, because we look for a non-FD
	for (int rhs = this.rhsFds.nextSetBit(0); rhs >= 0; rhs = this.rhsFds.nextSetBit(rhs + 1)) {
		BitSet extensions = (BitSet) currentLhs.clone();
		extensions.flip(0, numAttributes);
		extensions.clear(rhs);
		
		for (int extensionAttr = extensions.nextSetBit(0); extensionAttr >= 0; extensionAttr = extensions.nextSetBit(extensionAttr + 1)) {
			currentLhs.set(extensionAttr);
			if (childPlis[extensionAttr] == null)
				childPlis[extensionAttr] = currentPli.intersect(rhsPlis[extensionAttr]);
			
			// If a superset is a non-FD, mark this as not rhsFD, add the superset as a new node, filterGeneralizations() of the new node, call maximizeNegative() on the new supersets node
			//     if the superset node is in a right node of the tree, it will be checked anyways later; hence, only check supersets that are left or in the same tree path
			if (!childPlis[extensionAttr].refines(rhsPlis[rhs])) {
				this.rhsFds.clear(rhs);

				FDTreeElement newElement = invalidFds.addFunctionalDependency(currentLhs, rhs);
				//invalidFds.filterGeneralizations(currentLhs, rhs); // TODO: test effect
				newElement.maximizeNegativeRecursive(childPlis[extensionAttr], currentLhs, numAttributes, rhsPlis, invalidFds);
			}
			currentLhs.clear(extensionAttr);
		}
	}
}
 
Example 17
Source File: PathScoringUtilities.java    From constellation with Apache License 2.0 4 votes vote down vote up
private static Tuple<BitSet[], float[]> computeAllPathsDirected(final GraphReadMethods graph, final ScoreType scoreType,
        boolean includeConnectionsIn, boolean includeConnectionsOut, boolean treatUndirectedBidirectional) {
    final int vertexCount = graph.getVertexCount();
    final BitSet[] traversal = new BitSet[vertexCount];
    final float[] scores = new float[vertexCount];
    final ArrayList<Float> distances = new ArrayList<>();

    final BitSet update = new BitSet(vertexCount);
    final BitSet[] sendBuffer = new BitSet[vertexCount];
    final BitSet newUpdate = new BitSet(vertexCount);

    final BitSet turn = new BitSet(vertexCount);

    // initialising variables
    for (int vxPosition = 0; vxPosition < vertexCount; vxPosition++) {
        // get the vertex ID at this position
        final int vxId = graph.getVertex(vxPosition);

        traversal[vxPosition] = new BitSet(vertexCount);
        sendBuffer[vxPosition] = new BitSet(vertexCount);

        scores[vxPosition] = 0;

        // assuming the node has neighbours
        if (graph.getVertexNeighbourCount(vxId) > 0) {
            update.set(vxPosition);
        }
    }

    while (!update.isEmpty()) {

        // update the information of each node with messages
        for (int vertexPosition = update.nextSetBit(0); vertexPosition >= 0; vertexPosition = update.nextSetBit(vertexPosition + 1)) {
            traversal[vertexPosition].or(sendBuffer[vertexPosition]);
            traversal[vertexPosition].set(vertexPosition);
            sendBuffer[vertexPosition].clear();
        }

        // for each neighbour, check if there is any new information it needs to receive
        for (int vertexPosition = update.nextSetBit(0); vertexPosition >= 0; vertexPosition = update.nextSetBit(vertexPosition + 1)) {
            int vertexId = graph.getVertex(vertexPosition);

            for (int vertexNeighbourPosition = 0; vertexNeighbourPosition < graph.getVertexNeighbourCount(vertexId); vertexNeighbourPosition++) {
                int neighbourId = graph.getVertexNeighbour(vertexId, vertexNeighbourPosition);
                int neighbourPosition = graph.getVertexPosition(neighbourId);

                boolean isRequestedDirection = false;
                int linkId = graph.getLink(vertexId, neighbourId);
                for (int linkEdgePosition = 0; linkEdgePosition < graph.getLinkEdgeCount(linkId); linkEdgePosition++) {
                    final int edgeId = graph.getLinkEdge(linkId, linkEdgePosition);
                    final int edgeDirection = graph.getEdgeDirection(edgeId);
                    isRequestedDirection = (treatUndirectedBidirectional && edgeDirection == GraphConstants.UNDIRECTED)
                            || (includeConnectionsIn && graph.getEdgeSourceVertex(edgeId) == neighbourId)
                            || (includeConnectionsOut && graph.getEdgeDestinationVertex(edgeId) == neighbourId);
                    if (isRequestedDirection) {
                        break;
                    }
                }

                if (isRequestedDirection && !traversal[vertexPosition].equals(traversal[neighbourPosition])) {
                    final BitSet diff = (BitSet) traversal[vertexPosition].clone();
                    diff.andNot(traversal[neighbourPosition]);
                    turn.or(diff);
                    sendBuffer[neighbourPosition].or(diff);
                    newUpdate.set(neighbourPosition);
                }
            }
        }

        // update scores based on the current traversal state
        switch (scoreType) {
            case ECCENTRICITY:
                updateEccentricityScoresDirected(scores, turn);
                break;
            case AVERAGE_DISTANCE:
                updateAveragePathScoresUndirected(distances, scores, turn, sendBuffer);
                break;
            default:
                throw new IllegalArgumentException(String.format(SCORETYPE_ERROR_FORMAT, scoreType));
        }

        turn.clear();

        update.clear();
        update.or(newUpdate);
        newUpdate.clear();
    }

    switch (scoreType) {
        case ECCENTRICITY:
            return Tuple.create(traversal, scores);
        case AVERAGE_DISTANCE:
            final float[] distanceArray = new float[distances.size()];
            for (int i = 0; i < distances.size(); i++) {
                distanceArray[i] = distances.get(i);
            }
            return Tuple.create(traversal, distanceArray);
        default:
            throw new IllegalArgumentException(String.format(SCORETYPE_ERROR_FORMAT, scoreType));
    }
}
 
Example 18
Source File: TestRange.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
@Test
public void setTest7A() {
  final MutableRoaringBitmap rb = new MutableRoaringBitmap();
  final BitSet bs = new BitSet();
  assertTrue(TestRoaringBitmap.equals(bs, rb));

  final MutableRoaringBitmap rb1 = MutableRoaringBitmap.add(rb, 10L, 50L);
  bs.set(10, 50);
  rb.add(10L, 50L);
  assertEquals(rb1, rb);
  assertTrue(TestRoaringBitmap.equals(bs, rb1));

  MutableRoaringBitmap rb2 = MutableRoaringBitmap.add(rb1, 130L, 185L);
  bs.set(130, 185);
  rb.add(130L, 185L);
  assertEquals(rb2, rb);
  assertTrue(TestRoaringBitmap.equals(bs, rb2));

  MutableRoaringBitmap rb3 = MutableRoaringBitmap.add(rb2, 6407L, 6460);
  bs.set(6407, 6460);
  assertTrue(TestRoaringBitmap.equals(bs, rb3));
  rb2.add(6407L, 6460L);
  assertEquals(rb2, rb3);

  rb3 = MutableRoaringBitmap.add(rb3, (65536 * 3) + 3L, (65536 * 3) + 60);
  rb2.add((65536L * 3) + 3, (65536L * 3) + 60);
  bs.set((65536 * 3) + 3, (65536 * 3) + 60);
  assertEquals(rb2, rb3);
  assertTrue(TestRoaringBitmap.equals(bs, rb3));


  rb3 = MutableRoaringBitmap.add(rb3, 65536 * 3 + 195L, 65536 * 3 + 245);
  bs.set(65536 * 3 + 195, 65536 * 3 + 245);
  rb2.add(65536L * 3 + 195, 65536L * 3 + 245);
  assertEquals(rb2, rb3);
  assertTrue(TestRoaringBitmap.equals(bs, rb3));

  final int rbcard = rb3.getCardinality();

  assertEquals(255, rbcard);

  // now removing


  rb3 = MutableRoaringBitmap.remove(rb3, 65536L * 3 + 195, 65536L * 3 + 245);
  bs.clear(65536 * 3 + 195, 65536 * 3 + 245);
  rb2.remove(65536L * 3 + 195, 65536L * 3 + 245);

  assertEquals(rb2, rb3);
  assertTrue(TestRoaringBitmap.equals(bs, rb3));

  rb3 = MutableRoaringBitmap.remove(rb3, (65536 * 3) + 3L, (65536 * 3) + 60);
  bs.clear((65536 * 3) + 3, (65536 * 3) + 60);
  rb2.remove((65536L * 3) + 3, (65536L * 3) + 60);

  assertEquals(rb2, rb3);
  assertTrue(TestRoaringBitmap.equals(bs, rb3));

  rb3 = MutableRoaringBitmap.remove(rb3, 6407L, 6460L);
  bs.clear(6407, 6460);
  rb2.remove(6407L, 6460L);

  assertEquals(rb2, rb3);
  assertTrue(TestRoaringBitmap.equals(bs, rb3));


  rb2 = MutableRoaringBitmap.remove(rb1, 130L, 185L);
  bs.clear(130, 185);
  rb.remove(130L, 185L);
  assertEquals(rb2, rb);
  assertTrue(TestRoaringBitmap.equals(bs, rb2));


}
 
Example 19
Source File: StaggeredGridLayoutManager.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks for gaps if we've reached to the top of the list.
 * <p>
 * Intermediate gaps created by full span items are tracked via mLaidOutInvalidFullSpan field.
 */
View hasGapsToFix() {
    int startChildIndex = 0;
    int endChildIndex = getChildCount() - 1;
    BitSet mSpansToCheck = new BitSet(mSpanCount);
    mSpansToCheck.set(0, mSpanCount, true);

    final int firstChildIndex, childLimit;
    final int preferredSpanDir = mOrientation == VERTICAL && isLayoutRTL() ? 1 : -1;

    if (mShouldReverseLayout) {
        firstChildIndex = endChildIndex;
        childLimit = startChildIndex - 1;
    } else {
        firstChildIndex = startChildIndex;
        childLimit = endChildIndex + 1;
    }
    final int nextChildDiff = firstChildIndex < childLimit ? 1 : -1;
    for (int i = firstChildIndex; i != childLimit; i += nextChildDiff) {
        View child = getChildAt(i);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (mSpansToCheck.get(lp.mSpan.mIndex)) {
            if (checkSpanForGap(lp.mSpan)) {
                return child;
            }
            mSpansToCheck.clear(lp.mSpan.mIndex);
        }
        if (lp.mFullSpan) {
            continue; // quick reject
        }

        if (i + nextChildDiff != childLimit) {
            View nextChild = getChildAt(i + nextChildDiff);
            boolean compareSpans = false;
            if (mShouldReverseLayout) {
                // ensure child's end is below nextChild's end
                int myEnd = mPrimaryOrientation.getDecoratedEnd(child);
                int nextEnd = mPrimaryOrientation.getDecoratedEnd(nextChild);
                if (myEnd < nextEnd) {
                    return child; //i should have a better position
                } else if (myEnd == nextEnd) {
                    compareSpans = true;
                }
            } else {
                int myStart = mPrimaryOrientation.getDecoratedStart(child);
                int nextStart = mPrimaryOrientation.getDecoratedStart(nextChild);
                if (myStart > nextStart) {
                    return child; //i should have a better position
                } else if (myStart == nextStart) {
                    compareSpans = true;
                }
            }
            if (compareSpans) {
                // equal, check span indices.
                LayoutParams nextLp = (LayoutParams) nextChild.getLayoutParams();
                if (lp.mSpan.mIndex - nextLp.mSpan.mIndex < 0 != preferredSpanDir < 0) {
                    return child;
                }
            }
        }
    }
    // everything looks good
    return null;
}
 
Example 20
Source File: LiveLocalStoreAnalysis.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void makeFactTop(BitSet fact) {
    fact.clear();
    fact.set(topBit);
}