nodes: 0, module; 1, function_definition; 2, function_name:_push_subtree; 3, parameters; 4, block; 5, identifier:self; 6, typed_parameter; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, comment:# in general we want the highest bit, but here it's also the lowest bit; 11, comment:# so just reuse that code instead of writing a new highest_bit_set(); 12, expression_statement; 13, if_statement; 14, expression_statement; 15, assert_statement; 16, if_statement; 17, expression_statement; 18, expression_statement; 19, if_statement; 20, identifier:leaves; 21, type; 22, comment:"""Extend with a full subtree <= the current minimum subtree.
  
          The leaves must form a full subtree, i.e. of size 2^k for some k. If
          there is a minimum subtree (i.e. __mintree_height > 0), then the input
          subtree must be smaller or of equal size to the minimum subtree.
  
          If the subtree is smaller (or no such minimum exists, in an empty tree),
          we can simply append its hash to self.hashes, since this maintains the
          invariant property of being sorted in descending size order.
  
          If the subtree is of equal size, we are in a similar situation to an
          addition carry. We handle it by combining the two subtrees into a larger
          subtree (of size 2^(k+1)), then recursively trying to add this new
          subtree back into the tree.
  
          Any collection of leaves larger than the minimum subtree must undergo
          additional partition to conform with the structure of a merkle tree,
          which is a more complex operation, performed by extend().
          """; 23, assignment; 24, comparison_operator:count_bits_set(size) != 1; 25, block; 26, assignment; 27, boolean_operator; 28, block; 29, assignment; 30, comparison_operator:hashes == (root_hash,); 31, attribute; 32, block; 33, assignment; 34, assignment; 35, attribute; 36, block; 37, generic_type; 38, identifier:size; 39, call; 40, call; 41, integer:1; 42, raise_statement; 43, pattern_list; 44, expression_list; 45, comparison_operator:mintree_h > 0; 46, comparison_operator:subtree_h > mintree_h; 47, raise_statement; 48, pattern_list; 49, call; 50, identifier:hashes; 51, tuple; 52, identifier:self; 53, identifier:hashStore; 54, for_statement; 55, identifier:new_node_hashes; 56, call; 57, identifier:nodes; 58, list_comprehension; 59, identifier:self; 60, identifier:hashStore; 61, for_statement; 62, identifier:List; 63, type_parameter; 64, identifier:len; 65, argument_list; 66, identifier:count_bits_set; 67, argument_list; 68, call; 69, identifier:subtree_h; 70, identifier:mintree_h; 71, call; 72, attribute; 73, identifier:mintree_h; 74, integer:0; 75, identifier:subtree_h; 76, identifier:mintree_h; 77, call; 78, identifier:root_hash; 79, identifier:hashes; 80, attribute; 81, argument_list; 82, identifier:root_hash; 83, identifier:h; 84, identifier:hashes; 85, block; 86, attribute; 87, argument_list; 88, tuple; 89, for_in_clause; 90, identifier:node; 91, identifier:nodes; 92, block; 93, type; 94, identifier:leaves; 95, identifier:size; 96, identifier:ValueError; 97, argument_list; 98, identifier:lowest_bit_set; 99, argument_list; 100, identifier:self; 101, identifier:__mintree_height; 102, identifier:ValueError; 103, argument_list; 104, attribute; 105, identifier:_hash_full; 106, identifier:leaves; 107, integer:0; 108, identifier:size; 109, expression_statement; 110, identifier:self; 111, identifier:__push_subtree_hash; 112, identifier:subtree_h; 113, identifier:root_hash; 114, attribute; 115, identifier:height; 116, identifier:h; 117, pattern_list; 118, identifier:new_node_hashes; 119, expression_statement; 120, identifier:bytes; 121, binary_operator:"invalid subtree with size != 2^k: %s" % size; 122, identifier:size; 123, binary_operator:"subtree %s > current smallest subtree %s" % (
                  subtree_h, mintree_h); 124, identifier:self; 125, identifier:__hasher; 126, call; 127, identifier:self; 128, identifier:tree_size; 129, identifier:h; 130, identifier:height; 131, call; 132, string:"invalid subtree with size != 2^k: %s"; 133, identifier:size; 134, string:"subtree %s > current smallest subtree %s"; 135, tuple; 136, attribute; 137, argument_list; 138, attribute; 139, argument_list; 140, identifier:subtree_h; 141, identifier:mintree_h; 142, attribute; 143, identifier:writeLeaf; 144, identifier:h; 145, attribute; 146, identifier:writeNode; 147, identifier:node; 148, identifier:self; 149, identifier:hashStore; 150, identifier:self; 151, identifier:hashStore
code: def _push_subtree(self, leaves: List[bytes]):
          """Extend with a full subtree <= the current minimum subtree.
  
          The leaves must form a full subtree, i.e. of size 2^k for some k. If
          there is a minimum subtree (i.e. __mintree_height > 0), then the input
          subtree must be smaller or of equal size to the minimum subtree.
  
          If the subtree is smaller (or no such minimum exists, in an empty tree),
          we can simply append its hash to self.hashes, since this maintains the
          invariant property of being sorted in descending size order.
  
          If the subtree is of equal size, we are in a similar situation to an
          addition carry. We handle it by combining the two subtrees into a larger
          subtree (of size 2^(k+1)), then recursively trying to add this new
          subtree back into the tree.
  
          Any collection of leaves larger than the minimum subtree must undergo
          additional partition to conform with the structure of a merkle tree,
          which is a more complex operation, performed by extend().
          """
          size = len(leaves)
          if count_bits_set(size) != 1:
              raise ValueError("invalid subtree with size != 2^k: %s" % size)
          # in general we want the highest bit, but here it's also the lowest bit
          # so just reuse that code instead of writing a new highest_bit_set()
          subtree_h, mintree_h = lowest_bit_set(size), self.__mintree_height
          if mintree_h > 0 and subtree_h > mintree_h:
              raise ValueError("subtree %s > current smallest subtree %s" % (
                  subtree_h, mintree_h))
          root_hash, hashes = self.__hasher._hash_full(leaves, 0, size)
          assert hashes == (root_hash,)
  
          if self.hashStore:
              for h in hashes:
                  self.hashStore.writeLeaf(h)
  
          new_node_hashes = self.__push_subtree_hash(subtree_h, root_hash)
  
          nodes = [(self.tree_size, height, h) for h, height in new_node_hashes]
          if self.hashStore:
              for node in nodes:
                  self.hashStore.writeNode(node)