it.unimi.dsi.fastutil.longs.Long2IntMap Java Examples

The following examples show how to use it.unimi.dsi.fastutil.longs.Long2IntMap. 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: SalsaIterationsTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testSeedIteration() throws Exception {
  SalsaIterations<BipartiteGraph> salsaIterations = new SalsaIterations<BipartiteGraph>(
      salsaInternalState,
      new LeftSalsaIteration(salsaInternalState),
      new RightSalsaIteration(salsaInternalState),
      new FinalSalsaIteration(salsaInternalState)
  );
  salsaIterations.resetWithRequest(salsaRequest, random);

  salsaIterations.seedLeftSideForFirstIteration();

  Long2IntMap expectedCurrentLeftNodes = new Long2IntOpenHashMap(3);
  expectedCurrentLeftNodes.put(1, 900);
  expectedCurrentLeftNodes.put(2, 91);
  expectedCurrentLeftNodes.put(3, 10);

  assertEquals(expectedCurrentLeftNodes, salsaInternalState.getCurrentLeftNodes());
}
 
Example #2
Source File: SalsaIterationsTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonZeroDegreeSeedIteration() throws Exception {
  SalsaIterations<BipartiteGraph> salsaIterations = new SalsaIterations<BipartiteGraph>(
      salsaInternalStateSmallSeed,
      new LeftSalsaIteration(salsaInternalStateSmallSeed),
      new RightSalsaIteration(salsaInternalStateSmallSeed),
      new FinalSalsaIteration(salsaInternalStateSmallSeed)
  );
  salsaIterations.resetWithRequest(salsaRequestSmallSeed, random);

  salsaIterations.seedLeftSideForFirstIteration();

  Long2IntMap expectedCurrentLeftNodes = new Long2IntOpenHashMap(1);
  expectedCurrentLeftNodes.put(1, 1000);

  assertEquals(expectedCurrentLeftNodes, salsaInternalStateSmallSeed.getCurrentLeftNodes());
}
 
Example #3
Source File: SalsaIterationsTest.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleRightIteration() throws Exception {
  SalsaIterations<BipartiteGraph> salsaIterations = new SalsaIterations<BipartiteGraph>(
      salsaInternalState,
      new LeftSalsaIteration(salsaInternalState),
      new RightSalsaIteration(salsaInternalState),
      new FinalSalsaIteration(salsaInternalState)
  );
  salsaIterations.resetWithRequest(salsaRequest, random);
  SingleSalsaIteration leftSalsaIteration =
      new LeftSalsaIteration(salsaInternalState);
  leftSalsaIteration.resetWithRequest(salsaRequest, random);
  SingleSalsaIteration rightSalsaIteration =
      new RightSalsaIteration(salsaInternalState);
  rightSalsaIteration.resetWithRequest(salsaRequest, random);

  salsaIterations.seedLeftSideForFirstIteration();
  leftSalsaIteration.runSingleIteration();
  rightSalsaIteration.runSingleIteration();

  Long2IntMap expectedCurrentLeftNodes = new Long2IntOpenHashMap(3);
  expectedCurrentLeftNodes.put(1, 728);
  expectedCurrentLeftNodes.put(2, 86);
  expectedCurrentLeftNodes.put(3, 187);

  assertTrue(salsaInternalState.getCurrentRightNodes().isEmpty());
  assertEquals(expectedCurrentLeftNodes, salsaInternalState.getCurrentLeftNodes());
}
 
Example #4
Source File: DictionaryBasedGroupKeyGenerator.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Iterator<GroupKey> iterator() {
  return new Iterator<GroupKey>() {
    private final ObjectIterator<Long2IntMap.Entry> _iterator =
        _rawKeyToGroupIdMap.long2IntEntrySet().fastIterator();
    private final GroupKey _groupKey = new GroupKey();

    @Override
    public boolean hasNext() {
      return _iterator.hasNext();
    }

    @Override
    public GroupKey next() {
      Long2IntMap.Entry entry = _iterator.next();
      _groupKey._groupId = entry.getIntValue();
      _groupKey._stringKey = getGroupKey(entry.getLongKey());
      return _groupKey;
    }

    @Override
    public void remove() {
      throw new UnsupportedOperationException();
    }
  };
}
 
