Search in sources :

Example 6 with IntHashSet

use of org.eclipse.collections.impl.set.mutable.primitive.IntHashSet in project eclipse-collections by eclipse.

the class CodePointAdapter method distinct.

@Override
public CodePointAdapter distinct() {
    StringBuilder builder = new StringBuilder();
    IntHashSet seenSoFar = new IntHashSet();
    int length = this.adapted.length();
    for (int i = 0; i < length; ) {
        int codePoint = this.adapted.codePointAt(i);
        if (seenSoFar.add(codePoint)) {
            builder.appendCodePoint(codePoint);
        }
        i += Character.charCount(codePoint);
    }
    return new CodePointAdapter(builder.toString());
}
Also used : IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)

Example 7 with IntHashSet

use of org.eclipse.collections.impl.set.mutable.primitive.IntHashSet in project eclipse-collections by eclipse.

the class SetAdapter method collectInt.

@Override
public MutableIntSet collectInt(IntFunction<? super T> intFunction) {
    IntHashSet result = new IntHashSet(this.size());
    this.forEach(new CollectIntProcedure<>(intFunction, result));
    return result;
}
Also used : IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)

Example 8 with IntHashSet

use of org.eclipse.collections.impl.set.mutable.primitive.IntHashSet in project eclipse-collections by eclipse.

the class StackIterableTestCase method collectIntWithTarget.

@Override
@Test
public void collectIntWithTarget() {
    IntHashSet target = new IntHashSet();
    StackIterable<Integer> stack = this.newStackFromTopToBottom(1, 2, 3);
    IntHashSet result = stack.collectInt(PrimitiveFunctions.unboxIntegerToInt(), target);
    Assert.assertEquals(IntHashSet.newSetWith(1, 2, 3), result);
    Assert.assertSame("Target sent as parameter not returned", target, result);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet) Test(org.junit.Test)

Example 9 with IntHashSet

use of org.eclipse.collections.impl.set.mutable.primitive.IntHashSet in project eclipse-collections by eclipse.

the class IntHashSetAddTest method runHashPut.

private void runHashPut(int[] values) {
    for (int i = 0; i < 100; i++) {
        this.runHashContains(this.runHashPut(values, 1000, 1000), values, 1000, 1000);
    }
    for (int i = 0; i < 100; i++) {
        this.runHashContains(this.runHashPut(values, 1000000, 1), values, 1000000, 1);
    }
    IntHashSet set = null;
    long now1 = System.currentTimeMillis();
    for (int i = 0; i < 100; i++) {
        set = this.runHashPut(values, 1000000, 1);
    }
    long time1 = System.currentTimeMillis() - now1;
    LOGGER.info("IntHashSet, set size 1,000,000, puts/msec: {}", 100000000 / time1);
    long now2 = System.currentTimeMillis();
    for (int i = 0; i < 100; i++) {
        this.runHashContains(this.runHashPut(values, 1000000, 1), values, 1000000, 1);
    }
    long time2 = System.currentTimeMillis() - now2;
    LOGGER.info("IntHashSet, set size 1,000,000, contains/msec: {}", 100000000 / time2);
}
Also used : IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)

Example 10 with IntHashSet

use of org.eclipse.collections.impl.set.mutable.primitive.IntHashSet in project eclipse-collections by eclipse.

the class IntIntMapProbeTest method testRandomRemove.

private void testRandomRemove(MutableIntIntMap intIntMap, int keyCount) {
    Random random = new Random(0x123456789ABCDL);
    MutableIntSet set = new IntHashSet(keyCount);
    while (set.size() < keyCount) {
        set.add(random.nextInt());
    }
    int[] intKeysForMap = set.toArray();
    this.shuffle(intKeysForMap, random);
    for (int i = 0; i < keyCount; i++) {
        intIntMap.put(intKeysForMap[i], intKeysForMap[i] * 10);
    }
    this.shuffle(intKeysForMap, random);
    for (int i = 0; i < intKeysForMap.length; i++) {
        intIntMap.remove(intKeysForMap[i]);
        for (int j = i + 1; j < intKeysForMap.length; j++) {
            Assert.assertEquals((long) (intKeysForMap[j] * 10), intIntMap.get(intKeysForMap[j]));
        }
    }
}
Also used : MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) Random(java.util.Random) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)

Aggregations

IntHashSet (org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)22 MutableIntSet (org.eclipse.collections.api.set.primitive.MutableIntSet)8 Random (java.util.Random)4 FasterList (jcog.list.FasterList)2 BitSet (java.util.BitSet)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Supplier (java.util.function.Supplier)1 ChangedTextInput (nars.op.in.ChangedTextInput)1 Term (nars.term.Term)1 Anom (nars.term.anon.Anom)1 Int (nars.term.atom.Int)1 Variable (nars.term.var.Variable)1 IntIterator (org.eclipse.collections.api.iterator.IntIterator)1 MutableIntIterator (org.eclipse.collections.api.iterator.MutableIntIterator)1 MutableList (org.eclipse.collections.api.list.MutableList)1 IntObjectPair (org.eclipse.collections.api.tuple.primitive.IntObjectPair)1 IntIntHashMap (org.eclipse.collections.impl.map.mutable.primitive.IntIntHashMap)1 IntObjectHashMap (org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap)1 Test (org.junit.Test)1