Search in sources :

Example 6 with IntOpenHashSet

use of it.unimi.dsi.fastutil.ints.IntOpenHashSet in project geode by apache.

the class RegionVersionHolderRandomJUnitTest method testParallelThreads.

/**
   * This tries to be a more "real life" test. A bunch of threads perform updates, which should
   * create exceptions. Verify that the final exception list is correct.
   */
@Test
public void testParallelThreads() throws InterruptedException {
    RegionVersionHolder vh1 = new RegionVersionHolder(member());
    RegionVersionHolder vh2 = new RegionVersionHolder(member());
    int UPDATES = 50000;
    int NUM_UPDATERS = 20;
    int NUM_EXCEPTIONS = 500;
    Random random = new Random();
    IntOpenHashSet exceptions = new IntOpenHashSet();
    for (int i = 0; i < NUM_EXCEPTIONS; i++) {
        exceptions.add(i);
    }
    HolderUpdater[] updaters = new HolderUpdater[NUM_UPDATERS];
    for (int i = 0; i < updaters.length; i++) {
        updaters[i] = new HolderUpdater(UPDATES, i, NUM_UPDATERS, exceptions, vh1, vh2);
    }
    for (int i = 0; i < updaters.length; i++) {
        updaters[i].start();
    }
    for (int i = 0; i < updaters.length; i++) {
        updaters[i].join();
    }
    // System.out.println("testing vh1="+vh1);
    for (int i = 1; i < UPDATES; i++) {
        assertEquals("vector is incorrect on item " + i, !exceptions.contains(i), vh1.contains(i));
    }
    // Mimic a GII. Initialize vh2 from vh1. vh2 has not seen all of the updates
    vh2.initializeFrom(vh1);
    // System.out.println("testing vh2="+vh2);
    for (int i = 1; i < UPDATES; i++) {
        assertEquals("vector is incorrect on item " + i, !exceptions.contains(i), vh2.contains(i));
    }
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) Random(java.util.Random) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 7 with IntOpenHashSet

use of it.unimi.dsi.fastutil.ints.IntOpenHashSet in project gradle by gradle.

the class ClassDependenciesVisitor method retrieveConstants.

public static IntSet retrieveConstants(ClassReader reader) {
    IntSet constants = new IntOpenHashSet(2);
    ClassDependenciesVisitor visitor = new ClassDependenciesVisitor(constants);
    reader.accept(visitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
    return constants;
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) IntSet(it.unimi.dsi.fastutil.ints.IntSet)

Example 8 with IntOpenHashSet

use of it.unimi.dsi.fastutil.ints.IntOpenHashSet in project gradle by gradle.

the class IntSetSerializer method read.

@Override
public IntSet read(Decoder decoder) throws EOFException, Exception {
    int size = decoder.readInt();
    IntSet result = new IntOpenHashSet(size);
    for (int i = 0; i < size; i++) {
        result.add(decoder.readInt());
    }
    return result;
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) IntSet(it.unimi.dsi.fastutil.ints.IntSet)

Example 9 with IntOpenHashSet

use of it.unimi.dsi.fastutil.ints.IntOpenHashSet in project pinot by linkedin.

the class DistinctCountMVAggregationFunction method getOrCreateHashSetForGroupKey.

/**
   * Returns the hash-set for the given group-key. Creates and returns one, if it does not exist.
   *
   * @param groupByResultHolder Result Holder
   * @param groupKey Group key for which to get the hash set.
   * @return Hash-set for the group key
   */
private IntOpenHashSet getOrCreateHashSetForGroupKey(@Nonnull GroupByResultHolder groupByResultHolder, int groupKey) {
    IntOpenHashSet valueSet = groupByResultHolder.getResult(groupKey);
    if (valueSet == null) {
        valueSet = new IntOpenHashSet();
        groupByResultHolder.setValueForKey(groupKey, valueSet);
    }
    return valueSet;
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet)

Example 10 with IntOpenHashSet

use of it.unimi.dsi.fastutil.ints.IntOpenHashSet in project druid by druid-io.

the class InDimFilter method getFloatPredicateSupplier.

private Supplier<DruidFloatPredicate> getFloatPredicateSupplier() {
    return new Supplier<DruidFloatPredicate>() {

        private final Object initLock = new Object();

        private DruidFloatPredicate predicate;

        private void initFloatValues() {
            if (predicate != null) {
                return;
            }
            synchronized (initLock) {
                if (predicate != null) {
                    return;
                }
                IntArrayList floatBits = new IntArrayList(values.size());
                for (String value : values) {
                    Float floatValue = Floats.tryParse(value);
                    if (floatValue != null) {
                        floatBits.add(Float.floatToIntBits(floatValue));
                    }
                }
                if (floatBits.size() > NUMERIC_HASHING_THRESHOLD) {
                    final IntOpenHashSet floatBitsHashSet = new IntOpenHashSet(floatBits);
                    predicate = new DruidFloatPredicate() {

                        @Override
                        public boolean applyFloat(float input) {
                            return floatBitsHashSet.contains(Float.floatToIntBits(input));
                        }
                    };
                } else {
                    final int[] floatBitsArray = floatBits.toIntArray();
                    Arrays.sort(floatBitsArray);
                    predicate = new DruidFloatPredicate() {

                        @Override
                        public boolean applyFloat(float input) {
                            return Arrays.binarySearch(floatBitsArray, Float.floatToIntBits(input)) >= 0;
                        }
                    };
                }
            }
        }

        @Override
        public DruidFloatPredicate get() {
            initFloatValues();
            return predicate;
        }
    };
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) Supplier(com.google.common.base.Supplier) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList)

Aggregations

IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)14 IntSet (it.unimi.dsi.fastutil.ints.IntSet)5 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)2 Supplier (com.google.common.base.Supplier)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 ByteBuffer (java.nio.ByteBuffer)1 Random (java.util.Random)1 UnitTest (org.apache.geode.test.junit.categories.UnitTest)1 ClassAnalysis (org.gradle.api.internal.tasks.compile.incremental.deps.ClassAnalysis)1 Test (org.junit.Test)1 Test (org.testng.annotations.Test)1