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

The following examples show how to use gnu.trove.map.hash.TIntIntHashMap#get() . 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: 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 2
Source File: SuperdocEntityKeyphraseCountCollector.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private void writeToFile(TIntObjectHashMap<TIntIntHashMap> superdocKeyphraseCounts) throws IOException, SQLException {
  int eCount = 0;

  logger.info("Writing entity-keyphrase pairs for " + superdocKeyphraseCounts.size() + " entities");

  for (int eid : superdocKeyphraseCounts.keys()) {

    if ((++eCount % 100000) == 0) {
      double percent = (double) eCount / (double) superdocKeyphraseCounts.size();

      logger.info("Wrote " + eCount + " entities (" + new DecimalFormat("#.##").format(percent) + ")");
    }

    TIntIntHashMap keyphraseCounts = superdocKeyphraseCounts.get(eid);

    for (int kid : keyphraseCounts.keys()) {
      int count = keyphraseCounts.get(kid);

      writer.write(eid + "\t" + kid + "\t" + String.valueOf(count));
      writer.newLine();
    }
  }
}
 
Example 3
Source File: BanSplitter.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean split(Ban cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    final SplittableElementSet<Node> nodeIndex = SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition);
    VM v = cstr.getInvolvedVMs().iterator().next();
    int p = vmsPosition.get(v.id());
    return partitions.get(p).getSatConstraints().add(new Ban(v, nodeIndex.getSubSet(p)));
}
 
Example 4
Source File: FenceSplitter.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean split(Fence cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    final SplittableElementSet<Node> nodeIndex = SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition);

    VM v = cstr.getInvolvedVMs().iterator().next();
    int p = vmsPosition.get(v.id());

    Set<Node> ns = nodeIndex.getSubSet(p);
    if (!ns.isEmpty()) {
        return partitions.get(p).getSatConstraints().add(new Fence(v, ns));
    }
    return true;
}
 
Example 5
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 6
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 7
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 8
Source File: GraphConfidenceEstimator.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
/**
 * Returns all local scores computed during the graph creation. As some
 * entities are dropped (graph coherence), they will be missing from the
 * current graph. These entities will still be present in the returned
 * map with negative scores. This is necessary for proper normalization.
 */
private Map<Integer, Double> getMentionEntityLocalScores(Graph g, int mentionId) {
  Map<Integer, Double> scores = new HashMap<Integer, Double>();
  // Don't get the local scores from the graph edges, they are incomplete when
  // candidate entities are dropped due to the coherence robustness test.
  // The graph contains all scores as well in a different variable.
  Mention mention = (Mention) g.getNode(mentionId).getNodeData();
  TIntDoubleHashMap entitySims = g.getMentionEntitySims(mention);
  if (entitySims == null) {
    return new HashMap<Integer, Double>();
  }
  TIntIntHashMap entity2id = g.getEntityNodesIds();
  for (TIntDoubleIterator itr = entitySims.iterator(); itr.hasNext(); ) {
    itr.advance();
    // If the entity is not present in the graph anymore, assign a new, 
    // negative one. The negative ids will never be queried, they are
    // just there for the score normalization.
    Integer entityId = 0;
    if (!entity2id.contains(itr.key())) {
      entityId = outOfGraphEntityId;
      --outOfGraphEntityId;
    } else {
      entityId = entity2id.get(itr.key());
    }
    scores.put(entityId, itr.value());
  }
  return scores;
}
 
Example 9
Source File: LanguageModelContext.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public int getEntityUnitCount(Entity entity, int unit, UnitType unitType) {
  TIntObjectHashMap<TIntIntHashMap> curEntityUnitCounts = entityUnitCounts.get(unitType.ordinal());
  if (curEntityUnitCounts == null) return 0;
  TIntIntHashMap curUnitCounts = curEntityUnitCounts.get(entity.getId());
  if (curUnitCounts == null) return 0;
  return curUnitCounts.get(unit);
}
 
Example 10
Source File: KilledSplitter.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean split(Killed cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    VM v = cstr.getInvolvedVMs().iterator().next();
    int i = vmsPosition.get(v.id());
    return partitions.get(i).getSatConstraints().add(cstr);
}
 
Example 11
Source File: OnlineSplitter.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean split(Online cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    Node n = cstr.getInvolvedNodes().iterator().next();
    int i = nodePosition.get(n.id());
    return partitions.get(i).getSatConstraints().add(cstr);
}
 
Example 12
Source File: RootSplitter.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean split(Root cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    VM v = cstr.getInvolvedVMs().iterator().next();
    int i = vmsPosition.get(v.id());
    return partitions.get(i).getSatConstraints().add(cstr);
}
 
Example 13
Source File: ReadySplitter.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean split(Ready cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    VM v = cstr.getInvolvedVMs().iterator().next();
    int i = vmsPosition.get(v.id());
    return partitions.get(i).getSatConstraints().add(cstr);
}
 
Example 14
Source File: OfflineSplitter.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean split(Offline cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    Node n = cstr.getInvolvedNodes().iterator().next();
    int i = nodePosition.get(n.id());
    return partitions.get(i).getSatConstraints().add(cstr);
}
 
Example 15
Source File: OverbookSplitter.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean split(Overbook cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    Node n = cstr.getInvolvedNodes().iterator().next();
    int i = nodePosition.get(n.id());
    return partitions.get(i).getSatConstraints().add(cstr);
}
 
Example 16
Source File: RunningSplitter.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean split(Running cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    VM v = cstr.getInvolvedVMs().iterator().next();
    int i = vmsPosition.get(v.id());
    return partitions.get(i).getSatConstraints().add(cstr);
}
 
Example 17
Source File: SleepingSplitter.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean split(Sleeping cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    VM v = cstr.getInvolvedVMs().iterator().next();
    int i = vmsPosition.get(v.id());
    return partitions.get(i).getSatConstraints().add(cstr);
}
 
Example 18
Source File: QuarantineSplitter.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean split(Quarantine cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    Node n = cstr.getInvolvedNodes().iterator().next();
    int i = nodePosition.get(n.id());
    return partitions.get(i).getSatConstraints().add(cstr);
}
 
Example 19
Source File: PreserveSplitter.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean split(Preserve cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    VM v = cstr.getInvolvedVMs().iterator().next();
    int p = vmsPosition.get(v.id());
    return partitions.get(p).getSatConstraints().add(cstr);
}