Java Code Examples for it.unimi.dsi.fastutil.ints.IntIterator#remove()

The following examples show how to use it.unimi.dsi.fastutil.ints.IntIterator#remove() . 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: FastCollectionsUtils.java    From fastjgame with Apache License 2.0 6 votes vote down vote up
/**
 * 移除map中符合条件的元素,并对删除的元素执行后续的操作。
 *
 * @param collection 必须是可修改的集合
 * @param predicate  过滤条件,为真的删除
 * @param then       元素删除之后执行的逻辑
 * @return 删除的元素数量
 */
public static int removeIfAndThen(IntCollection collection, IntPredicate predicate, IntConsumer then) {
    if (collection.size() == 0) {
        return 0;
    }
    final IntIterator itr = collection.iterator();
    int value;
    int removeNum = 0;
    while (itr.hasNext()) {
        value = itr.nextInt();
        if (predicate.test(value)) {
            itr.remove();
            removeNum++;
            then.accept(value);
        }
    }
    return removeNum;
}
 
Example 2
Source File: CustomHashMap.java    From kourami with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean intersectionPE(CustomHashMap other){
boolean modified = false;

IntIterator itr = this.keySet().iterator();
while(itr.hasNext()){
    int key = itr.nextInt();
    int keyInv = 0 - key;
    if(!other.containsKey(key) && !other.containsKey(keyInv)){
	itr.remove();
	modified = true;
    }
}

for(int otherKey : other.keySet()){
    int otherKeyInv = 0-otherKey;
    boolean intst = this.containsKey(otherKey); //does this contain otherKey?
    boolean intstPrime = this.containsKey(otherKeyInv); //does this contain -(otherkey)?
    
    if(!intst && intstPrime){
	this.put(otherKey, other.get(otherKey));
	modified = true;
    }
}
return modified;
   }
 
Example 3
Source File: CustomHashMap.java    From kourami with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public boolean intersection(CustomHashMap other){
boolean modified = false;
IntIterator itr = this.keySet().iterator();
while(itr.hasNext()){
    int curInt = itr.nextInt();
    if(!other.containsKey(curInt)){
	itr.remove();
	modified = false;
    }
}
return modified;
   }