gnu.trove.TObjectIntHashMap Java Examples

The following examples show how to use gnu.trove.TObjectIntHashMap. 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: MessageCounter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public synchronized void increment(@Nonnull String groupName,
                                   @Nonnull NotificationSource source,
                                   @Nonnull NotificationCategory category,
                                   @Nonnull ProjectSystemId projectSystemId) {

  final TObjectIntHashMap<NotificationCategory> counter =
          ContainerUtil.getOrCreate(
                  ContainerUtil.getOrCreate(
                          ContainerUtil.getOrCreate(
                                  map,
                                  projectSystemId,
                                  ContainerUtil.<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>>newHashMap()),
                          groupName,
                          ContainerUtil.<NotificationSource, TObjectIntHashMap<NotificationCategory>>newHashMap()
                  ),
                  source,
                  new TObjectIntHashMap<NotificationCategory>()
          );
  if (!counter.increment(category)) counter.put(category, 1);
}
 
Example #2
Source File: LRIdentificationModelSingleNode.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public void initializeParameters()
{
	localA = new TObjectIntHashMap<String>();
	String[] keys = new String[mParamList.size()];
	mParamList.keys(keys);
	int count = 0;
	for(String param:keys)		
	{
		double val = mParamList.get(param);
		LDouble lDoubleVal = LDouble.convertToLogDomain(val);
		int paramIndex = count;
		localA.put(param, paramIndex);
		setValue(paramIndex, lDoubleVal);
		setGradient(paramIndex, new LDouble(LDouble.IdentityElement.PLUS_IDENTITY));
		count++;
	}
}
 
Example #3
Source File: LinDekNeighbors.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
	Pair<TObjectIntHashMap<String>, TObjectIntHashMap<String>> p = 
		readAdjectivesAndAdverbs();
	TObjectIntHashMap<String> adjectives = p.getFirst();
	TObjectIntHashMap<String> adverbs = p.getSecond();
	System.out.println("Number of adjectives:" + adjectives.size());
	System.out.println("Number of adverbs:" + adverbs.size());
	try {
		//createNeighborsForAdverbsAndAdjectives(p);
		//createNeighborsForNouns();
		createNeighborsForVerbs();
	} catch (IOException e) {
		e.printStackTrace();
		System.exit(-1);
	}
}
 
Example #4
Source File: LinDekNeighbors.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static int findWordPOS(TObjectIntHashMap<String> dAdjectives, 
		TObjectIntHashMap<String> dAdverbs,
		String word) {
	int adjCount = dAdjectives.get(word);
	int advCount = dAdverbs.get(word);

	if (adjCount == 0 && advCount == 0) {
		if (word.endsWith("ly")) 
			return 2;
		else {
			return 3;
		}				
	}
	int total = adjCount + advCount;
	double adjProb = (double)adjCount / (double) total;
	double advProb = (double)advCount / (double) total;
	if (Math.abs(adjProb - advProb) < 0.2) {
		return 3;
	} else {
		if (adjProb > advProb) {
			return 1;
		} else {
			return 2;
		}
	}
}
 
Example #5
Source File: MessageCounter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public synchronized void remove(@Nullable final String groupName,
                                @Nonnull final NotificationSource notificationSource,
                                @Nonnull final ProjectSystemId projectSystemId) {
  final Map<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>> groupMap =
          ContainerUtil.getOrCreate(
                  map,
                  projectSystemId,
                  ContainerUtil.<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>>newHashMap());
  if (groupName != null) {
    final TObjectIntHashMap<NotificationCategory> counter = ContainerUtil.getOrCreate(
            ContainerUtil.getOrCreate(
                    groupMap,
                    groupName,
                    ContainerUtil.<NotificationSource, TObjectIntHashMap<NotificationCategory>>newHashMap()
            ),
            notificationSource,
            new TObjectIntHashMap<NotificationCategory>()
    );
    counter.clear();
  }
  else {
    for (Map<NotificationSource, TObjectIntHashMap<NotificationCategory>> sourceMap : groupMap.values()) {
      sourceMap.remove(notificationSource);
    }
  }
}
 
