Calculate which AST nodes are unused.

    Note that we have to take special care in the case of
    x,y = f(z) where x is used later, but y is not.
180591
def unused(self):
    """"""
    unused = self.definitions - self.used
    # Filter (variable_name,node) pairs that should be removed, because
    # node is used elsewhere
    used_nodes = set([u[1] for u in self.used])
    unused = set([u for u in unused if u[1] not in used_nodes])
    return unused
180108
public void findAllCC() {
		if (nodeCC == null) {
			CCFirstNode = new int[n];
			CCNextNode = new int[n];
			nodeCC = new int[n];
			sizeCC = new int[n];
		}
		sizeMinCC = 0;
		sizeMaxCC = 0;
		ISet act = graph.getNodes();
		for (int i : act) {
			p[i] = -1;
		}
		for (int i = 0; i < CCFirstNode.length; i++) {
			CCFirstNode[i] = -1;
			sizeCC[i] = -1;
		}
		int cc = 0;
		for (int i : act) {
			if (p[i] == -1) {
				findCC(i, cc);
				if (sizeMinCC == 0 || sizeMinCC > sizeCC[cc]) {
					sizeMinCC = sizeCC[cc];
				}
				if (sizeMaxCC < sizeCC[cc]) {
					sizeMaxCC = sizeCC[cc];
				}
				cc++;
			}
		}
		nbCC = cc;
	}
674665
def cleanup(self):
        
        # cost from this node to the goal
        self.h = 0.0

        # cost from the start node to this node
        self.g = 0.0

        # distance from start to this point (f = g + h )
        self.f = 0.0

        self.opened = 0
        self.closed = False

        # used for backtracking to the start point
        self.parent = None

        # used for recurion tracking of IDA*
        self.retain_count = 0
        # used for IDA* and Jump-Point-Search
        self.tested = False
1101454
function removeUnusedProperties(node) {
    if (typeof node !== "object") {
        return;
    }
    ["position"].forEach(function (key) {
        if (node.hasOwnProperty(key)) {
            delete node[key];
        }
    });
}
1313926
def get_roots(self):
    
    if self.__directionless:
      sys.stderr.write("ERROR: can't get roots of an undirected graph\n")
      sys.exit()
    outputids = self.__nodes.keys()
    #print outputids
    rootset  = set(outputids) -  set(self.__child_to_parent.keys())
    return [self.__nodes[x] for x in rootset]
638533
def use_size(self):
        ""
        if self._nodes is None:
            return self._use_size
        return sum(i.use_size() for i in self._nodes)
1077937
def compute_node_positions(self):
        
        xs = []
        ys = []
        self.locs = dict()

        for node in self.nodes:
            x = self.graph.node[node][self.node_lon]
            y = self.graph.node[node][self.node_lat]
            xs.append(x)
            ys.append(y)
            self.locs[node] = (x, y)

        self.node_coords = {"x": xs, "y": ys}
