Recurse depth-first so order of declaring types is correct.
425061
private static void appendDeclaringTypes(TypeReference typeRef, char innerClassDelimiter,
      StringBuilder sb) {
    TypeReference declaringType = typeRef.getDeclaringType();
    if (declaringType != null) {
      appendDeclaringTypes(declaringType, innerClassDelimiter, sb);
      sb.append(declaringType.getSimpleName());
      sb.append(innerClassDelimiter);
    }
  }
681264
def find_first_declaration(
        declarations,
        decl_type=None,
        name=None,
        parent=None,
        recursive=True,
        fullname=None):
    

    decl_matcher = algorithm.match_declaration_t(
        decl_type=decl_type,
        name=name,
        fullname=fullname,
        parent=parent)
    if recursive:
        decls = make_flatten(declarations)
    else:
        decls = declarations
    for decl in decls:
        if decl_matcher(decl):
            return decl
    return None
1238804
def depth_first(problem, graph_search=False, viewer=None):
    '''
    
    '''
    return _search(problem,
                   LifoList(),
                   graph_search=graph_search,
                   viewer=viewer)
1037976
def binaryTree_depthFirstNumbers(binaryTree, labelTree=True, dontStopAtID=True):
    
    traversalIDs = {}
    def traverse(binaryTree, mid=0, leafNo=0):
        if binaryTree.internal and (dontStopAtID or binaryTree.iD is None):
            midStart = mid
            j, leafNo = traverse(binaryTree.left, mid, leafNo)
            mid = j
            j, leafNo = traverse(binaryTree.right, j+1, leafNo)
            traversalIDs[binaryTree] = TraversalID(midStart, mid, j)
            return j, leafNo
        traversalID = TraversalID(mid, mid, mid+1)
        traversalID.leafNo = leafNo
        #thus nodes must be unique
        traversalIDs[binaryTree] = traversalID
        return mid+1, leafNo+1
    traverse(binaryTree)
    if labelTree:
        for binaryTree in traversalIDs.keys():
            binaryTree.traversalID = traversalIDs[binaryTree]
    return traversalIDs
1355618
def depth_first_search_with_parent_data(graph, root_node = None, adjacency_lists = None):
    """"""
    ordering = []
    parent_lookup = {}
    children_lookup = defaultdict(lambda: [])

    all_nodes = graph.get_all_node_ids()
    if not all_nodes:
        return ordering, parent_lookup, children_lookup

    stack = deque()
    discovered = defaultdict(lambda: False)
    unvisited_nodes = set(all_nodes)

    if root_node is None:
        root_node = all_nodes[0]

    if adjacency_lists is None:
        adj = lambda v: graph.neighbors(v)
    else:
        adj = lambda v: adjacency_lists[v]

    # --Initialize the stack, simulating the DFS call on the root node
    stack.appendleft(root_node)
    parent_lookup[root_node] = root_node

    # We're using a non-recursive implementation of DFS, since Python isn't great for deep recursion
    while True:
        # Main DFS Loop
        while len(stack) > 0:
            u = stack.popleft()

            if not discovered[u]:
                discovered[u] = True
                if u in unvisited_nodes:
                    unvisited_nodes.remove(u)
                ordering.append(u)
                neighbors = adj(u)
                # When adding the new nodes to the stack, we want to add them in reverse order so that
                # the order the nodes are visited is the same as with a recursive DFS implementation
                for n in neighbors[::-1]:
                    if discovered[n]:
                        # If the node already exists in the discovered nodes list
                        # we don't want to re-add it to the stack
                        continue
                    stack.appendleft(n)
                    parent_lookup[n] = u
                    children_lookup[u].append(n)

        # While there are still nodes that need visiting, repopulate the stack
        if len(unvisited_nodes) > 0:
            u = unvisited_nodes.pop()
            stack.appendleft(u)
        else:
            break

    return ordering, parent_lookup, children_lookup
501681
function depthFlatten(array, i) {
  i = i || 0;

  if(i >= array.length)
    return array;

  if(isArray(array[i])) {
    return depthFlatten(array.slice(0,i)
      .concat(array[i], array.slice(i+1)), i);
  }
  return depthFlatten(array, i+1);
}
575992
function(depth) {
        if (depth >= this.depth || depth < 0)  {
            return null;
        }

        var p = this.parent;
        
        while (p.depth > depth) {
            p = p.parent;
        }

        return p;
    }
341352
public void depthFirstSearch(Context context, SearchResultVisitor visitor, Resource root) {
        ArrayDeque<SearchResults.Result> stack = Queues.newArrayDeque();

        // Build an instance of a SearchResult for the root resource
        // but don't invoke the visitor with it
        boolean skipFirstVisit = true;
        SearchResults initialResults = new SearchResults();
        initialResults.addResult(root, new ArrayList<String>(0));
        stack.add(initialResults.iterator().next());

        while (!stack.isEmpty()) {
            SearchResults.Result r = stack.pop();
            if (skipFirstVisit) {
                skipFirstVisit = false;
            } else {
                if (!visitor.visit(r)) {
                    return;
                }
            }

            // Reverse the order of the results so we walk the left-most
            // branches first
            ImmutableList<SearchResults.Result> results = ImmutableList.copyOf(m_searcher.search(
                    context, matchKeyAndValue(Constants.PARENT_TERM_FIELD, r.getResource().getId())));
            for (SearchResults.Result result : results.reverse()) {
                stack.push(result);
            }
        }
    }