Example #6
Source File: DFSTBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public DFSTBuilder(@Nonnull OutboundSemiGraph<Node> graph) {
  myAllNodes = (Node[])graph.getNodes().toArray();
  myGraph = graph;
  int size = graph.getNodes().size();
  myNodeToNNumber = new TObjectIntHashMap<Node>(size * 2, 0.5f);
  myInvN = (Node[])new Object[size];
  myInvT = (Node[])new Object[size];
  new Tarjan().build();
}
 
Example #7
Source File: SeverityRegistrar.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static OrderMap fromList(@Nonnull List<HighlightSeverity> orderList) {
  TObjectIntHashMap<HighlightSeverity> map = new TObjectIntHashMap<HighlightSeverity>();
  for (int i = 0; i < orderList.size(); i++) {
    HighlightSeverity severity = orderList.get(i);
    map.put(severity, i);
  }
  return new OrderMap(map);
}
 
Example #8
Source File: OccurrenceConsumer.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void incTodoOccurrence(final IndexPattern pattern) {
  if (myTodoOccurrences == null) {
    myTodoOccurrences = new TObjectIntHashMap<IndexPattern>();
    for (IndexPattern indexPattern : IndexPatternUtil.getIndexPatterns()) {
      myTodoOccurrences.put(indexPattern, 0);
    }
  }
  myTodoOccurrences.adjustValue(pattern, 1);
}
 
Example #9
Source File: VcsLogStorageImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public MyCommitIdKeyDescriptor(@Nonnull List<VirtualFile> roots) {
  myRoots = roots;

  myRootsReversed = new TObjectIntHashMap<>();
  for (int i = 0; i < roots.size(); i++) {
    myRootsReversed.put(roots.get(i), i);
  }
}
 
Example #10
Source File: ExternalSystemTasksTreeModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void ensureSubProjectsStructure(@Nonnull ExternalProjectPojo topLevelProject, @Nonnull Collection<ExternalProjectPojo> subProjects) {
  ExternalSystemNode<ExternalProjectPojo> topLevelProjectNode = ensureProjectNodeExists(topLevelProject);
  Map<String/*config path*/, ExternalProjectPojo> toAdd = ContainerUtilRt.newHashMap();
  for (ExternalProjectPojo subProject : subProjects) {
    toAdd.put(subProject.getPath(), subProject);
  }
  toAdd.remove(topLevelProject.getPath());

  final TObjectIntHashMap<Object> taskWeights = new TObjectIntHashMap<>();
  for (int i = 0; i < topLevelProjectNode.getChildCount(); i++) {
    ExternalSystemNode<?> child = topLevelProjectNode.getChildAt(i);
    Object childElement = child.getDescriptor().getElement();
    if (childElement instanceof ExternalTaskExecutionInfo) {
      taskWeights.put(childElement, subProjects.size() + i);
      continue;
    }
    if (toAdd.remove(((ExternalProjectPojo)childElement).getPath()) == null) {
      removeNodeFromParent(child);
      //noinspection AssignmentToForLoopParameter
      i--;
    }
  }
  if (!toAdd.isEmpty()) {
    for (Map.Entry<String, ExternalProjectPojo> entry : toAdd.entrySet()) {
      ExternalProjectPojo element = new ExternalProjectPojo(entry.getValue().getName(), entry.getValue().getPath());
      insertNodeInto(new ExternalSystemNode<>(descriptor(element, myUiAware.getProjectIcon())), topLevelProjectNode);
    }
  }
}
 
Example #11
Source File: MessageCounter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public synchronized int getCount(@Nullable final String groupName,
                                 @Nonnull final NotificationSource notificationSource,
                                 @Nullable final NotificationCategory notificationCategory,
                                 @Nonnull final ProjectSystemId projectSystemId) {
  int count = 0;
  final Map<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>> groupMap = ContainerUtil.getOrElse(
          map,
          projectSystemId,
          Collections.<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>>emptyMap());

  for (Map.Entry<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>> entry : groupMap.entrySet()) {
    if (groupName == null || groupName.equals(entry.getKey())) {
      final TObjectIntHashMap<NotificationCategory> counter = entry.getValue().get(notificationSource);
      if (counter == null) continue;

      if (notificationCategory == null) {
        for (int aCount : counter.getValues()) {
          count += aCount;
        }
      }
      else {
        count = counter.get(notificationCategory);
      }
    }
  }

  return count;
}
 
