private int getNode(DefaultCallGraphNode node) { int index = nodeToIndex.getOrDefault(node, -1); if (index < 0) { index = nodeToIndex.size(); nodeToIndex.put(node, index); nodes.add(new SerializableCallGraph.Node()); nodesToProcess.add(node); } return index; }
private ObjectIntMap<Instruction> getInstructionIndexes(BasicBlock block) { ObjectIntMap<Instruction> indexes = new ObjectIntHashMap<>(); for (Instruction instruction : block) { indexes.put(instruction, indexes.size()); } return indexes; }
private int getCallSite(DefaultCallSite callSite) { int index = callSiteToIndex.getOrDefault(callSite, -1); if (index < 0) { index = callSiteToIndex.size(); callSiteToIndex.put(callSite, index); callSites.add(new SerializableCallGraph.CallSite()); callSitesToProcess.add(callSite); } return index; }
private int getFieldAccess(DefaultFieldAccessSite fieldAccessSite) { int index = fieldAccessToIndex.getOrDefault(fieldAccessSite, -1); if (index < 0) { index = fieldAccessToIndex.size(); fieldAccessToIndex.put(fieldAccessSite, index); fieldAccessList.add(new SerializableCallGraph.FieldAccess()); fieldAccessToProcess.add(fieldAccessSite); } return index; } }
public int size() { return map.size(); }
/** * Creates a new vector that is appropriately sized to accommodate all the features that have been named so far. * @return a new, empty ConcatVector */ public ConcatVector newVector() { return new ConcatVector(featureToIndex.size()); }
private int getFieldAccess(DefaultFieldAccessSite fieldAccessSite) { int index = fieldAccessToIndex.getOrDefault(fieldAccessSite, -1); if (index < 0) { index = fieldAccessToIndex.size(); fieldAccessToIndex.put(fieldAccessSite, index); fieldAccessList.add(new SerializableCallGraph.FieldAccess()); fieldAccessToProcess.add(fieldAccessSite); } return index; }
private int getCallSite(DefaultCallSite callSite) { int index = callSiteToIndex.getOrDefault(callSite, -1); if (index < 0) { index = callSiteToIndex.size(); callSiteToIndex.put(callSite, index); callSites.add(new SerializableCallGraph.CallSite()); callSitesToProcess.add(callSite); } return index; }
private int getNode(DefaultCallGraphNode node) { int index = nodeToIndex.getOrDefault(node, -1); if (index < 0) { index = nodeToIndex.size(); nodeToIndex.put(node, index); nodes.add(new SerializableCallGraph.Node()); nodesToProcess.add(node); } return index; }
private int getClassAccess(DefaultClassAccessSite classAccessSite) { int index = classAccessToIndex.getOrDefault(classAccessSite, -1); if (index < 0) { index = classAccessToIndex.size(); classAccessToIndex.put(classAccessSite, index); classAccessList.add(new SerializableCallGraph.ClassAccess()); classAccessToProcess.add(classAccessSite); } return index; } }
private ObjectIntMap<Instruction> getInstructionIndexes(BasicBlock block) { ObjectIntMap<Instruction> indexes = new ObjectIntOpenHashMap<>(); for (Instruction instruction : block) { indexes.put(instruction, indexes.size()); } return indexes; }
/** * An optimization, this lets clients inform the ConcatVectorNamespace of how many features to expect, so * that we can avoid resizing ConcatVectors. * @param featureName the feature to add to our index */ public int ensureFeature(String featureName) { int feature = featureToIndex.getOrDefault(featureName, -1); if (feature == -1) { synchronized (featureToIndex) { feature = featureToIndex.getOrDefault(featureName, -1); if (feature == -1) { feature = featureToIndex.size(); featureToIndex.put(featureName, feature); } } } return feature; }
/** * This constructs a fresh vector that is sized correctly to accommodate all the known sparse values for vectors * that are possibly sparse. * * @param presize a flag for whether or not to create all the dense double arrays for our sparse features * * @return a new, internally correctly sized ConcatVector that will work correctly as weights for features from * this namespace; */ public ConcatVector newWeightsVector(boolean presize) { ConcatVector vector = new ConcatVector(featureToIndex.size()); if (presize) { for (ObjectCursor<String> s : sparseFeatureIndex.keys()) { int size = sparseFeatureIndex.get(s.value).size(); vector.setDenseComponent(ensureFeature(s.value), new double[size]); } } setAlwaysOneFeature(vector, 1); return vector; }
rtn = sparseIndex.getOrDefault(index, -1); if (rtn == -1) { rtn = sparseIndex.size(); reverseSparseIndex.put(rtn, index); sparseIndex.put(index, rtn);