Java Code Examples for gnu.trove.map.hash.TIntIntHashMap#put()

The following examples show how to use gnu.trove.map.hash.TIntIntHashMap#put() . 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: Bench.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static List<Collection<Node>> makeEdges(List<Node> l, int switchSize) {
    TIntIntHashMap parts = new TIntIntHashMap();
    int curPart = 0;
    int i = 0;
    for (Node n : l) {
        i = (i + 1) % switchSize;
        if ((i + 1) % switchSize == 0) {
            curPart++;
        }
        parts.put(n.id(), curPart);
    }
    SplittableElementSet<Node> sp = SplittableElementSet.newNodeIndex(l, parts);
    final List<Collection<Node>> splits = new ArrayList<>();
    sp.forEachPartition((index, key, from, to) -> splits.add(new ElementSubSet<>(index, key, from, to)));
    return splits;
}
 
Example 2
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
public TIntObjectHashMap<TIntIntHashMap> getEntityKeyphraseIntersectionCount(Entities entities) throws EntityLinkingDataAccessException {
  TIntObjectHashMap<TIntIntHashMap> isec = new TIntObjectHashMap<TIntIntHashMap>();
  for (String[] eKps : allEntityKeyphrases) {
    int entity = DataAccess.getInternalIdForKBEntity(getTestKBEntity(eKps[0]));
    TIntIntHashMap counts = new TIntIntHashMap();
    isec.put(entity, counts);

    if (eKps.length > 1) {
      int currentKp = -1;
      for (int i = 1; i < eKps.length; ++i) {
        if (i % 2 == 1) {
          currentKp = DataAccess.getIdForWord(eKps[i]);
        } else {
          int count = Integer.parseInt(eKps[i]);
          counts.put(currentKp, count);
        }
      }
    }
  }
  return isec;
}
 
Example 3
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private TIntIntHashMap getKeywordDocumentFrequencies(TIntHashSet keywords) throws EntityLinkingDataAccessException {
  TIntIntHashMap freqs = new TIntIntHashMap();
  for (String[] kpF : allKeyphraseFrequencies) {
    String[] tokens = kpF[0].split(" ");
    int freq = Integer.parseInt(kpF[1]);
    for (String token : tokens) {
      freqs.put(DataAccess.getIdForWord(token), freq);
    }
  }

  for (int kw : keywords.toArray()) {
    if (!freqs.containsKey(kw)) {
      System.err.println("allKeyphraseFrequencies do not contain token '" + DataAccess.getWordForId(kw) + "'");
    }
  }

  return freqs;
}
 
Example 4
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
@Override public TIntIntHashMap getEntitySuperdocSize(Entities entities) throws EntityLinkingDataAccessException {
  TIntIntHashMap sizes = new TIntIntHashMap();
  for (String entity[] : allEntitySizes) {
    int id = DataAccess.getInternalIdForKBEntity(getTestKBEntity(entity[0]));
    int size = Integer.parseInt(entity[1]);
    sizes.put(id, size);
  }

  for (Entity e : entities) {
    if (!sizes.containsKey(e.getId())) {
      System.err.println("allEntitySizes does not contain '" + e);
    }
  }

  return sizes;
}
 
Example 5
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
@Override public TIntIntHashMap getKeyphraseDocumentFrequencies(TIntHashSet keyphrases) throws EntityLinkingDataAccessException {
  TIntIntHashMap freqs = new TIntIntHashMap();
  for (String[] kpF : allKeyphraseFrequencies) {
    int keyphrase = DataAccess.getIdForWord(kpF[0]);
    int freq = Integer.parseInt(kpF[1]);
    freqs.put(keyphrase, freq);
  }

  for (int kp : keyphrases.toArray()) {
    if (!freqs.containsKey(kp)) {
      System.err.println("allKeyphraseFrequencies does not contain '" + DataAccess.getWordForId(kp) + "'");
    }
  }

  return freqs;
}
 
Example 6
Source File: SplittableElementSetTest.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test(dependsOnMethods = "testNewVMSet")
public void testGetPartitions() {
    List<VM> l = new ArrayList<>();
    final TIntIntHashMap index = new TIntIntHashMap();
    for (int i = 0; i < 10; i++) {
        l.add(new VM(i));
        index.put(i, i % 2);
    }
    SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, index);
    //check each partition contains element having the same partition key.
    List<ElementSubSet<VM>> ss = s.getPartitions();
    for (ElementSubSet<VM> sub : ss) {
        Iterator<VM> ite = sub.iterator();
        int partKey = index.get(ite.next().id());
        while (ite.hasNext()) {
            Assert.assertEquals(index.get(ite.next().id()), partKey);
        }
    }
    Assert.assertEquals(s.size(), 10);
    Assert.assertEquals(ss.size(), 2);
}
 