Example #12
Source File: KShortestPathsFinder.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void computeDistancesToTarget() {
  myNonTreeEdges = new MultiMap<Node, GraphEdge<Node>>();
  mySortedNodes = new ArrayList<Node>();
  myNextNodes = new HashMap<Node, Node>();
  TObjectIntHashMap<Node> distances = new TObjectIntHashMap<Node>();
  Deque<Node> nodes = new ArrayDeque<Node>();
  nodes.addLast(myFinish);
  distances.put(myFinish, 0);
  while (!nodes.isEmpty()) {
    myProgressIndicator.checkCanceled();
    Node node = nodes.removeFirst();
    mySortedNodes.add(node);
    int d = distances.get(node) + 1;
    Iterator<Node> iterator = myGraph.getIn(node);
    while (iterator.hasNext()) {
      Node prev = iterator.next();
      if (distances.containsKey(prev)) {
        int dPrev = distances.get(prev);
        myNonTreeEdges.putValue(prev, new GraphEdge<Node>(prev, node, d - dPrev));
        continue;
      }
      distances.put(prev, d);
      myNextNodes.put(prev, node);
      nodes.addLast(prev);
    }
  }
}
 
Example #13
Source File: SimpleGraphInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static <CommitId> TObjectIntHashMap<CommitId> reverseCommitIdMap(PermanentCommitsInfo<CommitId> permanentCommitsInfo, int size) {
  TObjectIntHashMap<CommitId> result = new TObjectIntHashMap<>();
  for (int i = 0; i < size; i++) {
    result.put(permanentCommitsInfo.getCommitId(i), i);
  }
  return result;
}
 
Example #14
Source File: SeverityRegistrar.java    From consulo with Apache License 2.0 5 votes vote down vote up
private OrderMap(@Nonnull TObjectIntHashMap<HighlightSeverity> map) {
  super(map.size());
  map.forEachEntry(new TObjectIntProcedure<HighlightSeverity>() {
    @Override
    public boolean execute(HighlightSeverity key, int value) {
      OrderMap.super.put(key, value);
      return true;
    }
  });
  trimToSize();
}
 
Example #15
Source File: DFSTBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Comparator<Node> comparator() {
  if (myComparator == null) {
    final TObjectIntHashMap<Node> map = isAcyclic() ? myNodeToNNumber : myNodeToTNumber;
    myComparator = new Comparator<Node>() {
      @Override
      public int compare(@Nonnull Node t, @Nonnull Node t1) {
        return map.get(t) - map.get(t1);
      }
    };
  }
  return myComparator;
}
 
Example #16
Source File: ArrangementEngine.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static <E extends ArrangementEntry> void sortByName(@Nonnull List<E> entries) {
  if (entries.size() < 2) {
    return;
  }
  final TObjectIntHashMap<E> weights = new TObjectIntHashMap<E>();
  int i = 0;
  for (E e : entries) {
    weights.put(e, ++i);
  }
  ContainerUtil.sort(entries, new Comparator<E>() {
    @Override
    public int compare(E e1, E e2) {
      String name1 = e1 instanceof NameAwareArrangementEntry ? ((NameAwareArrangementEntry)e1).getName() : null;
      String name2 = e2 instanceof NameAwareArrangementEntry ? ((NameAwareArrangementEntry)e2).getName() : null;
      if (name1 != null && name2 != null) {
        return name1.compareTo(name2);
      }
      else if (name1 == null && name2 == null) {
        return weights.get(e1) - weights.get(e2);
      }
      else if (name2 == null) {
        return -1;
      }
      else {
        return 1;
      }
    }
  });
}
 
Example #17
Source File: VarModality.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns a hash code using the given map from vars to ints.
 */
public int hashCode(TObjectIntHashMap varMap) {
	// see if this already in map
	if (varMap.containsKey(this))
		return varMap.get(this);
	// otherwise add it
	int next = varMap.size() + 1;
	varMap.put(this, next);
	return next;
}
 
Example #18
Source File: VarModality.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
* Returns whether this var equals the given object up to variable names,
* using the given maps from vars to ints.
*/
  public boolean equals(Object obj, TObjectIntHashMap varMap, TObjectIntHashMap varMap2) {
      if (this == obj) return true;
      if (obj.getClass() != this.getClass()) { return false; }
      VarModality vm = (VarModality) obj;
      if (varMap.get(this) != varMap2.get(vm)) return false;
      return true;
  }
 
