it.unimi.dsi.fastutil.ints.IntCollection Java Examples

The following examples show how to use it.unimi.dsi.fastutil.ints.IntCollection. 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: LhsSelector.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
@Timed
public IntCollection findLhsMatches(Selector selector) {
	Collection<IntCollection> clusters = emptyList();
	int i = 0;
	for (ColumnPairWithThreshold pair : lhs) {
		int value = selector.get(i);
		IntCollection cluster = pair.getMatching(value);
		if (cluster.isEmpty()) {
			return IntLists.EMPTY_LIST;
		}
		clusters.add(cluster);
		i++;
	}
	return CollectionUtils.intersection(clusters)
		.orElseGet(rightRecords::getAll);
}
 
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: 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 #4
Source File: Object2IntHashMultimap.java    From BungeeTabListPlus with GNU General Public License v3.0 5 votes vote down vote up
public void remove(T key, int value) {
    IntCollection collection = map.get(key);
    if (collection != null) {
        collection.rem(value);
        if (collection.isEmpty()) {
            map.remove(key);
        }
    }
}
 
Example #5
Source File: ArbitraryValidationTask.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Timed
	private long validate(Selector selector, Collection<int[]> left) {
		IntCollection rightMatches = intersector.findLhsMatches(selector);
//		log.trace("Validating {} left matches with {} right matches", left.size(),
//			rightMatches.size());
		rhs.forEach(rhsTask -> rhsTask.validate(left, rightMatches));
		return (long) left.size() * rightMatches.size();
	}
 
Example #6
Source File: SlimSimilarityIndex.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private IntCollection getSimilarRecords(int leftValue) {
	Int2DoubleMap row = similarityTable.row(leftValue).asMap();
	IntCollection result = new IntArrayList();
	Seq.seq(row.int2DoubleEntrySet())
		.filter(this::isAbove)
		.map(this::getRecords)
		.forEach(result::addAll);
	return result;
}
 
Example #7
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;
}
 
Example #8
Source File: CollectionUtilsTest.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntersection() {
	List<IntCollection> clusters = ImmutableList.<IntCollection>builder()
		.add(new IntOpenHashSet(Arrays.asList(1, 2, 3, 4)))
		.add(new IntOpenHashSet(Arrays.asList(2, 3, 4, 5)))
		.add(new IntOpenHashSet(Arrays.asList(1, 3, 4)))
		.build();
	Assert.assertThat(CollectionUtils.intersection(clusters), isPresentAnd(hasSize(2)));
	Assert.assertThat(CollectionUtils.intersection(clusters), isPresentAnd(hasItems(3, 4)));
}
 
Example #9
Source File: CollectionUtilsTest.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyAfterIntersection() {
	List<IntCollection> clusters = ImmutableList.<IntCollection>builder()
		.add(new IntOpenHashSet(Arrays.asList(1, 2, 3, 4)))
		.add(new IntOpenHashSet(Arrays.asList(2, 3, 4, 5)))
		.add(new IntOpenHashSet(Arrays.asList(1, 3, 4)))
		.add(new IntOpenHashSet(Arrays.asList(1, 5)))
		.build();
	Assert.assertThat(CollectionUtils.intersection(clusters), isPresentAnd(empty()));
}
 
Example #10
Source File: SingleValidationTask.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private long validate(IntCollection leftMatches, IntCollection rightMatches) {
	log.trace("Validating {} left matches with {} right matches", Integer.valueOf(leftMatches.size()),
		Integer.valueOf(rightMatches.size()));
	Iterable<int[]> left = getRecords(leftMatches);
	rhs.forEach(rhsTask -> rhsTask.validate(left, rightMatches));
	return (long) leftMatches.size() * rightMatches.size();
}
 
Example #11
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 #12
Source File: CollectingThresholdMap.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private IntCollection collect(Double2ObjectMap<IntSet> sortedMap, double max) {
	//this function seems to be the most crucial part of the code
	for (Entry<IntSet> entry : sortedMap.double2ObjectEntrySet()) {
		double threshold = entry.getDoubleKey();
		if (threshold < max) {
			// thresholds are sorted descending
			break;
		}
		IntSet value = entry.getValue();
		result.addAll(value);
	}
	return result;
}
 