1222300
def types(*args, **kwargs):
    

    rtype = first(args)

    return Types(rtype=rtype, ptypes=kwargs)
771220
private void ssInsertionSort(int PA, int first, int last, int depth) {
        // PA, first, last are pointers in SA
        int i, j;// pointers in SA
        int t, r;

        for (i = last - 2; first <= i; --i) {
            for (t = SA[i], j = i + 1; 0 < (r = ssCompare(PA + t, PA + SA[j], depth)); ) {
                do {
                    SA[j - 1] = SA[j];
                }
                while ((++j < last) && (SA[j] < 0));
                if (last <= j) {
                    break;
                }
            }
            if (r == 0) {
                SA[j] = ~SA[j];
            }
            SA[j - 1] = t;
        }

    }
477658
function( obj, type, stack ) {
                    stack = stack || [];
                    var inStack, res,
                        parser = this.parsers[ type || this.typeOf( obj ) ];

                    type = typeof parser;
                    inStack = inArray( obj, stack );

                    if ( inStack !== -1 ) {
                        return "recursion(" + ( inStack - stack.length ) + ")";
                    }
                    if ( type === "function" ) {
                        stack.push( obj );
                        res = parser.call( this, obj, stack );
                        stack.pop();
                        return res;
                    }
                    return ( type === "string" ) ? parser : this.parsers.error;
                }
5361
function depthFirstSearch(obj, handler) {
  var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
  var reverse = arguments[3];

  var rootChildren = hp.isArray(obj) ? obj : [obj];
  //
  var StopException = function StopException() {};
  var func = function func(children, parent) {
    if (reverse) {
      children = children.slice();
      children.reverse();
    }
    var len = children.length;
    for (var i = 0; i < len; i++) {
      var item = children[i];
      var r = handler(item, i, parent);
      if (r === false) {
        // stop
        throw new StopException();
      } else if (r === 'skip children') {
        continue;
      } else if (r === 'skip siblings') {
        break;
      }
      if (item[childrenKey] != null) {
        func(item[childrenKey], item);
      }
    }
  };
  try {
    func(rootChildren);
  } catch (e) {
    if (e instanceof StopException) {
      // stop
    } else {
      throw e;
    }
  }
}
1036016
function(node, callback, depth) {
			if (this.isSkipped(node)) {
				return;
			}

			var childNode,
				childNodes = node && node.childNodes || [];

			depth = (depth || 1);

			for (var n = 0, len = childNodes.length; n < len; n++) {
				childNode = childNodes[n];

				// callback can return false to stop recursive
				if (callback(childNode, depth) !== false) {
					this.walk(childNode, callback, depth + 1);
				}
			}
		}
795079
private static Node getNextSiblingOfType(Node first, Token ... types) {
    for (Node c = first; c != null; c = c.getNext()) {
      for (Token type : types) {
        if (c.getToken() == type) {
          return c;
        }
      }
    }
    return null;
  }
66306
private void trCopy(int ISA, int first, int a, int b, int last, int depth) {
        int c, d, e;// ptr
        int s, v;

        v = b - 1;
        for (c = first, d = a - 1; c <= d; ++c) {
            s = SA[c] - depth;
            if ((0 <= s) && (SA[ISA + s] == v)) {
                SA[++d] = s;
                SA[ISA + s] = d;
            }
        }
        for (c = last - 1, e = d + 1, d = b; e < d; --c) {
            s = SA[c] - depth;
            if ((0 <= s) && (SA[ISA + s] == v)) {
                SA[--d] = s;
                SA[ISA + s] = d;
            }
        }
    }
121799
def _init_typedef(self, typedef_curr, name, lnum):
        """"""
        if typedef_curr is None:
            return TypeDef()
        msg = "PREVIOUS {REC} WAS NOT TERMINATED AS EXPECTED".format(REC=name)
        self._die(msg, lnum)
1287032
function depthFirst(uniqNodes, edges) {
    var nodeIds = Object.keys(uniqNodes);
    var totalNodes = nodeIds.length;
    debug('Found %d unique nodes: %j', totalNodes, nodeIds);

    var sortedNodes = [];
    var markedNodes = {};

    var nodeIndex = 0;
    do {
        var currentNode = uniqNodes[nodeIds[nodeIndex]];

        if (!markedNodes[currentNode.id()]) {
            visit(currentNode, edges, markedNodes, sortedNodes);
        }
    } while (++nodeIndex < totalNodes);

    return sortedNodes;
}