Example #19
Source File: GFeatVar.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns a hash code using the given map from vars to ints.
 */
public int hashCode(TObjectIntHashMap varMap) {
	// see if this already in map
	if (varMap.containsKey(this))
		return varMap.get(this);
	// otherwise add it
	int next = varMap.size() + 1;
	varMap.put(this, next);
	return next;
}
 
Example #20
Source File: GFeatVar.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
* Returns whether this var equals the given object up to variable names,
* using the given maps from vars to ints.
* (Note that the name and index may differ, but the types must be equal.)
*/
  public boolean equals(Object obj, TObjectIntHashMap varMap, TObjectIntHashMap varMap2) {
      if (this == obj) return true;
      if (obj.getClass() != this.getClass()) { return false; }
      GFeatVar gv = (GFeatVar) obj;
      if (varMap.get(this) != varMap2.get(gv)) return false;
      if (!this.type.equals(gv.type)) return false;
      return true;
  }
 
Example #21
Source File: ExpandedSupModel.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public static TObjectIntHashMap<String> getReverseMap(TIntObjectHashMap<String> map) {
	TObjectIntHashMap<String> rMap = new TObjectIntHashMap<String>();
	int[] keys = map.keys();
	for (int i = 0; i < keys.length; i++) {
		rMap.put(map.get(keys[i]), keys[i]);
	}
	return rMap;
}
 
Example #22
Source File: ControlDependencies.java    From whyline with MIT License 5 votes vote down vote up
private TObjectIntHashMap<Instruction> visitPostOrderIterative(Instruction start, ArrayList<Instruction> instructionsInPostOrderTraversalOfReverseControlFlowGraph) {
	
	TObjectIntHashMap<Instruction>postOrderNumbers = new TObjectIntHashMap<Instruction>();
	
	ArrayList<Instruction> stack = new ArrayList<Instruction>();
	TIntHashSet visitedIndices = new TIntHashSet(code.getNumberOfInstructions());
	TIntHashSet processedIndices = new TIntHashSet(code.getNumberOfInstructions());
	
	stack.add(start);
	while(stack.size() > 0) {
		Instruction top = stack.get(stack.size() - 1);
		if(visitedIndices.contains(top.getIndex())) {
			stack.remove(stack.size() - 1);
			if(!processedIndices.contains(top.getIndex())) {
				processedIndices.add(top.getIndex());
				
				instructionsInPostOrderTraversalOfReverseControlFlowGraph.add(0, top);
				postOrderNumbers.put(top, instructionsInPostOrderTraversalOfReverseControlFlowGraph.size());

			}
		}
		// Remember that we were here, then add the predecessors in reverse order to the stack.
		else {
			visitedIndices.add(top.getIndex());
			int insertionIndex = 0;
			for(Instruction predecessor : top.getOrderedPredecessors()) {
				if(!visitedIndices.contains(predecessor.getIndex())) {
					stack.add(stack.size() - insertionIndex, predecessor);
					insertionIndex++;
				}
			}
		}

	}

	return postOrderNumbers;
	
}
 
Example #23
Source File: MethodDependencyGraph.java    From whyline with MIT License 5 votes vote down vote up
/**
 * Returns a map of all known methods in trace and their distances from the given target
 * in the method dependence graph. If the method is not in the map, the distance is undefined
 * (there is no path).
 */
public TObjectIntHashMap<String> getMethodDistancesToMethod(MethodInfo target) {
	
	if(target == null) {
		System.out.println("Received null method target.");
		return null;
	}
	
	TObjectIntHashMap<String> distancesByMethod = new TObjectIntHashMap<String>(); 
	System.out.println("Analyzing distance from " + methodToMethods.size() + " methods to " + target.getQualifiedNameAndDescriptor());

	Set<MethodInfo> visited = new HashSet<MethodInfo>();
	LinkedList<MethodInfo> queue = new LinkedList<MethodInfo>();
	distancesByMethod.put(target.getQualifiedNameAndDescriptor(), 0);
	visited.add(target);
	queue.offer(target);
	while(!queue.isEmpty()) {
		
		MethodInfo method = queue.poll();
		assert distancesByMethod.containsKey(method.getQualifiedNameAndDescriptor());
		int distance = distancesByMethod.get(method.getQualifiedNameAndDescriptor()) + 1;
		for(MethodInfo relatedMethod : methodToMethods.get(method)) {

			// Visit this method.
			if(!visited.contains(relatedMethod)) {
				visited.add(relatedMethod);
				distancesByMethod.put(relatedMethod.getQualifiedNameAndDescriptor(), distance);
				queue.offer(relatedMethod);
			}
			
		}
		
		
	}
	
	return distancesByMethod;
	
}
 
