A helper function for determining all of the branches in the
            tree. This should be called after the tree has been fully
            constructed and its nodes and edges are populated.
333057
def _identifyBranches(self):
        

        if self.debug:
            sys.stdout.write("Identifying branches: ")
            start = time.clock()

        seen = set()
        self.branches = set()

        # Find all of the branching nodes in the tree, degree > 1
        # That is, they appear in more than one edge
        for e1, e2 in self.edges:
            if e1 not in seen:
                seen.add(e1)
            else:
                self.branches.add(e1)

            if e2 not in seen:
                seen.add(e2)
            else:
                self.branches.add(e2)

        if self.debug:
            end = time.clock()
            sys.stdout.write("%f s\n" % (end - start))
1068999
def get_branches(grid):
    

    station = grid._station

    tree = nx.dfs_tree(grid._graph, station)

    # TODO: idea
    # 1. build tree from lv_grid station as root -> diretions should point to
    # descending leafs
    # 2. for analysis of current issues get list of descendants with
    # nx.descendants(tree, station). Sum peak load / gen capacity
    # 3. Extract nodes belonging to main route of a branch by checking all
    # successors if these are LVCalbleDistributors
    # notes and hints:
    # 1. associated edges can be accessed via grid._graph.in_edges(<node>)
    # respectively grid._graph.out_edges(<node>)
    # 2. when using nx.descendants(tree, station) make sure the order of nodes
    # is maintained as this is important to properly assess voltage and over-
    # loading issues

    # first_cbl_dists = [x for x in grid._graph.neighbors(station)
    #                    if isinstance(x, LVCableDistributorDing0)]


    # if len(first_cbl_dists) > 0:
    #     ancestors =  nx.ancestors(grid._graph, first_cbl_dists[0])
    # else:
    #     ancestors = None
    # return ancestors
    branch_heads = list(nx.neighbors(tree, station))

    descendants = {branch_head: list(nx.descendants(tree, branch_head)) for
                   branch_head in branch_heads}



    return descendants
355768
private void postTraversalProcessing() {
		int nc1 = treeSize;
		info[KR] = new int[leafCount];
		info[RKR] = new int[leafCount];

		int lc = leafCount;
		int i = 0;

		// compute left-most leaf descendants
		// go along the left-most path, remember each node and assign to it the path's
		// leaf
		// compute right-most leaf descendants (in reversed postorder)
		for (i = 0; i < treeSize; i++) {
			if (paths[LEFT][i] == -1) {
				info[POST2_LLD][i] = i;
			} else {
				info[POST2_LLD][i] = info[POST2_LLD][paths[LEFT][i]];
			}
			if (paths[RIGHT][i] == -1) {
				info[RPOST2_RLD][treeSize - 1 - info[POST2_PRE][i]] =
						(treeSize - 1 - info[POST2_PRE][i]);
			} else {
				info[RPOST2_RLD][treeSize - 1 - info[POST2_PRE][i]] =
						info[RPOST2_RLD][treeSize - 1
								- info[POST2_PRE][paths[RIGHT][i]]];
			}
		}

		// compute key root nodes
		// compute reversed key root nodes (in revrsed postorder)
		boolean[] visited = new boolean[nc1];
		boolean[] visitedR = new boolean[nc1];
		Arrays.fill(visited, false);
		int k = lc - 1;
		int kR = lc - 1;
		for (i = nc1 - 1; i >= 0; i--) {
			if (!visited[info[POST2_LLD][i]]) {
				info[KR][k] = i;
				visited[info[POST2_LLD][i]] = true;
				k--;
			}
			if (!visitedR[info[RPOST2_RLD][i]]) {
				info[RKR][kR] = i;
				visitedR[info[RPOST2_RLD][i]] = true;
				kR--;
			}
		}

		// compute minimal key roots for every subtree
		// compute minimal reversed key roots for every subtree (in reversed postorder)
		int parent = -1;
		int parentR = -1;
		for (i = 0; i < leafCount; i++) {
			parent = info[KR][i];
			while (parent > -1 && info[POST2_MIN_KR][parent] == -1) {
				info[POST2_MIN_KR][parent] = i;
				parent = info[POST2_PARENT][parent];
			}
			parentR = info[RKR][i];
			while (parentR > -1 && info[RPOST2_MIN_RKR][parentR] == -1) {
				info[RPOST2_MIN_RKR][parentR] = i;
				parentR =
						info[POST2_PARENT][info[RPOST2_POST][parentR]]; // get parent's postorder
				if (parentR > -1) {
					parentR = treeSize - 1 - info[POST2_PRE][parentR]; // if parent exists get its
					// rev. postorder
				}
			}
		}
	}
449574
public function calculateAllTrees()
    {
        $fields = $this->formObject->getConfiguration()->getFields();

        foreach ($fields as $field) {
            $this->getActivationConditionTreeForField($field);

            foreach ($field->getValidation() as $validation) {
                $this->getActivationConditionTreeForValidation($validation);
            }
        }
    }
