Java Code Examples for it.unimi.dsi.fastutil.ints.IntOpenHashSet#add()

The following examples show how to use it.unimi.dsi.fastutil.ints.IntOpenHashSet#add() . 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 vote down vote up
/** 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: InPredicateEvaluatorFactory.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
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 3
Source File: NotInPredicateEvaluatorFactory.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
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 4
Source File: IntDictionaryMap.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Override
public Selection selectIsIn(String... strings) {
  IntOpenHashSet keys = new IntOpenHashSet(strings.length);
  for (String string : strings) {
    int key = getKeyForValue(string);
    if (key != DEFAULT_RETURN_VALUE) {
      keys.add(key);
    }
  }

  Selection results = new BitmapBackedSelection();
  for (int i = 0; i < values.size(); i++) {
    if (keys.contains(values.getInt(i))) {
      results.add(i);
    }
  }
  return results;
}
 
Example 5
Source File: IntDictionaryMap.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Override
public Selection selectIsIn(Collection<String> strings) {
  IntOpenHashSet keys = new IntOpenHashSet(strings.size());
  for (String string : strings) {
    int key = getKeyForValue(string);
    if (key != DEFAULT_RETURN_VALUE) {
      keys.add(key);
    }
  }

  Selection results = new BitmapBackedSelection();
  for (int i = 0; i < values.size(); i++) {
    if (keys.contains(values.getInt(i))) {
      results.add(i);
    }
  }
  return results;
}
 
Example 6
Source File: IntDictionaryMap.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Override
public Selection selectIsIn(String... strings) {
  IntOpenHashSet keys = new IntOpenHashSet(strings.length);
  for (String string : strings) {
    int key = getKeyForValue(string);
    if (key != DEFAULT_RETURN_VALUE) {
      keys.add(key);
    }
  }

  Selection results = new BitmapBackedSelection();
  for (int i = 0; i < values.size(); i++) {
    if (keys.contains(values.getInt(i))) {
      results.add(i);
    }
  }
  return results;
}
 
Example 7
Source File: BertWordPiecePreProcessor.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param lowerCase If true: tokenization should convert all characters to lower case
 * @param stripAccents  If true: strip accents off characters. Usually same as lower case. Should be true when using "uncased" official BERT TensorFlow models
 */
public BertWordPiecePreProcessor(boolean lowerCase, boolean stripAccents, Map<String,Integer> vocab){
    this.lowerCase = lowerCase;
    this.stripAccents = stripAccents;
    if(vocab != null) {
        charSet = new IntOpenHashSet();
        for (String s : vocab.keySet()) {
            int cpNum = 0;
            int n = s.codePointCount(0, s.length());
            int charOffset = 0;
            while (cpNum++ < n) {
                int cp = s.codePointAt(charOffset);
                charOffset += Character.charCount(cp);
                charSet.add(cp);
            }
        }
    } else {
        charSet = null;
    }
}
 
Example 8
Source File: DatasetWikiIdExporter.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
private IntOpenHashSet analyzeAsC2W(DatasetConfiguration config) throws GerbilException {
    D2WDataset dataset = (D2WDataset) config.getDataset(ExperimentType.D2KB);
    if (dataset == null) {
        return null;
    }
    List<HashSet<Annotation>> goldStandard = dataset.getD2WGoldStandardList();
    IntOpenHashSet ids = new IntOpenHashSet();
    for (HashSet<Annotation> annotations : goldStandard) {
        for (Annotation annotation : annotations) {
            ids.add(annotation.getConcept());
        }
    }
    return ids;
}
 
Example 9
Source File: InPredicateEvaluatorFactory.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
IntRawValueBasedInPredicateEvaluator(InPredicate inPredicate) {
  List<String> values = inPredicate.getValues();
  _matchingValues = new IntOpenHashSet(HashUtil.getMinHashSetSize(values.size()));
  for (String value : values) {
    _matchingValues.add(Integer.parseInt(value));
  }
}
 
Example 10
Source File: NotInPredicateEvaluatorFactory.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
IntRawValueBasedNotInPredicateEvaluator(NotInPredicate notInPredicate) {
  List<String> values = notInPredicate.getValues();
  _nonMatchingValues = new IntOpenHashSet(HashUtil.getMinHashSetSize(values.size()));
  for (String value : values) {
    _nonMatchingValues.add(Integer.parseInt(value));
  }
}
 