Example 7
Source File: SplittableElementSetTest.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test(dependsOnMethods = "testNewVMSet")
public void testOrdering() {
    List<VM> l = new ArrayList<>();
    final TIntIntHashMap index = new TIntIntHashMap();
    Random rnd = new Random();
    for (int i = 0; i < 10; i++) {
        l.add(new VM(i));
        index.put(i, rnd.nextInt(3));
    }
    SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, index);
    System.err.println(s);
    List<VM> values = s.getValues();
    for (int i = 0; i < values.size() - 1; i++) {
        Assert.assertTrue(index.get(values.get(i).id()) <= index.get(values.get(i + 1).id()));
    }
}
 
Example 8
Source File: MaterializeMIWeights.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private TIntIntHashMap getCounts(String table, String key) throws SQLException {
  TIntIntHashMap counts = new TIntIntHashMap();
  Connection con = EntityLinkingManager.getConnectionForDatabase(EntityLinkingManager.DB_AIDA);
  Statement stmt = con.createStatement();
  con.setAutoCommit(false);
  stmt.setFetchSize(1000000);
  ResultSet rs = stmt.executeQuery("SELECT " + key + ",count FROM " + table);
  while (rs.next()) {
    int keyThing = rs.getInt(key);
    int count = rs.getInt("count");
    counts.put(keyThing, count);
  }
  con.setAutoCommit(true);
  EntityLinkingManager.releaseConnection(con);
  return counts;
}
 
Example 9
Source File: ConnectedComponentsDemo.java    From COMP3204 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void merge(TIntIntHashMap linked, int start, int target) {
	if (start == target)
		return;

	final int old = linked.get(start);

	if (old > target) {
		linked.put(start, target);
		merge(linked, old, target);
	} else {
		merge(linked, target, old);
	}
}
 
Example 10
Source File: ElementSubSetTest.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
    Model mo = new DefaultModel();
    List<VM> l = new ArrayList<>();
    final TIntIntHashMap index = new TIntIntHashMap();

    for (int i = 0; i < 10; i++) {
        l.add(mo.newVM());
        index.put(i, i % 2);
    }

    SplittableElementSet<VM> si = SplittableElementSet.newVMIndex(l, index);
    List<VM> values = si.getValues();

    ElementSubSet<VM> p1 = new ElementSubSet<>(si, 0, 0, 5);
    //test contains()
    Assert.assertTrue(p1.contains(values.get(0)));
    Assert.assertFalse(p1.contains(values.get(5)));

    //test containsAll()
    Assert.assertFalse(p1.containsAll(l));

    //test size()
    Assert.assertEquals(p1.size(), 5);
    Assert.assertFalse(p1.isEmpty());

    System.out.println(p1);
    //test iterator
    for (VM v : p1) {
        Assert.assertEquals(v.id() % 2, 0);
    }
}
 
Example 11
Source File: SplittableElementSetTest.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testNewNodeSet() {
    List<Node> l = new ArrayList<>();
    TIntIntHashMap m = new TIntIntHashMap();
    for (int i = 0; i < 10; i++) {
        l.add(new Node(i));
        m.put(i, i % 2);
    }
    SplittableElementSet<Node> s = SplittableElementSet.newNodeIndex(l, m);
    for (Node v : s.getValues()) {
        Assert.assertTrue(v.id() >= 0 && v.id() < 10);
    }
    Assert.assertEquals(s.size(), l.size());
    Assert.assertEquals(s.getRespectiveIndex(), m);
}
 
Example 12
Source File: SplittableElementSetTest.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testNewVMSet() {
    List<VM> l = new ArrayList<>();
    TIntIntHashMap m = new TIntIntHashMap();
    for (int i = 0; i < 10; i++) {
        l.add(new VM(i));
        m.put(i, i % 2);
    }
    SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, m);
    for (VM v : s.getValues()) {
        Assert.assertTrue(v.id() >= 0 && v.id() < 10);
    }
    Assert.assertEquals(s.size(), l.size());
    Assert.assertEquals(s.getRespectiveIndex(), m);
}
 
Example 13
Source File: AliasedCumulativesFiltering.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Translation for a relatives resources changes to an absolute free resources.
 *
 * @param changes       the map that indicates the free CPU variation
 * @param sortedMoments the different moments sorted in ascending order
 */
private static void toAbsoluteFreeResources(TIntIntHashMap changes, int[] sortedMoments) {
    for (int i = 1; i < sortedMoments.length; i++) {
        int t = sortedMoments[i];
        int lastT = sortedMoments[i - 1];
        int lastFree = changes.get(lastT);

        changes.put(t, changes.get(t) + lastFree);
    }
}
 
Example 14
Source File: LocalTaskScheduler.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Translation for a relatives resources changes to an absolute free resources.
 *
 * @param changes       the map that indicates the free CPU variation
 * @param sortedMoments the different moments sorted in ascending order
 */
private static void toAbsoluteFreeResources(TIntIntHashMap changes, int[] sortedMoments) {
    for (int i = 1; i < sortedMoments.length; i++) {
        int t = sortedMoments[i];
        int lastT = sortedMoments[i - 1];
        int lastFree = changes.get(lastT);

        changes.put(t, changes.get(t) + lastFree);
    }
}
 
