Java Code Examples for it.unimi.dsi.fastutil.ints.IntCollection#iterator()

The following examples show how to use it.unimi.dsi.fastutil.ints.IntCollection#iterator() . 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: DioriteRandomUtils.java    From Diorite with MIT License 6 votes vote down vote up
@Nullable
public static <T> T getWeightedRandom(Random random, Object2IntMap<T> choices)
{
    long i = 0;
    IntCollection ints = choices.values();
    for (IntIterator iterator = ints.iterator(); iterator.hasNext(); )
    {
        int x = iterator.nextInt();
        i += x;
    }
    i = getRandomLong(random, 0, i);
    for (Object2IntMap.Entry<T> entry : choices.object2IntEntrySet())
    {
        i -= entry.getIntValue();
        if (i < 0)
        {
            return entry.getKey();
        }
    }
    return null;
}
 
Example 3
Source File: SingleValidationTask.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private Iterable<int[]> getRecords(IntCollection leftMatches) {
	int size = leftMatches.size();
	Collection<int[]> left = new ArrayList<>(size);
	OfInt it = leftMatches.iterator();
	while (it.hasNext()) {
		int leftId = it.nextInt();
		int[] record = leftRecords.get(leftId);
		left.add(record);
	}
	return left;
}
 
Example 4
Source File: RecordSelector.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
Iterable<int[]> getRecords(IntCollection ids) {
	int size = ids.size();
	Collection<int[]> result = new ArrayList<>(size);
	OfInt it = ids.iterator();
	while (it.hasNext()) {
		int id = it.nextInt();
		int[] record = records.get(id);
		result.add(record);
	}
	return result;
}
 
Example 5
Source File: SparseDataSet.java    From hlta with GNU General Public License v3.0 5 votes vote down vote up
private DataSet SparseToDense(int batchSize, int start){
	
	if(isRandomised == false){
		randomiseDatacaseIndex();
	}
	/*
	 *  convert from sparse to dense
	 */
	
	// create a dataset over variables corresponding to the external IDs
	DataSet Dense = new DataSet(_VariablesSet);
	
	// adding datacases
	for(int i = start ; i < batchSize + start ; i++){
		
		int[] states = new int[_VariablesSet.length];
		IntCollection row = SDataSet.userMatrix().get(_randomToOriginalDataCaseIndexMap.get(i));
		
		// Filling in the positive entries
		IntIterator iter = row.iterator();
		while(iter.hasNext()){
		    int internal_ID = iter.nextInt(); // the id of the item
		    String name = _item_mapping.toOriginalID(internal_ID);
		    states[_mapNameToIndex.get(name)] = 1;
		}
		Dense.addDataCase(states, 1);
		
	}
	
	return Dense;
}