code: def extend(self, new_leaves: List[bytes]):
          
          size = len(new_leaves)
          final_size = self.tree_size + size
          idx = 0
          while True:
              # keep pushing subtrees until mintree_size > remaining
              max_h = self.__mintree_height
              max_size = 1 << (max_h - 1) if max_h > 0 else 0
              if max_h > 0 and size - idx >= max_size:
                  self._push_subtree(new_leaves[idx:idx + max_size])
                  idx += max_size
              else:
                  break
          # fill in rest of tree in one go, now that we can
          if idx < size:
              root_hash, hashes = self.__hasher._hash_full(new_leaves, idx, size)
              self._update(final_size, self.hashes + hashes)
          assert self.tree_size == final_size
docs: Extend this tree with new_leaves on the end.
  
          The algorithm works by using _push_subtree() as a primitive, calling
          it with the maximum number of allowed leaves until we can add the
          remaining leaves as a valid entire (non-full) subtree in one go.