1281205
def _determine_uses(self, included_files, forward_declarations):
        """"""
        file_uses = dict.fromkeys(included_files, UNUSED)
        decl_uses = dict.fromkeys(forward_declarations, UNUSED)
        symbol_table = self.symbol_table

        for name, node in forward_declarations.items():
            try:
                symbol_table.lookup_symbol(node.name, node.namespace)
                decl_uses[name] |= USES_REFERENCE
            except symbols.Error:
                module = Module(name, None)
                symbol_table.add_symbol(node.name, node.namespace, node,
                                        module)

        def _do_lookup(name, namespace):
            try:
                file_use_node = symbol_table.lookup_symbol(name, namespace)
            except symbols.Error:
                return
            name = file_use_node[1].filename
            file_uses[name] = file_uses.get(name, 0) | USES_DECLARATION

        def _add_declaration(name, namespace):
            if not name:
                # Ignore anonymous struct. It is not standard, but we might as
                # well avoid crashing if it is easy.
                return

            names = [n for n in namespace if n is not None]
            if names:
                name = '::'.join(names) + '::' + name
            if name in decl_uses:
                decl_uses[name] |= USES_DECLARATION

        def _add_reference(name, namespace):
            try:
                file_use_node = symbol_table.lookup_symbol(name, namespace)
            except symbols.Error:
                return

            name = file_use_node[1].filename
            if file_use_node[1].ast_list is None:
                decl_uses[name] |= USES_REFERENCE
            elif name in file_uses:
                # enum and typedef can't be forward declared
                if isinstance(file_use_node[0], (ast.Enum, ast.Typedef)):
                    file_uses[name] |= USES_DECLARATION
                else:
                    file_uses[name] |= USES_REFERENCE

        def _add_use(node, namespace, name=''):
            if isinstance(node, basestring):
                name = node
            elif isinstance(node, list):
                # name contains a list of tokens.
                name = '::'.join([n.name for n in name])

            # node is a Type so look for its symbol immediately.
            if name:
                _do_lookup(name, namespace)
                return

            # Try to search for the value of the variable declaration for any
            # symbols, such as `#define` values or other variable names which
            # may be included in other files.
            obj = getattr(node, 'initial_value', None)
            if obj:
                _do_lookup(obj, namespace)

            # If node is a VariableDeclaration, check if the variable type is
            # a symbol used in other includes.
            obj = getattr(node, 'type', None)
            if obj and isinstance(obj.name, basestring):
                _do_lookup(obj.name, namespace)

            if not isinstance(node, basestring):
                # Happens when variables are defined with inlined types, e.g.:
                #   enum {...} variable;
                return

        def _add_variable(node, namespace, reference=False):
            obj = node.type if isinstance(
                node, ast.VariableDeclaration) else node

            if obj.reference or obj.pointer or reference:
                _add_reference(obj.name, namespace)
            else:
                # Add a use for the variable declaration type as well as the
                # variable value.
                _add_use(obj.name, namespace)
                _add_use(node, namespace)
            # This needs to recurse when the node is a templated type.
            _add_template_use(obj.name,
                              obj.templated_types,
                              namespace,
                              reference)

        def _process_function(function, namespace):
            reference = function.body is None
            if function.return_type:
                return_type = function.return_type
                _add_variable(return_type, namespace, reference)

            for s in function.specializations:
                _add_variable(s, namespace, not function.body)

            templated_types = function.templated_types or ()
            for p in function.parameters:
                node = p.type
                if node.name not in templated_types:
                    if function.body and p.name:
                        # Assume that if the function has a body and a name
                        # the parameter type is really used.
                        # NOTE(nnorwitz): this is over-aggressive. It would be
                        # better to iterate through the body and determine
                        # actual uses based on local vars and data members
                        # used.
                        _add_use(node.name, namespace)
                    elif (
                        p.default and
                        p.default[0].name != '0' and
                        p.default[0].name != 'NULL' and
                        p.default[0].name != 'nullptr'
                    ):
                        _add_use(node.name, namespace)
                    elif node.reference or node.pointer or reference:
                        _add_reference(node.name, namespace)
                    else:
                        _add_use(node.name, namespace)
                    _add_template_use(node.name,
                                      node.templated_types,
                                      namespace,
                                      reference)

        def _process_function_body(function, namespace):
            previous = None
            save = namespace[:]
            for t in function.body:
                if t.token_type == tokenize.NAME:
                    previous = t
                    if not keywords.is_keyword(t.name):
                        # TODO(nnorwitz): handle static function calls.
                        # TODO(nnorwitz): handle using statements in file.
                        # TODO(nnorwitz): handle using statements in function.
                        # TODO(nnorwitz): handle namespace assignment in file.
                        _add_use(t.name, namespace)
                elif t.name == '::' and previous is not None:
                    namespace.append(previous.name)
                elif t.name in (':', ';'):
                    namespace = save[:]

        def _add_template_use(name, types, namespace, reference=False):
            for cls in types or ():
                if cls.pointer or cls.reference or reference:
                    _add_reference(cls.name, namespace)
                elif name.endswith('_ptr'):
                    # Special case templated classes that end w/_ptr.
                    # These are things like auto_ptr which do
                    # not require the class definition, only decl.
                    _add_reference(cls.name, namespace)
                elif name.startswith('Q') and name.endswith('Pointer'):
                    # Special case templated classes from the Qt framework.
                    _add_reference(cls.name, namespace)
                else:
                    _add_use(cls.name, namespace)
                _add_template_use(cls.name, cls.templated_types,
                                  namespace, reference)

        def _process_types(nodes, namespace):
            for node in nodes:
                if isinstance(node, ast.Type):
                    _add_variable(node, namespace)

        # Iterate through the source AST/tokens, marking each symbols use.
        ast_seq = [self.ast_list]
        namespace_stack = []
        while ast_seq:
            for node in ast_seq.pop():
                if isinstance(node, ast.VariableDeclaration):
                    namespace = namespace_stack + node.namespace
                    _add_variable(node, namespace)
                elif isinstance(node, ast.Function):
                    namespace = namespace_stack + node.namespace
                    _process_function(node, namespace)
                    if node.body:
                        _process_function_body(node, namespace)
                elif isinstance(node, ast.Typedef):
                    namespace = namespace_stack + node.namespace
                    _process_types(node.alias, namespace)
                elif isinstance(node, ast.Friend):
                    expr = node.expr
                    namespace = namespace_stack + node.namespace
                    if isinstance(expr, ast.Type):
                        _add_reference(expr.name, namespace)
                    elif isinstance(expr, ast.Function):
                        _process_function(expr, namespace)
                elif isinstance(node, ast.Union) and node.body is not None:
                    ast_seq.append(node.body)
                elif isinstance(node, ast.Class) and node.body is not None:
                    _add_declaration(node.name, node.namespace)
                    namespace = namespace_stack + node.namespace
                    _add_template_use('', node.bases, namespace)
                    ast_seq.append(node.body)
                elif isinstance(node, ast.Using):
                    if node.names[0].name == 'namespace':
                        namespace_stack.append(node.names[1].name)

        return file_uses, decl_uses