Example 11
Source File: DatasetWikiIdExporter.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
private IntOpenHashSet analyzeAsD2W(DatasetConfiguration config) throws GerbilException {
    C2WDataset dataset = (C2WDataset) config.getDataset(ExperimentType.C2KB);
    if (dataset == null) {
        return null;
    }
    List<HashSet<Tag>> goldStandard = dataset.getC2WGoldStandardList();
    IntOpenHashSet ids = new IntOpenHashSet();
    for (HashSet<Tag> tags : goldStandard) {
        for (Tag tag : tags) {
            ids.add(tag.getConcept());
        }
    }
    return ids;
}
 
Example 12
Source File: IgnoreWIDs.java    From tagme with Apache License 2.0 5 votes vote down vote up
@Override
protected IntSet parseSet() throws IOException
{
	log.info("Loading data...");
	Object2IntMap<String> titles = new TitlesToWIDMap(lang).getDataset();
	IntOpenHashSet ids = new IntOpenHashSet(titles.size());
	
	Pattern p_date = WikiPatterns.getPattern(lang, Type.PAGE_DATE);
	Pattern p_other = WikiPatterns.getPattern(lang, Type.PAGE_IGNORE);
	
	PLogger plog = new PLogger(log,"titles","dates","others").setEnd(0, titles.size()).start("Parsing ignore-pages...");
	for(String title : titles.keySet())
	{
		plog.update(0);
		if (p_date.matcher(title).find()) {
			plog.update(1);
			ids.add(titles.get(title));
		}
		else if (p_other.matcher(title).find()) {
			plog.update(2);
			ids.add(titles.get(title));
		}
	}
	plog.stop();
	
	ids.trim();
	return ids;
}
 
Example 13
Source File: GlobalVisitStats.java    From fasten with Apache License 2.0 4 votes vote down vote up
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 14
Source File: AggregationGroupByTrimmingServiceTest.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@Test
public void testTrimming() {
  // Test Server side trimming
  Map<String, Object[]> intermediateResultsMap = new HashMap<>(NUM_GROUPS);
  for (int i = 0; i < NUM_GROUPS; i++) {
    IntOpenHashSet set = new IntOpenHashSet();
    for (int j = 0; j <= i; j += NUM_GROUPS / MAX_SIZE_OF_SET) {
      set.add(j);
    }
    intermediateResultsMap.put(_groups.get(i), new Object[]{(double) i, set});
  }
  List<Map<String, Object>> trimmedIntermediateResultMaps =
      _trimmingService.trimIntermediateResultsMap(intermediateResultsMap);
  Map<String, Object> trimmedSumResultMap = trimmedIntermediateResultMaps.get(0);
  Map<String, Object> trimmedDistinctCountResultMap = trimmedIntermediateResultMaps.get(1);
  int trimSize = trimmedSumResultMap.size();
  Assert.assertEquals(trimmedDistinctCountResultMap.size(), trimSize, ERROR_MESSAGE);
  for (int i = NUM_GROUPS - trimSize; i < NUM_GROUPS; i++) {
    String group = _groups.get(i);
    Assert.assertEquals(((Double) trimmedSumResultMap.get(group)).intValue(), i, ERROR_MESSAGE);
    Assert.assertEquals(((IntOpenHashSet) trimmedDistinctCountResultMap.get(group)).size(),
        i / (NUM_GROUPS / MAX_SIZE_OF_SET) + 1, ERROR_MESSAGE);
  }

  // Test Broker side trimming
  Map<String, Comparable> finalDistinctCountResultMap = new HashMap<>(trimSize);
  for (Map.Entry<String, Object> entry : trimmedDistinctCountResultMap.entrySet()) {
    finalDistinctCountResultMap.put(entry.getKey(), ((IntOpenHashSet) entry.getValue()).size());
  }
  List[] groupByResultLists =
      _trimmingService.trimFinalResults(new Map[]{trimmedSumResultMap, finalDistinctCountResultMap});
  List<GroupByResult> sumGroupByResultList = groupByResultLists[0];
  List<GroupByResult> distinctCountGroupByResultList = groupByResultLists[1];
  for (int i = 0; i < GROUP_BY_TOP_N; i++) {
    int expectedGroupIndex = NUM_GROUPS - 1 - i;
    GroupByResult sumGroupByResult = sumGroupByResultList.get(i);
    List<String> sumGroup = sumGroupByResult.getGroup();
    Assert.assertEquals(sumGroup.size(), NUM_GROUP_KEYS, ERROR_MESSAGE);
    Assert.assertEquals(buildGroupString(sumGroup), _groups.get(expectedGroupIndex), ERROR_MESSAGE);
    Double value = (Double) sumGroupByResult.getValue();
    Assert.assertEquals(value.intValue(), expectedGroupIndex, ERROR_MESSAGE);
    // For distinctCount, because multiple groups have same value, so there is no guarantee on the order of groups,
    // just check the value
    GroupByResult distinctCountGroupByResult = distinctCountGroupByResultList.get(i);
    Assert
        .assertEquals(distinctCountGroupByResult.getValue(), expectedGroupIndex / (NUM_GROUPS / MAX_SIZE_OF_SET) + 1,
            ERROR_MESSAGE);
  }
}
 