Example 15
Source File: YagoEntityKeyphraseCooccurrenceDataProviderIteratorTest.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private TIntObjectHashMap<TIntIntHashMap> createHashMap() {
  TIntObjectHashMap<TIntIntHashMap> overallMap = new TIntObjectHashMap<TIntIntHashMap>();
  TIntIntHashMap map1 = new TIntIntHashMap();
  overallMap.put(1, map1);

  TIntIntHashMap map2 = new TIntIntHashMap();
  map2.put(21, 100);
  map2.put(22, 101);
  map2.put(23, 102);
  overallMap.put(2, map2);

  TIntIntHashMap map3 = new TIntIntHashMap();
  map3.put(31, 103);
  map3.put(32, 104);
  map3.put(33, 105);
  overallMap.put(3, map3);

  TIntIntHashMap map4 = new TIntIntHashMap();
  overallMap.put(4, map4);

  TIntIntHashMap map5 = new TIntIntHashMap();
  map5.put(51, 106);
  map5.put(52, 107);
  map5.put(53, 108);
  overallMap.put(5, map5);

  TIntIntHashMap map6 = new TIntIntHashMap();
  overallMap.put(6, map6);

  TIntIntHashMap map7 = new TIntIntHashMap();
  overallMap.put(7, map7);

  return overallMap;
}
 
Example 16
Source File: DataAccess.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public static TIntIntHashMap getUnitDocumentFrequencies(TIntSet keywords, UnitType unitType) throws EntityLinkingDataAccessException {
  logger.debug("Get Unit-document frequencies.");
  Integer runId = RunningTimer.recordStartTime("DataAccess:KWDocFreq");
  TIntIntHashMap keywordCounts = new TIntIntHashMap((int) (keywords.size() / Constants.DEFAULT_LOAD_FACTOR));
  for (TIntIterator itr = keywords.iterator(); itr.hasNext(); ) {
    int keywordId = itr.next();
    int count = DataAccessCache.singleton().getUnitCount(keywordId, unitType);
    keywordCounts.put(keywordId, count);
  }
  RunningTimer.recordEndTime("DataAccess:KWDocFreq", runId);
  return keywordCounts;
}
 
Example 17
Source File: DataAccess.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public static TIntIntHashMap getKeywordDocumentFrequencies(TIntSet keywords) throws EntityLinkingDataAccessException {
  logger.debug("Get keyword-document frequencies.");
  Integer runId = RunningTimer.recordStartTime("DataAccess:KWDocFreq");
  TIntIntHashMap keywordCounts = new TIntIntHashMap((int) (keywords.size() / Constants.DEFAULT_LOAD_FACTOR));
  for (TIntIterator itr = keywords.iterator(); itr.hasNext(); ) {
    int keywordId = itr.next();
    int count = DataAccessCache.singleton().getKeywordCount(keywordId);
    keywordCounts.put(keywordId, count);
  }
  RunningTimer.recordEndTime("DataAccess:KWDocFreq", runId);
  return keywordCounts;
}
 
Example 18
Source File: FixedNodeSetsPartitioning.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
    Model mo = i.getModel();

    SynchronizedElementBuilder eb = new SynchronizedElementBuilder(mo);

    List<Instance> parts = new ArrayList<>(partitions.size());

    //nb of VMs
    int nbVMs = i.getModel().getMapping().getNbVMs();
    int nbNodes = i.getModel().getMapping().getNbNodes();
    TIntIntHashMap vmPosition = new TIntIntHashMap(nbVMs);
    TIntIntHashMap nodePosition = new TIntIntHashMap(nbNodes);

    int partNumber = 0;

    Set<VM> toLaunch = getVMsToLaunch(i);

    for (Collection<Node> s : partitions) {
        SubModel partModel = new SubModel(mo, eb, s, new HashSet<>(toLaunch.size() / partitions.size()));

        parts.add(new Instance(partModel, new THashSet<>(), i.getOptConstraint()));

        //VM Index
        partModel.getMapping().fillVMIndex(vmPosition, partNumber);
        //Node index
        for (Node n : s) {
            nodePosition.put(n.id(), partNumber);
        }
        partNumber++;
    }

    //Round-robin placement for the VMs to launch
    int p = 0;
    for (VM v : toLaunch) {
        if (!parts.get(p).getModel().getMapping().addReadyVM(v)) {
            throw new SplitException(parts.get(p).getModel(), "Unable to dispatch the VM to launch '" + v + "'");
        }
        vmPosition.put(v.id(), p);
        p = (p + 1) % parts.size();
    }

    //Split the constraints
    for (SatConstraint cstr : i.getSatConstraints()) {
        if (!cstrMapper.split(cstr, i, parts, vmPosition, nodePosition)) {
            throw new SplitException(i.getModel(), "Unable to split " + cstr);
        }
    }

    return parts;
}
 
Example 19
Source File: TroveMapTest.java    From hashmapTest with The Unlicense 4 votes vote down vote up
@Override
public void setup(final int[] keys, final float fillFactor, int oneFailOutOf) {
    super.setup( keys, fillFactor, oneFailOutOf );
    m_map = new TIntIntHashMap( keys.length, fillFactor );
    for (int key : keys) m_map.put( key + (key % oneFailOutOf == 0 ? 1 : 0), key );
}