1108724
function removeUnusedVariableDeclarators (ast) {
  var unused = findUnusedVariableDeclarators(ast);
  traverse.traverse(ast, {
    enter: function (node, parent) {
      if (node.type !== 'VariableDeclaration') {
        return;
      }
      node.declarations = fast.filter(node.declarations, function (item) {
        return !~fast.indexOf(unused, item);
      });
    }
  });
  return ast;
}
673590
function removeUnusedAssignmentExpressions (ast) {
  var unused = findUnusedAssignmentExpressions(ast);
  traverse.traverse(ast, {
    enter: function (node, parent) {
      if (node.type !== 'BlockStatement') {
        return;
      }
      node.body = fast.filter(node.body, function (item) {
        return !~fast.indexOf(unused, item);
      });
    }
  });
  return ast;
}
1000350
def _clear(self, node, left, right):
        
        if self.lazyset[node] is not None:  # first do the pending set
            val = self.lazyset[node]
            self.minval[node] = val
            self.maxval[node] = val
            self.sumval[node] = val * (right - left)
            self.lazyset[node] = None
            if left < right - 1:            # not a leaf
                self.lazyset[2 * node] = val    # propagate to direct descendents
                self.lazyadd[2 * node] = 0
                self.lazyset[2 * node + 1] = val
                self.lazyadd[2 * node + 1] = 0
        if self.lazyadd[node] != 0:        # then do the pending add
            val = self.lazyadd[node]
            self.minval[node] += val
            self.maxval[node] += val
            self.sumval[node] += val * (right - left)
            self.lazyadd[node] = 0
            if left < right - 1:            # not at a leaf
                self.lazyadd[2 * node] += val     # propagate to direct descendents
                self.lazyadd[2 * node + 1] += val
