Java Code Examples for it.unimi.dsi.fastutil.ints.IntOpenHashSet#size()
The following examples show how to use
it.unimi.dsi.fastutil.ints.IntOpenHashSet#size() .
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: CallGraphGenerator.java From fasten with Apache License 2.0 | 6 votes |
/** Generate a random DAG using preferential attachment. First an independent set of <code>n0</code> nodes is generated. * Then <code>n-n0</code> more nodes are generated: for each node, the outdegree is determined using <code>outdegreeDistribution.nextInt()</code> * minimized with the number of existing nodes. For each arc, the target is the existing node <code>i</code> with probability proportional to * <code>k+1</code> where <code>k</code> is <code>i</code>'s current outdegree. * * @param n number of nodes. * @param n0 number of initial nodes. * @param outdegreeDistribution distribution from which outdegrees are sampled. * @param random generator used to produce the arcs. * @return the generated DAG. */ public static ArrayListMutableGraph preferentialAttachmentDAG(final int n, final int n0, final IntegerDistribution outdegreeDistribution, final RandomGenerator random) { final ArrayListMutableGraph g = new ArrayListMutableGraph(n); final FenwickTree ft = new FenwickTree(n); // Initial independent set for (int source = 0; source < n0; source++) ft.incrementCount(source + 1); // Rest of the graph final IntOpenHashSet s = new IntOpenHashSet(); for (int source = n0; source < n; source++) { final int m = Math.min(outdegreeDistribution.sample(), source - 1); // Outdegree s.clear(); while(s.size() < m) { final int t = ft.sample(random); if (s.add(t)) { ft.incrementCount(t); g.addArc(source, t - 1); } } ft.incrementCount(source + 1); } return g; }
Example 2
Source File: NotInPredicateEvaluatorFactory.java From incubator-pinot with Apache License 2.0 | 6 votes |
DictionaryBasedNotInPredicateEvaluator(NotInPredicate notInPredicate, Dictionary dictionary) { List<String> values = notInPredicate.getValues(); _nonMatchingDictIdSet = new IntOpenHashSet(HashUtil.getMinHashSetSize(values.size())); for (String value : values) { int dictId = dictionary.indexOf(value); if (dictId >= 0) { _nonMatchingDictIdSet.add(dictId); } } _numNonMatchingDictIds = _nonMatchingDictIdSet.size(); if (_numNonMatchingDictIds == 0) { _alwaysTrue = true; } else if (dictionary.length() == _numNonMatchingDictIds) { _alwaysFalse = true; } _dictionary = dictionary; }
Example 3
Source File: InPredicateEvaluatorFactory.java From incubator-pinot with Apache License 2.0 | 6 votes |
DictionaryBasedInPredicateEvaluator(InPredicate inPredicate, Dictionary dictionary) { List<String> values = inPredicate.getValues(); _matchingDictIdSet = new IntOpenHashSet(HashUtil.getMinHashSetSize(values.size())); for (String value : values) { int dictId = dictionary.indexOf(value); if (dictId >= 0) { _matchingDictIdSet.add(dictId); } } _numMatchingDictIds = _matchingDictIdSet.size(); if (_numMatchingDictIds == 0) { _alwaysFalse = true; } else if (dictionary.length() == _numMatchingDictIds) { _alwaysTrue = true; } }
Example 4
Source File: GlobalVisitStats.java From fasten with Apache License 2.0 | 4 votes |
public static Result reaches(final KnowledgeBase kb, final long startSig, final int maxRevs, final ProgressLogger pl) { final LongOpenHashSet result = new LongOpenHashSet(); final Object2ObjectOpenHashMap<String, IntOpenHashSet> product2Revs = new Object2ObjectOpenHashMap<>(); final MutableLong totRevs = new MutableLong(); // Visit queue final LongArrayFIFOQueue queue = new LongArrayFIFOQueue(); queue.enqueue(startSig); result.add(startSig); String p = kb.callGraphs.get(index(startSig)).product; IntOpenHashSet revs = new IntOpenHashSet(); revs.add(index(startSig)); product2Revs.put(p, revs); totRevs.increment(); pl.itemsName = "nodes"; pl.info = new Object() { @Override public String toString() { return "[nodes: " + result.size() + " products: " + product2Revs.size() + " revisions: " + totRevs.getValue() + "]"; } }; pl.start("Visiting reachable nodes..."); while (!queue.isEmpty()) { final long node = queue.dequeueLong(); for (final long s : kb.successors(node)) if (!result.contains(s)) { p = kb.callGraphs.get(index(s)).product; final long gid = gid(s); if (badGIDs.contains(gid)) continue; final String targetNameSpace = kb.new Node(gid, index(s)).toFastenURI().getRawNamespace(); if (targetNameSpace.startsWith("java.") || targetNameSpace.startsWith("javax.") || targetNameSpace.startsWith("jdk.")) { badGIDs.add(gid); continue; } revs = product2Revs.get(p); if (revs == null) product2Revs.put(p, revs = new IntOpenHashSet()); if (revs.contains(index(s)) || revs.size() < maxRevs) { queue.enqueue(s); result.add(s); //System.out.println(kb.new Node(gid(node), index(node)).toFastenURI() + " -> " + kb.new Node(gid(s), index(s)).toFastenURI()); if (revs.add(index(s))) totRevs.increment(); } } pl.lightUpdate(); } pl.done(); return new Result(result, product2Revs.size(), totRevs.getValue().longValue()); }
Example 5
Source File: GlobalVisitStats.java From fasten with Apache License 2.0 | 4 votes |
public static Result coreaches(final KnowledgeBase kb, final long startSig, final int maxRevs, final ProgressLogger pl) { final LongOpenHashSet result = new LongOpenHashSet(); final Object2ObjectOpenHashMap<String, IntOpenHashSet> product2Revs = new Object2ObjectOpenHashMap<>(); final MutableLong totRevs = new MutableLong(); // Visit queue final LongArrayFIFOQueue queue = new LongArrayFIFOQueue(); queue.enqueue(startSig); result.add(startSig); String p = kb.callGraphs.get(index(startSig)).product; IntOpenHashSet revs = new IntOpenHashSet(); revs.add(index(startSig)); product2Revs.put(p, revs); totRevs.increment(); pl.itemsName = "nodes"; pl.info = new Object() { @Override public String toString() { return "[nodes: " + result.size() + " products: " + product2Revs.size() + " revisions: " + totRevs.getValue() + "]"; } }; pl.start("Visiting coreachable nodes..."); while (!queue.isEmpty()) { final long node = queue.dequeueLong(); for (final long s : kb.predecessors(node)) if (!result.contains(s)) { p = kb.callGraphs.get(index(s)).product; final String targetNameSpace = kb.new Node(gid(s), index(s)).toFastenURI().getRawNamespace(); if (targetNameSpace.startsWith("java.") || targetNameSpace.startsWith("javax.") || targetNameSpace.startsWith("jdk.")) continue; revs = product2Revs.get(p); if (revs == null) product2Revs.put(p, revs = new IntOpenHashSet()); if (revs.contains(index(s)) || revs.size() < maxRevs) { queue.enqueue(s); result.add(s); //System.out.println(kb.new Node(gid(node), index(node)).toFastenURI() + " -> " + kb.new Node(gid(s), index(s)).toFastenURI()); if (revs.add(index(s))) totRevs.increment(); } } pl.lightUpdate(); } pl.done(); return new Result(result, product2Revs.size(), totRevs.getValue().longValue()); }
Example 6
Source File: TimeColumn.java From tablesaw with Apache License 2.0 | 4 votes |
@Override public int countUnique() { IntOpenHashSet hashSet = new IntOpenHashSet(data); return hashSet.size(); }
Example 7
Source File: TimeColumn.java From tablesaw with Apache License 2.0 | 4 votes |
@Override public int countUnique() { IntOpenHashSet hashSet = new IntOpenHashSet(data); return hashSet.size(); }
Example 8
Source File: DistinctCountAggregationFunction.java From incubator-pinot with Apache License 2.0 | 4 votes |
@Override public Integer extractFinalResult(IntOpenHashSet intermediateResult) { return intermediateResult.size(); }
Example 9
Source File: ImmutableDictionaryTest.java From incubator-pinot with Apache License 2.0 | 4 votes |
@BeforeClass public void setUp() throws Exception { FileUtils.deleteQuietly(TEMP_DIR); IntOpenHashSet intSet = new IntOpenHashSet(); while (intSet.size() < NUM_VALUES) { intSet.add(RANDOM.nextInt()); } _intValues = intSet.toIntArray(); Arrays.sort(_intValues); LongOpenHashSet longSet = new LongOpenHashSet(); while (longSet.size() < NUM_VALUES) { longSet.add(RANDOM.nextLong()); } _longValues = longSet.toLongArray(); Arrays.sort(_longValues); FloatOpenHashSet floatSet = new FloatOpenHashSet(); while (floatSet.size() < NUM_VALUES) { floatSet.add(RANDOM.nextFloat()); } _floatValues = floatSet.toFloatArray(); Arrays.sort(_floatValues); DoubleOpenHashSet doubleSet = new DoubleOpenHashSet(); while (doubleSet.size() < NUM_VALUES) { doubleSet.add(RANDOM.nextDouble()); } _doubleValues = doubleSet.toDoubleArray(); Arrays.sort(_doubleValues); Set<String> stringSet = new HashSet<>(); while (stringSet.size() < NUM_VALUES) { stringSet.add(RandomStringUtils.random(RANDOM.nextInt(MAX_STRING_LENGTH)).replace('\0', ' ')); } _stringValues = stringSet.toArray(new String[NUM_VALUES]); Arrays.sort(_stringValues); Set<ByteArray> bytesSet = new HashSet<>(); while (bytesSet.size() < NUM_VALUES) { byte[] bytes = new byte[BYTES_LENGTH]; RANDOM.nextBytes(bytes); bytesSet.add(new ByteArray(bytes)); } _bytesValues = bytesSet.toArray(new ByteArray[NUM_VALUES]); Arrays.sort(_bytesValues); try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_intValues, new DimensionFieldSpec(INT_COLUMN_NAME, FieldSpec.DataType.INT, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_longValues, new DimensionFieldSpec(LONG_COLUMN_NAME, FieldSpec.DataType.LONG, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_floatValues, new DimensionFieldSpec(FLOAT_COLUMN_NAME, FieldSpec.DataType.FLOAT, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_doubleValues, new DimensionFieldSpec(DOUBLE_COLUMN_NAME, FieldSpec.DataType.DOUBLE, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_stringValues, new DimensionFieldSpec(STRING_COLUMN_NAME, FieldSpec.DataType.STRING, true), TEMP_DIR)) { dictionaryCreator.build(); _numBytesPerStringValue = dictionaryCreator.getNumBytesPerEntry(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_bytesValues, new DimensionFieldSpec(BYTES_COLUMN_NAME, FieldSpec.DataType.BYTES, true), TEMP_DIR)) { dictionaryCreator.build(); assertEquals(dictionaryCreator.getNumBytesPerEntry(), BYTES_LENGTH); } }
Example 10
Source File: ImmutableDictionaryTypeConversionTest.java From incubator-pinot with Apache License 2.0 | 4 votes |
@BeforeClass public void setUp() throws Exception { FileUtils.deleteQuietly(TEMP_DIR); IntOpenHashSet intSet = new IntOpenHashSet(); while (intSet.size() < NUM_VALUES) { intSet.add(RANDOM.nextInt(MAX_VALUE - MIN_VALUE) + MIN_VALUE); } _intValues = intSet.toIntArray(); Arrays.sort(_intValues); _longValues = new long[NUM_VALUES]; ArrayCopyUtils.copy(_intValues, _longValues, NUM_VALUES); _floatValues = new float[NUM_VALUES]; ArrayCopyUtils.copy(_intValues, _floatValues, NUM_VALUES); _doubleValues = new double[NUM_VALUES]; ArrayCopyUtils.copy(_intValues, _doubleValues, NUM_VALUES); _stringValues = new String[NUM_VALUES]; ArrayCopyUtils.copy(_intValues, _stringValues, NUM_VALUES); _bytesValues = new ByteArray[NUM_VALUES]; for (int i = 0; i < NUM_VALUES; i++) { _bytesValues[i] = BytesUtils.toByteArray(_stringValues[i]); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_intValues, new DimensionFieldSpec(INT_COLUMN_NAME, FieldSpec.DataType.INT, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_longValues, new DimensionFieldSpec(LONG_COLUMN_NAME, FieldSpec.DataType.LONG, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_floatValues, new DimensionFieldSpec(FLOAT_COLUMN_NAME, FieldSpec.DataType.FLOAT, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_doubleValues, new DimensionFieldSpec(DOUBLE_COLUMN_NAME, FieldSpec.DataType.DOUBLE, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_stringValues, new DimensionFieldSpec(STRING_COLUMN_NAME, FieldSpec.DataType.STRING, true), TEMP_DIR)) { dictionaryCreator.build(); assertEquals(dictionaryCreator.getNumBytesPerEntry(), STRING_LENGTH); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_bytesValues, new DimensionFieldSpec(BYTES_COLUMN_NAME, FieldSpec.DataType.BYTES, true), TEMP_DIR)) { dictionaryCreator.build(); assertEquals(dictionaryCreator.getNumBytesPerEntry(), BYTES_LENGTH); } _dictIds = new int[NUM_VALUES]; for (int i = 0; i < NUM_VALUES; i++) { _dictIds[i] = i; } _intValuesBuffer = new int[NUM_VALUES]; _longValuesBuffer = new long[NUM_VALUES]; _floatValuesBuffer = new float[NUM_VALUES]; _doubleValuesBuffer = new double[NUM_VALUES]; _stringValuesBuffer = new String[NUM_VALUES]; _bytesValuesBuffer = new byte[NUM_VALUES][]; }