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

The following examples show how to use it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap. 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 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 #2
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 #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: OnHeapLongDictionary.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for the class.
 * Populates the value <-> mappings.
 *
 * @param dataBuffer Pinot data buffer
 * @param length Length of the dictionary
 */
public OnHeapLongDictionary(PinotDataBuffer dataBuffer, int length) {
  super(dataBuffer, length, Long.BYTES, (byte) 0);

  _valToDictId = new Long2IntOpenHashMap(length);
  _valToDictId.defaultReturnValue(NULL_VALUE_INDEX);
  _dictIdToVal = new long[length];

  for (int dictId = 0; dictId < length; dictId++) {
    long value = getLong(dictId);
    _dictIdToVal[dictId] = value;
    _valToDictId.put(value, dictId);
  }
}
 
Example #5
Source File: NoDictionarySingleColumnGroupKeyGenerator.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to create the group-key map, depending on the data type.
 * Uses primitive maps when possible.
 *
 * @param keyType DataType for the key
 * @return Map
 */
private Map createGroupKeyMap(FieldSpec.DataType keyType) {
  Map map;
  switch (keyType) {
    case INT:
      Int2IntMap intMap = new Int2IntOpenHashMap();
      intMap.defaultReturnValue(INVALID_ID);
      map = intMap;
      break;

    case LONG:
      Long2IntOpenHashMap longMap = new Long2IntOpenHashMap();
      longMap.defaultReturnValue(INVALID_ID);
      map = longMap;
      break;

    case FLOAT:
      Float2IntOpenHashMap floatMap = new Float2IntOpenHashMap();
      floatMap.defaultReturnValue(INVALID_ID);
      map = floatMap;
      break;

    case DOUBLE:
      Double2IntOpenHashMap doubleMap = new Double2IntOpenHashMap();
      doubleMap.defaultReturnValue(INVALID_ID);
      map = doubleMap;
      break;

    case STRING:
      Object2IntOpenHashMap<String> stringMap = new Object2IntOpenHashMap<>();
      stringMap.defaultReturnValue(INVALID_ID);
      map = stringMap;
      break;

    default:
      throw new IllegalArgumentException("Illegal data type for no-dictionary key generator: " + keyType);
  }
  return map;
}
 
Example #6
Source File: KnowledgeBase.java    From fasten with Apache License 2.0 5 votes vote down vote up
public CallGraphData(final ImmutableGraph graph, final ImmutableGraph transpose, final Properties graphProperties, final Properties transposeProperties, final long[] LID2GID, final Long2IntOpenHashMap GID2LID, final int nInternal, final int size) {
	super();
	this.graph = graph;
	this.transpose = transpose;
	this.graphProperties = graphProperties;
	this.transposeProperties = transposeProperties;
	this.LID2GID = LID2GID;
	this.GID2LID = GID2LID;
	this.externalNodes = new LongOpenHashSet(Arrays.copyOfRange(LID2GID, nInternal, LID2GID.length));
	this.size = size;
}
 
Example #7
Source File: CommonInternalState.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
/**
 * Get a new instance of a fresh internal state.
 *
 * @param salsaStats          is the stats object to use
 * @param expectedNodesToHit  is the number of nodes the random walk is expected to hit
 */
public CommonInternalState(
    SalsaStats salsaStats,
    int expectedNodesToHit) {
  this.salsaStats = salsaStats;
  this.currentLeftNodes = new Long2IntOpenHashMap(expectedNodesToHit);
  this.currentRightNodes = new Long2IntOpenHashMap(expectedNodesToHit);
  this.visitedRightNodes = new Long2ObjectOpenHashMap<NodeInfo>(expectedNodesToHit);
  this.nonZeroSeedSet = new LongOpenHashSet(expectedNodesToHit);
}
 
Example #8
Source File: RocksDao.java    From fasten with Apache License 2.0 5 votes vote down vote up
private void initKryo() {
      kryo = new Kryo();
      kryo.register(BVGraph.class, new BVGraphSerializer(kryo));
kryo.register(Boolean.class);
      kryo.register(byte[].class);
      kryo.register(InputBitStream.class);
      kryo.register(NullInputStream.class);
      kryo.register(EliasFanoMonotoneLongBigList.class, new JavaSerializer());
      kryo.register(MutableString.class, new FieldSerializer<>(kryo, MutableString.class));
      kryo.register(Properties.class);
      kryo.register(long[].class);
      kryo.register(Long2IntOpenHashMap.class);
kryo.register(GOV3LongFunction.class, new JavaSerializer());
  }
 
Example #9
Source File: KnowledgeBase.java    From fasten with Apache License 2.0 5 votes vote down vote up
/** Initializes the kryo instance used for serialization. */
private void initKryo() {
	kryo = new Kryo();
	kryo.register(BVGraph.class, new BVGraphSerializer(kryo));
	kryo.register(byte[].class);
	kryo.register(InputBitStream.class);
	kryo.register(NullInputStream.class);
	kryo.register(EliasFanoMonotoneLongBigList.class, new JavaSerializer());
	kryo.register(MutableString.class, new FieldSerializer<>(kryo, MutableString.class));
	kryo.register(Properties.class);
	kryo.register(long[].class);
	kryo.register(Long2IntOpenHashMap.class);
}
 
Example #10
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 #11
Source File: UnionFindMapStorage.java    From graph_processing with MIT License 4 votes vote down vote up
public UnionFindMapStorage(GraphDatabaseService db) {
    this.db = db;
    this.rootMap = new Long2LongOpenHashMap();
    this.rankMap = new Long2IntOpenHashMap();
    this.nodes = new NodeCounter().getNodeCount(db);
}
 
Example #12
Source File: PerfectFrequency.java    From caffeine with Apache License 2.0 4 votes vote down vote up
public PerfectFrequency(Config config) {
  sampleSize = 10 * new BasicSettings(config).maximumSize();
  counts = new Long2IntOpenHashMap();
}
 
Example #13
Source File: DictionaryBasedGroupKeyGenerator.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public LongMapBasedHolder(int initialSize) {
  _rawKeyToGroupIdMap = new Long2IntOpenHashMap(initialSize);
  _rawKeyToGroupIdMap.defaultReturnValue(INVALID_ID);
}
 
Example #14
Source File: DictionaryBasedGroupKeyGenerator.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public LongMapBasedHolder(Object rawKeyToGroupIdMap) {
  _rawKeyToGroupIdMap = (Long2IntOpenHashMap) rawKeyToGroupIdMap;
  _rawKeyToGroupIdMap.clear();
}
 
Example #15
Source File: LongToIdMap.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public LongToIdMap() {
  _valueToIdMap = new Long2IntOpenHashMap();
  _valueToIdMap.defaultReturnValue(INVALID_KEY);
  _idToValueMap = new LongArrayList();
}
 
Example #16
Source File: ArrayImmutableDirectedGraph.java    From fasten with Apache License 2.0 4 votes vote down vote up
protected ArrayImmutableDirectedGraph(final Long2IntOpenHashMap GID2Offset, final long[] succpred, final LongOpenHashSet externalNodes) {
	this.GID2Offset = GID2Offset;
	this.succpred = succpred;
	this.externalNodes = externalNodes;
}
 
Example #17
Source File: DynamicTranslationModel.java    From phrasal with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructor.
 * 
 * @param initialCapacity
 */
public LexCoocTable(int initialCapacity) {
  counts = new Long2IntOpenHashMap(initialCapacity);
  counts.defaultReturnValue(0);
}