Returns a new tree equal to this tree extended with new_leaves.
438584
def extended(self, new_leaves: List[bytes]):
        """"""
        new_tree = self.__copy__()
        new_tree.extend(new_leaves)
        return new_tree
646130
public Tree<T> addLeaf( T child )
    {
        Tree<T> leaf = new Tree<T>( child );
        leaf.parent = this;
        children.add( leaf );
        return leaf;
    }
729842
def build_leaf(object)
      this = self
      run_validator = method(:run_validator)
      check_types = method(:check_types)

      object.instance_exec do
        define_singleton_method(this.name) { this.value }
        define_singleton_method("#{this.name}=") do |value|
          run_validator.call(value)
          check_types.call(value)
          this.value = value
        end
      end

      object
    end
1056542
def get_tree(cls, parent=None):
        
        if parent:
            depth = parent.get_depth() + 1
            results = [parent]
        else:
            depth = 1
            results = []
        cls._get_tree_recursively(results, parent, depth)
        return results
839878
def uproot(tree):
        
        uprooted = tree.copy()
        uprooted.parent = None
        for child in tree.all_children():
            uprooted.add_general_child(child)
        return uprooted
212450
def add_root(cls, **kwargs):
        """"""

        if len(kwargs) == 1 and 'instance' in kwargs:
            # adding the passed (unsaved) instance to the tree
            newobj = kwargs['instance']
            if newobj.pk:
                raise NodeAlreadySaved("Attempted to add a tree node that is "\
                    "already in the database")
        else:
            newobj = cls(**kwargs)

        newobj._cached_depth = 1
        if not cls.node_order_by:
            try:
                max = get_result_class(cls).objects.filter(
                    parent__isnull=True).order_by(
                    'sib_order').reverse()[0].sib_order
            except IndexError:
                max = 0
            newobj.sib_order = max + 1
        newobj.save()
        return newobj
386211
def create_tree(self):
        
        feature_indices = []
        for i in self.estimator.tree_.feature:
            n_features = self.n_features
            if self.n_features > 1 or (self.n_features == 1 and i >= 0):
                feature_indices.append([str(j) for j in range(n_features)][i])
        indentation = 1 if self.target_language in ['java', 'js',
                                                    'php', 'ruby'] else 0
        return self.create_branches(
            self.estimator.tree_.children_left,
            self.estimator.tree_.children_right,
            self.estimator.tree_.threshold,
            self.estimator.tree_.value,
            feature_indices, 0, indentation)
284225
def clone(self):
        """"""
        return Leaf(self.type, self.value,
                    (self.prefix, (self.lineno, self.column)),
                    fixers_applied=self.fixers_applied)
1206650
def leaves(self, unique=True):
        """"""
        if not self.children:
            return [self]
        else:
            res = list()
            for child in self.children:
                for sub_child in child.leaves(unique=unique):
                    if not unique or sub_child not in res:
                        res.append(sub_child)
            return res
181534
def get_subtree(self, root):
        
        if not isinstance(root, Tree):
            self.log_exc(u"root is not an instance of Tree", None, True, TypeError)
        new_text_file = TextFile()
        new_text_file.fragments_tree = root
        return new_text_file
1230896
def fromtree(cls, tree):
        
        mets = cls()
        mets.tree = tree
        mets._parse_tree(tree)

        return mets
719193
def __internal_union(self, root_a, root_b):
        
        # Merge the trees, smaller to larger
        update_rank = False
        # --Determine the larger tree
        rank_a = self.__forest[root_a]
        rank_b = self.__forest[root_b]
        if rank_a < rank_b:
            larger = root_b
            smaller = root_a
        else:
            larger = root_a
            smaller = root_b
            if rank_a == rank_b:
                update_rank = True
        # --Make the smaller tree a subtree of the larger tree
        self.__forest[smaller] = larger
        # --Update the rank of the new tree (if necessary)
        if update_rank:
            self.__forest[larger] -= 1
408012
def new_children(self, **kwargs):
        """"""
        for k, v in kwargs.items():
            self.new_child(k, v)

        return self
196940
def add_child(tree_node)
      return if tree_node.parent == self
      if not tree_node.parent.nil?
        tree_node.remove_from_parent
      else
        tree_node.prefix_path = nil
      end
      tree_node.invalidate
      tree_node.parent = self
      if @children.length > 0
        @children.last.next = tree_node
        tree_node.prev      = @children.last
      else
        tree_node.prev = nil
      end
      tree_node.next = nil
      @children << tree_node
      @leaves_and_children << tree_node
      self
    end
145987
def __Build(leaves):
        
        if len(leaves) < 1:
            raise Exception('Leaves must have length')
        if len(leaves) == 1:
            return leaves[0]

        num_parents = int((len(leaves) + 1) / 2)
        parents = [MerkleTreeNode() for i in range(0, num_parents)]

        for i in range(0, num_parents):
            node = parents[i]
            node.LeftChild = leaves[i * 2]
            leaves[i * 2].Parent = node
            if (i * 2 + 1 == len(leaves)):
                node.RightChild = node.LeftChild
            else:
                node.RightChild = leaves[i * 2 + 1]
                leaves[i * 2 + 1].Parent = node

            hasharray = bytearray(node.LeftChild.Hash.ToArray() + node.RightChild.Hash.ToArray())
            node.Hash = UInt256(data=Crypto.Hash256(hasharray))

        return MerkleTree.__Build(parents)
925541
def get_tree_root(self):
        
        root = self
        while root.up is not None:
            root = root.up
        return root
296199
def new_child(self):
        
        child = Environment(self.globals, self.max_things)
        child.scopes = self.scopes.new_child()
        child.things = WeakSet(self.things)
        return child