843266
def check
      branch_depth = nil

      traverse do |node, position, stack|
        if position == 0
          # Nodes should have between min_size() and
          # @tree.node_size children or values. Only the root node may have
          # less.
          if node.size > @tree.node_size
            node.error "BigArray node #{node._id} is too large. It has " +
              "#{node.size} nodes instead of max. #{@tree.node_size}."
            return false
          end
          if node.parent && node.size < min_size
            node.error "BigArray node #{node._id} is too small"
            return false
          end

          if node.is_leaf?
            # All leaf nodes must have same distance from root node.
            if branch_depth
              unless branch_depth == stack.size
                node.error "All leaf nodes must have same distance from root"
                return false
              end
            else
              branch_depth = stack.size
            end

            return false unless node.check_leaf_node_links

            if node.children
              node.error "children must be nil for a leaf node"
              return false
            end
          else
            unless node.children.size == node.offsets.size
              node.error "Offset count (#{node.offsets.size}) must be equal " +
                "to children count (#{node.children.size})"
                return false
            end

            if node.values
              node.error "values must be nil for a branch node"
              return false
            end

            unless @prev_sibling.nil? && @next_sibling.nil?
              node.error "prev_sibling and next_sibling must be nil for " +
                "branch nodes"
            end

            return false unless node.check_offsets

            return false unless node.check_child_nodes(stack)
          end
        elsif position <= node.size
          # These checks are done after we have completed the respective child
          # node with index 'position - 1'.
          index = position - 1
          if node.is_leaf?
            if block_given?
              # If a block was given, call this block with the key and value.
              return false unless yield(node.first_index + index,
                                        node.values[index])
            end
          end
        end
      end

      true
    end
1205821
public void gotoEnd() {
	currentNode = tree;
	while (currentNode.hasChildren()) {
	    currentNode = currentNode.getChildren().get(
		    currentNode.getChildren().size() - 1);
	}
    }
267546
def branch(self):
        
        branch = [self]
        for c in self.children:
            branch += c.branch()
        return branch
1122772
function findAll (tree, test) {
  var found = test(tree) ? [tree] : []
  if (isNode(tree)) {
    if (tree.children.length > 0) {
      tree.children.forEach(function (child) {
        found = found.concat(findAll(child, test))
      })
    }
  }

  return found
}
1115588
def leaf_nodes(self):
        
        # Now contains all nodes that contain dependencies.
        deps = {item for sublist in self.edges.values() for item in sublist}
        # contains all nodes *without* any dependencies (leaf nodes)
        return self.nodes - deps
701975
function (oTree, bSelected) {
			oTree.selected = bSelected;
			for (var i = 0; i < oTree.nodes.length; i++) {
				this.recursiveSelect(oTree.nodes[i], bSelected);
			}
		}
310227
def _build_tree(self):
        
        if not self.nn_ready:
            self.kdtree   = scipy.spatial.cKDTree(self.data)
            self.nn_ready = True
427379
function() {
//		this.debug("fixSelection3FromEndNodes()");
		_assert(this.tree.options.selectMode === 3, "expected selectMode 3");

		// Visit all end nodes and adjust their parent's `selected` and `partsel`
		// attributes. Return selection state true, false, or undefined.
		function _walk(node){
			var i, l, child, s, state, allSelected,someSelected,
				children = node.children;

			if( children && children.length ){
				// check all children recursively
				allSelected = true;
				someSelected = false;

				for( i=0, l=children.length; i<l; i++ ){
					child = children[i];
					// the selection state of a node is not relevant; we need the end-nodes
					s = _walk(child);
					if( s !== false ) {
						someSelected = true;
					}
					if( s !== true ) {
						allSelected = false;
					}
				}
				state = allSelected ? true : (someSelected ? undefined : false);
			}else{
				// This is an end-node: simply report the status
//				state = ( node.unselectable ) ? undefined : !!node.selected;
				state = !!node.selected;
			}
			node._changeSelectStatusAttrs(state);
			return state;
		}
		_walk(this);

		// Update parent's state
		this.visitParents(function(node){
			var i, l, child, state,
				children = node.children,
				allSelected = true,
				someSelected = false;

			for( i=0, l=children.length; i<l; i++ ){
				child = children[i];
				// When fixing the parents, we trust the sibling status (i.e.
				// we don't recurse)
				if( child.selected || child.partsel ) {
					someSelected = true;
				}
				if( !child.unselectable && !child.selected ) {
					allSelected = false;
				}
			}
			state = allSelected ? true : (someSelected ? undefined : false);
			node._changeSelectStatusAttrs(state);
		});
	}
854617
public void checkTree() {
		Map<TreeNode, TreeNode> nodes = this.useIdentity ? new IdentityHashMap<TreeNode, TreeNode>()
				:new HashMap<TreeNode,TreeNode>();
		
		// Traverse the tree and check if each node is only used once.
		addUniqueNodes(nodes,tree.getRoot());
	}
719173
function(node) {
    if (node) {
        this.start = {
            line: node.start.line,
            column: node.start.column
        };
        this.end = {
            line: node.end.line,
            column: node.end.column
        };
        this.offset = {
            start: node.start.offset,
            end: node.end.offset
        };
    }
}
406495
def if_node(node, indent)
      # Check if we have any condition met, or an else branch
      node[@value].each_with_index do |value, index|
        # If we have a branch that meets the condition, generate code for the
        # children related to that specific branch
        case value
        when node[@value].first then buffer_eval "if #{value}"
        when node[@value].last then buffer_eval "else"
        else buffer_eval "elsif #{value}"
        end

        # Evaluate child nodes
        node[@children][index].each do |child|
          root child, indent
        end
      end

      # End
      buffer_eval "end"
    end
1081922
boolean treeFinished(treeNode root){
		return (root.parent == null && root.lc == null && root.rc == null);
	}
1102830
function(branch, obj) {
  var names = _.map(branch.children, getName);
  var name = getName(obj);
  return _.contains(names, name);
}