Example 15
Source File: NotInPredicateFilter.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public NotInPredicateFilter(Dictionary dictionary, List<String> values) {
  _notInSet = new IntOpenHashSet(values.size());
  for (String value : values) {
    _notInSet.add(dictionary.indexOf(value));
  }
}
 
Example 16
Source File: ImmutableDictionaryTypeConversionTest.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@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][];
}
 
Example 17
Source File: MappingData.java    From ViaVersion with MIT License 4 votes vote down vote up
public static void init() {
    Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 mappings...");
    JsonObject mapping1_13_2 = MappingDataLoader.loadData("mapping-1.13.2.json", true);
    JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json", true);

    oldToNewItems.defaultReturnValue(-1);
    blockStateMappings = new Mappings(mapping1_13_2.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"));
    blockMappings = new Mappings(mapping1_13_2.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"));
    MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_13_2.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"));
    soundMappings = new Mappings(mapping1_13_2.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"));

    JsonObject blockStates = mapping1_14.getAsJsonObject("blockstates");
    Map<String, Integer> blockStateMap = new HashMap<>(blockStates.entrySet().size());
    for (Map.Entry<String, JsonElement> entry : blockStates.entrySet()) {
        blockStateMap.put(entry.getValue().getAsString(), Integer.parseInt(entry.getKey()));
    }

    JsonObject heightMapData = MappingDataLoader.loadData("heightMapData-1.14.json");
    JsonArray motionBlocking = heightMapData.getAsJsonArray("MOTION_BLOCKING");
    MappingData.motionBlocking = new IntOpenHashSet(motionBlocking.size(), 1F);
    for (JsonElement blockState : motionBlocking) {
        String key = blockState.getAsString();
        Integer id = blockStateMap.get(key);
        if (id == null) {
            Via.getPlatform().getLogger().warning("Unknown blockstate " + key + " :(");
        } else {
            MappingData.motionBlocking.add(id.intValue());
        }
    }

    if (Via.getConfig().isNonFullBlockLightFix()) {
        nonFullBlocks = new IntOpenHashSet(1611, 1F);
        for (Map.Entry<String, JsonElement> blockstates : mapping1_13_2.getAsJsonObject("blockstates").entrySet()) {
            final String state = blockstates.getValue().getAsString();
            if (state.contains("_slab") || state.contains("_stairs") || state.contains("_wall["))
                nonFullBlocks.add(blockStateMappings.getNewId(Integer.parseInt(blockstates.getKey())));
        }
        nonFullBlocks.add(blockStateMappings.getNewId(8163)); // grass path
        for (int i = 3060; i <= 3067; i++) { // farmland
            nonFullBlocks.add(blockStateMappings.getNewId(i));
        }
    }
}
 
Example 18
Source File: TableResizerTest.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public void setUp() {
  _dataSchema = new DataSchema(new String[]{"d1", "d2", "d3", "sum(m1)", "max(m2)", "distinctcount(m3)", "avg(m4)"},
      new DataSchema.ColumnDataType[]{DataSchema.ColumnDataType.STRING, DataSchema.ColumnDataType.INT, DataSchema.ColumnDataType.DOUBLE, DataSchema.ColumnDataType.DOUBLE, DataSchema.ColumnDataType.DOUBLE, DataSchema.ColumnDataType.OBJECT, DataSchema.ColumnDataType.OBJECT});
  _aggregationFunctions = new AggregationFunction[]{new SumAggregationFunction(
      ExpressionContext.forIdentifier("m1")), new MaxAggregationFunction(
      ExpressionContext.forIdentifier("m2")), new DistinctCountAggregationFunction(
      ExpressionContext.forIdentifier("m3")), new AvgAggregationFunction(ExpressionContext.forIdentifier("m4"))};

  IntOpenHashSet i1 = new IntOpenHashSet();
  i1.add(1);
  IntOpenHashSet i2 = new IntOpenHashSet();
  i2.add(1);
  i2.add(2);
  IntOpenHashSet i3 = new IntOpenHashSet();
  i3.add(1);
  i3.add(2);
  IntOpenHashSet i4 = new IntOpenHashSet();
  i4.add(1);
  i4.add(2);
  i4.add(3);
  IntOpenHashSet i5 = new IntOpenHashSet();
  i5.add(1);
  i5.add(2);
  i5.add(3);
  i5.add(4);
  _records = Lists.newArrayList(new Record(new Object[]{"a", 10, 1.0, 10, 100, i1, new AvgPair(10, 2) /* 5 */}),
      new Record(new Object[]{"b", 10, 2.0, 20, 200, i2, new AvgPair(10, 3) /* 3.33 */}),
      new Record(new Object[]{"c", 200, 3.0, 30, 300, i3, new AvgPair(20, 4) /* 5 */}),
      new Record(new Object[]{"c", 50, 4.0, 30, 200, i4, new AvgPair(30, 10) /* 3 */}),
      new Record(new Object[]{"c", 300, 5.0, 20, 100, i5, new AvgPair(10, 5) /* 2 */}));

  _keys = Lists.newArrayList(new Key(new Object[]{"a", 10, 1.0}), new Key(new Object[]{"b", 10, 2.0}),
      new Key(new Object[]{"c", 200, 3.0}), new Key(new Object[]{"c", 50, 4.0}),
      new Key(new Object[]{"c", 300, 5.0}));
  _recordsMap = new HashMap<>();
  for (int i = 0; i < _records.size(); i++) {
    _recordsMap.put(_keys.get(i), _records.get(i));
  }
  /*_recordsMap = new HashMap<>();
  _recordsMap.put(new Key(new Object[]{"a", 10, 1.0}), new Record(new Object[]{"a", 10, 1.0,10, 100, i1, new AvgPair(10, 2) *//* 5 *//*}));
  _recordsMap.put(new Key(new Object[]{"b", 10, 2.0}), new Record(new Object[]{"b", 10, 2.0,20, 200, i2, new AvgPair(10, 3) *//* 3.33 *//*}));
  _recordsMap.put(new Key(new Object[]{"c", 200, 3.0}),new Record(new Object[]{"c", 200, 3.0,30, 300, i3, new AvgPair(20, 4) *//* 5 *//*}));
  _recordsMap.put(new Key(new Object[]{"c", 50, 4.0}), new Record(new Object[]{"c", 50, 4.0,30, 200, i4, new AvgPair(30, 10) *//* 3 *//*}));
  _recordsMap.put(new Key(new Object[]{"c", 300, 5.0}), new Record(new Object[]{"c", 300, 5.0,20, 100, i5, new AvgPair(10, 5) *//* 2 *//*}));
   */
}
 
Example 19
Source File: GlobalVisitStats.java    From fasten with Apache License 2.0 4 votes vote down vote up
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 20
Source File: DistinctCountAggregationFunction.java    From incubator-pinot with Apache License 2.0 2 votes vote down vote up
/**
 * Helper method to set value for a groupKey into the result holder.
 *
 * @param groupByResultHolder Result holder
 * @param groupKey Group-key for which to set the value
 * @param value Value for the group key
 */
private void setValueForGroupKey(GroupByResultHolder groupByResultHolder, int groupKey, int value) {
  IntOpenHashSet valueSet = getValueSet(groupByResultHolder, groupKey);
  valueSet.add(value);
}