66316
def reduceUselessAssignments(root: LNode):
    
    for n in root.children:
        if n.children:
            reduceUselessAssignments(n)

    do_update = False
    for n in root.children:
        if isinstance(n.originObj, Assignment)\
                and not n.originObj.indexes\
                and len(n.west) == 1:
            src = n.originObj.src
            if isinstance(src, RtlSignalBase) and src.hidden:
                continue

            if not do_update:
                nodes = set(root.children)
                do_update = True

            nodes.remove(n)

            srcPorts = []
            dstPorts = []
            edgesToRemove = []

            inP = getSinglePort(n.west)
            outP = getSinglePort(n.east)
            for e in inP.incomingEdges:
                sPort = e.src
                srcPorts.append((sPort, e.originObj))
                edgesToRemove.append(e)

            for e in outP.outgoingEdges:
                dPort = e.dst
                dstPorts.append(dPort)
                edgesToRemove.append(e)

            for e in edgesToRemove:
                e.remove()

            for srcPort, originObj in srcPorts:
                for dstPort in dstPorts:
                    root.addEdge(srcPort, dstPort,
                                 originObj=originObj)

    if do_update:
        root.children = list(nodes)
1256123
def function_nodes(self):
        

        return {k: v for k, v in self.nodes.items() if v['type'] == 'function'}
1075790
def get_unused_color(self):
        
        if not self.unused_colors:
            # If we somehow run out of colors, reset the color matcher.
            self.reset()
        used_colors = [c for c in self.xlwt_colors if c not in self.unused_colors]
        result_color = max(self.unused_colors,
                           key=lambda c: min(self.color_distance(c, c2)
                                             for c2 in used_colors))
        result_index = self.xlwt_colors.index(result_color)
        self.unused_colors.discard(result_color)
        return result_index
1097839
def _compute_unnecessary_deps(self, target, actual_deps):
    
    # Flatten the product deps of this target.
    product_deps = set()
    for dep_entries in actual_deps.values():
      product_deps.update(dep_entries)

    # Determine which of the DEFAULT deps in the declared set of this target were used.
    used = set()
    unused = set()
    for dep, _ in self._analyzer.resolve_aliases(target, scope=Scopes.DEFAULT):
      if dep in used or dep in unused:
        continue
      # TODO: What's a better way to accomplish this check? Filtering by `has_sources` would
      # incorrectly skip "empty" `*_library` targets, which could then be used as a loophole.
      if isinstance(dep, (Resources, UnpackedJars)):
        continue
      # If any of the target's jars or classfiles were used, consider it used.
      if product_deps.isdisjoint(self._analyzer.files_for_target(dep)):
        unused.add(dep)
      else:
        used.add(dep)

    # If there were no unused deps, break.
    if not unused:
      return {}

    # For any deps that were used, count their derived-from targets used as well.
    # TODO: Refactor to do some of this above once tests are in place.
    for dep in list(used):
      for derived_from in dep.derived_from_chain:
        if derived_from in unused:
          unused.remove(derived_from)
          used.add(derived_from)

    # Prune derived targets that would be in the set twice.
    for dep in list(unused):
      if set(dep.derived_from_chain) & unused:
        unused.remove(dep)

    if not unused:
      return {}

    # For any deps that were not used, determine whether their transitive deps were used, and
    # recommend those as replacements.
    replacements = {}
    for dep in unused:
      replacements[dep] = set()
      for t in dep.closure():
        if t in used or t in unused:
          continue
        if not product_deps.isdisjoint(self._analyzer.files_for_target(t)):
          replacements[dep].add(t.concrete_derived_from)

    return replacements
393841
def get_unused_list_annotation_values(graph) -> Mapping[str, Set[str]]:
    
    result = {}
    for annotation, values in graph.annotation_list.items():
        used_values = get_annotation_values(graph, annotation)
        if len(used_values) == len(values):  # all values have been used
            continue
        result[annotation] = set(values) - used_values
    return result
3067
private void sweep() {
        for (Node p = head, s, n; p != null && (s = p.next) != null; ) {
            if (!s.isMatched())
                // Unmatched nodes are never self-linked
                p = s;
            else if ((n = s.next) == null) // trailing node is pinned
                break;
            else if (UNLINKED == n)    // stale
                // No need to also check for p == s, since that implies s == n
                p = head;
            else
                p.casNext(s, n);
        }
    }