List of usage examples for com.google.common.collect Sets newIdentityHashSet
public static <E> Set<E> newIdentityHashSet()
From source file:com.complexible.common.base.Memory.java
/** * Returns the size of this object (with its references). */// w w w .ja va 2s. c o m public static long sizeOf(Object obj) { return sizeOf(obj, Sets.newIdentityHashSet()); }
From source file:org.jetbrains.jet.lang.resolve.NamespaceFactoryImpl.java
private void storeBindingForFileAndExpression(@Nullable JetFile file, @Nullable JetReferenceExpression expression, @NotNull NamespaceDescriptor namespaceDescriptor) { if (expression != null) { trace.record(REFERENCE_TARGET, expression, namespaceDescriptor); }/* w w w . java 2 s. c o m*/ if (file != null) { trace.record(BindingContext.FILE_TO_NAMESPACE, file, namespaceDescriptor); // Register files corresponding to this namespace // The trace currently does not support bi-di multimaps that would handle this task nicer Collection<JetFile> files = trace.get(NAMESPACE_TO_FILES, namespaceDescriptor); if (files == null) { files = Sets.newIdentityHashSet(); } files.add(file); trace.record(BindingContext.NAMESPACE_TO_FILES, namespaceDescriptor, files); } }
From source file:org.napile.compiler.lang.resolve.NamespaceFactoryImpl.java
private void storeBindingForFileAndExpression(@Nullable NapileFile file, @Nullable NapileReferenceExpression expression, @NotNull PackageDescriptor packageDescriptor) { if (expression != null) { trace.record(REFERENCE_TARGET, expression, packageDescriptor); }/*from w ww.j a va 2s .c om*/ if (file != null) { trace.record(BindingTraceKeys.FILE_TO_NAMESPACE, file, packageDescriptor); // Register files corresponding to this namespace // The trace currently does not support bi-di multimaps that would handle this task nicer Collection<NapileFile> files = trace.get(NAMESPACE_TO_FILES, packageDescriptor); if (files == null) { files = Sets.newIdentityHashSet(); } files.add(file); trace.record(BindingTraceKeys.NAMESPACE_TO_FILES, packageDescriptor, files); } }
From source file:org.apache.calcite.plan.SubstitutionVisitor.java
public SubstitutionVisitor(RelNode target_, RelNode query_, ImmutableList<UnifyRule> rules, RelBuilderFactory relBuilderFactory) { this.cluster = target_.getCluster(); final RexExecutor executor = Util.first(cluster.getPlanner().getExecutor(), RexUtil.EXECUTOR); this.simplify = new RexSimplify(cluster.getRexBuilder(), false, executor); this.rules = rules; this.query = Holder.of(MutableRels.toMutable(query_)); this.target = MutableRels.toMutable(target_); this.relBuilder = relBuilderFactory.create(cluster, null); final Set<MutableRel> parents = Sets.newIdentityHashSet(); final List<MutableRel> allNodes = new ArrayList<>(); final MutableRelVisitor visitor = new MutableRelVisitor() { public void visit(MutableRel node) { parents.add(node.getParent()); allNodes.add(node);/*w w w . j a v a2s . c om*/ super.visit(node); } }; visitor.go(target); // Populate the list of leaves in the tree under "target". // Leaves are all nodes that are not parents. // For determinism, it is important that the list is in scan order. allNodes.removeAll(parents); targetLeaves = ImmutableList.copyOf(allNodes); allNodes.clear(); parents.clear(); visitor.go(query); allNodes.removeAll(parents); queryLeaves = ImmutableList.copyOf(allNodes); }
From source file:org.apache.hadoop.hive.ql.optimizer.calcite.rules.views.SubstitutionVisitor.java
/** Creates a SubstitutionVisitor. */ public SubstitutionVisitor(RelNode target_, RelNode query_, ImmutableList<UnifyRule> rules, RelBuilderFactory relBuilderFactory) { this.cluster = target_.getCluster(); this.rules = rules; this.query = Holder.of(toMutable(query_)); this.target = toMutable(target_); this.relBuilder = relBuilderFactory.create(cluster, null); final Set<MutableRel> parents = Sets.newIdentityHashSet(); final List<MutableRel> allNodes = new ArrayList<>(); final MutableRelVisitor visitor = new MutableRelVisitor() { public void visit(MutableRel node) { parents.add(node.parent);//from ww w . j av a2 s. co m allNodes.add(node); super.visit(node); } }; visitor.go(target); // Populate the list of leaves in the tree under "target". // Leaves are all nodes that are not parents. // For determinism, it is important that the list is in scan order. allNodes.removeAll(parents); targetLeaves = ImmutableList.copyOf(allNodes); allNodes.clear(); parents.clear(); visitor.go(query); allNodes.removeAll(parents); queryLeaves = ImmutableList.copyOf(allNodes); }
From source file:com.continuuity.weave.yarn.YarnWeavePreparer.java
private Closeable createContainerJar(ApplicationBundler bundler, Map<String, LocalResource> localResources) throws IOException { try {//from ww w .ja v a 2 s . c o m Set<Class<?>> classes = Sets.newIdentityHashSet(); classes.add(WeaveContainerMain.class); classes.add(KafkaAppender.class); classes.addAll(dependencies); ClassLoader classLoader = getClass().getClassLoader(); for (RuntimeSpecification spec : weaveSpec.getRunnables().values()) { classes.add(classLoader.loadClass(spec.getRunnableSpecification().getClassName())); } LOG.debug("Create and copy container.jar"); Location location = createTempLocation("container", ".jar"); bundler.createBundle(location, classes); LOG.debug("Done container.jar"); localResources.put("container.jar", YarnUtils.createLocalResource(location)); return getCloseable(location); } catch (ClassNotFoundException e) { throw Throwables.propagate(e); } }
From source file:org.jamocha.dn.compiler.ecblocks.Block.java
public Block(final AssignmentGraph graph) { this.graph = graph; this.rowContainer = new RowContainer(graph); this.columns = new HashSet<>(); this.factVariablesUsed = Sets.newIdentityHashSet(); this.bindingPartition = new BindingPartition(); this.occurrencePartition = new OccurrencePartition(); }
From source file:com.google.template.soy.jbcsrc.TemplateVariableManager.java
/** * Enters a new scope. Variables may only be defined within a scope. *///from w ww. j av a2 s.c om Scope enterScope() { final Map<VarKey, Variable> currentFrame = new LinkedHashMap<>(); final Label scopeExit = new Label(); frames.push(currentFrame); return new Scope() { @Override Variable createSynthetic(SyntheticVarName varName, Expression initExpr, SaveStrategy strategy) { VarKey key = VarKey.create(Kind.SYNTHETIC, varName.name()); // synthetics are prefixed by $ by convention String name = fieldNames.generateName("$" + varName.name()); return doCreate(name, new Label(), scopeExit, initExpr, key, strategy); } @Override Variable create(String name, Expression initExpr, SaveStrategy strategy) { VarKey key = VarKey.create(Kind.USER_DEFINED, name); name = fieldNames.generateName(name); return doCreate(name, new Label(), scopeExit, initExpr, key, strategy); } @Override Statement exitScope() { frames.pop(); // Use identity semantics to make sure we visit each label at most once. visiting a label // more than once tends to corrupt internal asm state. final Set<Label> endLabels = Sets.newIdentityHashSet(); for (Variable var : currentFrame.values()) { endLabels.add(var.local.end()); availableSlots.clear(var.local.index(), var.local.index() + var.local.resultType().getSize()); } return new Statement() { // TODO(lukes): we could generate null writes for when object typed fields go out of // scope. This would potentially allow intermediate results to be collected sooner. @Override void doGen(CodeBuilder adapter) { for (Label label : endLabels) { adapter.visitLabel(label); } } }; } private Variable doCreate(String name, Label start, Label end, Expression initExpr, VarKey key, SaveStrategy strategy) { int index = reserveSlotFor(initExpr.resultType()); LocalVariable local = LocalVariable.createLocal(name, index, initExpr.resultType(), start, end); Variable var; switch (strategy) { case DERIVED: var = new DerivedVariable(initExpr, local); break; case STORE: var = new FieldSavedVariable(initExpr, local); break; default: throw new AssertionError(); } currentFrame.put(key, var); allVariables.add(var); return var; } }; }
From source file:org.jamocha.dn.compiler.ecblocks.Block.java
public Block(final BlockInterface other) { this.graph = other.getGraph(); this.rowContainer = new RowContainer(other.getRowContainer()); this.columns = other.getColumns().stream().map(Column::copy).collect(toHashSet()); this.factVariablesUsed = Sets.newIdentityHashSet(); this.factVariablesUsed.addAll(other.getFactVariablesUsed()); this.bindingPartition = new BindingPartition(other.getBindingPartition()); this.occurrencePartition = new OccurrencePartition(other.getOccurrencePartition()); }
From source file:com.android.tools.idea.uibuilder.structure.NlDropListener.java
/** * Modified dragged to keep only the elements that have no ancestor in the selection * * @param dragged the dragged element//from ww w .j a va 2 s .c om */ private static Collection<NlComponent> keepOnlyAncestors(@NotNull Collection<NlComponent> dragged) { final Set<NlComponent> selection = Sets.newIdentityHashSet(); selection.addAll(dragged); Stack<NlComponent> toTraverse = new Stack<>(); for (NlComponent selectedElement : dragged) { final List<NlComponent> children = selectedElement.getChildren(); // recursively delete children from the selection toTraverse.addAll(children); while (!toTraverse.isEmpty()) { // Traverse the subtree for each children NlComponent child = toTraverse.pop(); toTraverse.addAll(child.getChildren()); if (selection.contains(child)) { selection.remove(child); } } } return selection; }