Example #13
Source File: CollectingThresholdMap.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Override
public IntCollection greaterOrEqual(int valueId, double max) {
	if (useCache) {
		GreaterOrEqualCall call = new GreaterOrEqualCall(valueId, max);
		LoadingCache<GreaterOrEqualCall, IntCollection> cache = getCache();
		return cache.getUnchecked(call);
	}
	return greaterOrEqual_(valueId, max);
}
 
Example #14
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 #15
Source File: SingleActualEnforcer.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private CompressedEnforceMatch enforce(IntCollection leftMatches, IntCollection rightMatches) {
	Iterable<int[]> left = leftRecords.getRecords(leftMatches);
	Iterable<int[]> right = rightRecords.getRecords(rightMatches);
	return new CompressedEnforceMatch(left, right);
}
 
Example #16
Source File: SingleActualEnforcer.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private CompressedEnforceMatch enforce(Cluster entry) {
	int value = entry.getValue();
	IntCollection leftMatches = entry.getRecords();
	IntCollection rightMatches = columnPair.getAllSimilarRightRecords(value, threshold);
	return enforce(leftMatches, rightMatches);
}
 
Example #17
Source File: CollectionUtils.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public static Optional<IntCollection> intersection(Collection<IntCollection> clusters) {
	//shrink result as early as possible
	List<IntCollection> sorted = sort(clusters, CLUSTER_COMPARATOR);
	return createIntersector(sorted).map(HeadAndTailIntersector::intersect);
}
 
Example #18
Source File: ArbitraryActualEnforcer.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private CompressedEnforceMatch enforce(Selector selector, Collection<int[]> left) {
	IntCollection rightMatches = intersector.findLhsMatches(selector);
	Iterable<int[]> right = rightRecords.getRecords(rightMatches);
	return new CompressedEnforceMatch(left, right);
}
 
Example #19
Source File: LhsSelector.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private Collection<IntCollection> emptyList() {
	int size = lhs.size();
	return new ArrayList<>(size);
}
 
Example #20
Source File: ColumnPairWithThreshold.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
IntCollection getMatching(int value) {
	return columnPair.getAllSimilarRightRecords(value, threshold);
}
 
Example #21
Source File: HeadAndTailIntersector.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public static HeadAndTailIntersector create(IntCollection head,
	Collection<IntCollection> tail) {
	IntArrayList result = createResult(head);
	return new HeadAndTailIntersector(head, tail, result);
}
 
Example #22
Source File: HeadAndTailIntersector.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public IntCollection intersect() {
	IntConsumer addIfInTail = this::addIfInTail;
	head.forEach(addIfInTail);
	return result;
}
 
Example #23
Source File: HeadAndTailIntersector.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private boolean contains(IntCollection cluster) {
	return cluster.contains(match);
}
 
Example #24
Source File: SingleValidationTask.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private void validate(Cluster cluster) {
	int value = cluster.getValue();
	IntCollection leftMatches = cluster.getRecords();
	IntCollection rightMatches = columnPair.getAllSimilarRightRecords(value, threshold);
	support += validate(leftMatches, rightMatches);
}
 
Example #25
Source File: CollectionUtils.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public static IntSet merge(IntSet left, IntCollection right) {
	left.addAll(right);
	return left;
}
 
Example #26
Source File: CollectionUtils.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public static IntCollection merge(IntCollection left, IntCollection right) {
	left.addAll(right);
	return left;
}
 
Example #27
Source File: CollectionUtils.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private static Optional<HeadAndTailIntersector> createIntersector(
	List<IntCollection> clusters) {
	return with(clusters).create();
}
 
Example #28
Source File: CollectionUtils.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private static WithClusters with(List<IntCollection> clusters) {
	return new WithClusters(clusters);
}
 
Example #29
Source File: CollectionUtils.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private HeadAndTailIntersector create(IntCollection head) {
	Collection<IntCollection> tail = tail(clusters);
	return HeadAndTailIntersector.create(head, tail);
}
 
Example #30
Source File: Object2IntHashMultimap.java    From BungeeTabListPlus with GNU General Public License v3.0 4 votes vote down vote up
public boolean contains(T key, int value) {
    IntCollection collection = map.get(key);
    return collection != null && collection.contains(value);
}