Example #24
Source File: ExpandedSupModel.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
	String supmodel = args[0];
	String supalphabet = args[1];
	String ssalphabet = args[2];
	String outmodel = args[3];
	
	TIntObjectHashMap<String> supAlphabet = 
		readAlphabet(supalphabet);
	TObjectIntHashMap<String> rSupAlphabet = getReverseMap(supAlphabet);
	TIntObjectHashMap<String> ssAlphabet = 
		readAlphabet(ssalphabet);
	int supsize = supAlphabet.size();
	int sssize = ssAlphabet.size();
	double[] supmodelarr = readDoubleArray(supmodel, supsize+1);
	double[] ssmodelarr = new double[sssize+1];
	ssmodelarr[0] = supmodelarr[0];
	for (int i = 1; i < sssize+1; i++) {
		String feat = ssAlphabet.get(i);
		if (rSupAlphabet.contains(feat)) {
			int index = rSupAlphabet.get(feat);
			ssmodelarr[i] = supmodelarr[index];
		} else {
			ssmodelarr[i] = 1.0;
		}
	}
	writeArray(ssmodelarr, outmodel);
}
 
Example #25
Source File: ListFocusTraversalPolicy.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static <X> TObjectIntHashMap<X> indexMap(@Nonnull X[] array) {
  TObjectIntHashMap<X> map = new TObjectIntHashMap<>(array.length);
  for (X x : array) {
    if (!map.contains(x)) {
      map.put(x, map.size());
    }
  }
  map.compact();
  return map;
}
 
Example #26
Source File: ConvertGraphToSerObj.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public static int indexString(String string, TObjectIntHashMap<String> map, ArrayList<String> list) {
	if (map.contains(string)) {
		return map.get(string);
	} else {
		int size = map.size();
		map.put(string, size);
		list.add(string);
		return size;
	}
}
 
Example #27
Source File: IntCounter.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public IntCounter(TObjectIntHashMap<T> map) {
	m_map = map;
	
	int vals[] = map.getValues();
	for (int val : vals) {
		m_sum += val;
	}
}
 
Example #28
Source File: AbstractDataIndexer.java    From bluima with Apache License 2.0 5 votes vote down vote up
/**
     * Utility method for creating a String[] array from a map whose
     * keys are labels (Strings) to be stored in the array and whose
     * values are the indices (Integers) at which the corresponding
     * labels should be inserted.
     *
     * @param labelToIndexMap a <code>TObjectIntHashMap</code> value
     * @return a <code>String[]</code> value
     * @since maxent 1.2.6
     */
protected static String[] toIndexedStringArray(TObjectIntHashMap labelToIndexMap) {
    final String[] array = new String[labelToIndexMap.size()];
    labelToIndexMap.forEachEntry(new TObjectIntProcedure() {
            public boolean execute(Object str, int index) {
                array[index] = (String)str;
                return true;
            }
        });
    return array;
}
 
Example #29
Source File: ModuleRootsProcessorFromModuleDir.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean containsFile(@Nonnull TObjectIntHashMap<VirtualFile> roots, @Nonnull final VirtualFile virtualFile) {
  return !roots.forEachKey(new TObjectProcedure<VirtualFile>() {
    @Override
    public boolean execute(VirtualFile object) {
      return !VfsUtilCore.isAncestor(object, virtualFile, false);
    }
  });
}
 
Example #30
Source File: IntCounter.java    From semafor-semantic-parser with GNU General Public License v3.0 4 votes vote down vote up
public IntCounter(TObjectHashingStrategy<T> hs) {
	m_map = new TObjectIntHashMap<T>(hs);
}