Example #5
Source File: NoDictionarySingleColumnGroupKeyGenerator.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private int getKeyForValue(long value) {
  Long2IntMap map = (Long2IntMap) _groupKeyMap;
  int groupId = map.get(value);
  if (groupId == INVALID_ID) {
    if (_numGroups < _globalGroupIdUpperBound) {
      groupId = _numGroups;
      map.put(value, _numGroups++);
    }
  }
  return groupId;
}
 
Example #6
Source File: CommonInternalState.java    From GraphJet with Apache License 2.0 4 votes vote down vote up
public Long2IntMap getCurrentLeftNodes() {
  return currentLeftNodes;
}
 
Example #7
Source File: CommonInternalState.java    From GraphJet with Apache License 2.0 4 votes vote down vote up
public Long2IntMap getCurrentRightNodes() {
  return currentRightNodes;
}
 
Example #8
Source File: PowerLawDegreeEdgeRandomIteratorTest.java    From GraphJet with Apache License 2.0 4 votes vote down vote up
@Test
public void testPowerLawDegreeEdgeIterator() throws Exception {
  int maxNumNodes = 4;
  int maxDegree = 6;
  PowerLawDegreeEdgePool powerLawDegreeEdgePool =
      new PowerLawDegreeEdgePool(maxNumNodes, maxDegree, 2.0, new NullStatsReceiver());

  addEdgesToPool(powerLawDegreeEdgePool);

  PowerLawDegreeEdgeRandomIterator powerLawDegreeEdgeRandomIterator =
      new PowerLawDegreeEdgeRandomIterator(powerLawDegreeEdgePool);

  Random random = new Random(90238490238409L);
  int numSamples = 5;

  powerLawDegreeEdgeRandomIterator.resetForNode(1, numSamples, random);
  assertEquals(new IntArrayList(new int[]{13, 13, 11, 15, 14}),
      new IntArrayList(powerLawDegreeEdgeRandomIterator));
  powerLawDegreeEdgeRandomIterator.resetForNode(2, numSamples, random);
  assertEquals(new IntArrayList(new int[]{22, 22, 21, 23, 22}),
      new IntArrayList(powerLawDegreeEdgeRandomIterator));
  powerLawDegreeEdgeRandomIterator.resetForNode(3, numSamples, random);
  assertEquals(new IntArrayList(new int[]{31, 31, 31, 31, 31}),
      new IntArrayList(powerLawDegreeEdgeRandomIterator));
  powerLawDegreeEdgeRandomIterator.resetForNode(4, numSamples, random);
  assertEquals(new IntArrayList(new int[]{43, 41, 43, 41, 42}),
      new IntArrayList(powerLawDegreeEdgeRandomIterator));
  powerLawDegreeEdgeRandomIterator.resetForNode(5, numSamples, random);
  assertEquals(new IntArrayList(new int[]{51, 51, 51, 51, 51}),
      new IntArrayList(powerLawDegreeEdgeRandomIterator));

  // Test a larger sample
  powerLawDegreeEdgeRandomIterator.resetForNode(4, 900, random);
  Long2IntMap occurrenceCounts = new Long2IntOpenHashMap(3);
  for (int sample : new IntArrayList(powerLawDegreeEdgeRandomIterator)) {
    occurrenceCounts.put(sample, occurrenceCounts.get(sample) + 1);
  }
  assertEquals(301, occurrenceCounts.get(41));
  assertEquals(296, occurrenceCounts.get(42));
  assertEquals(303, occurrenceCounts.get(43));
}
 
Example #9
Source File: PerfectFrequency.java    From caffeine with Apache License 2.0 4 votes vote down vote up
private void reset() {
  for (Long2IntMap.Entry entry : counts.long2IntEntrySet()) {
    entry.setValue(entry.getIntValue() / 2);
  }
  size = (size / 2);
}