code: def _TrimNode(node, index, depth, flags):
          
          if depth == 1 or node.LeftChild is None:
              return
  
          if depth == 2:
              if not flags[index * 2] and not flags[index * 2 + 1]:
                  node.LeftChild = None
                  node.RightChild = None
  
          else:
  
              MerkleTree._TrimNode(node.LeftChild, index * 2, depth - 1, flags)
              MerkleTree._TrimNode(node.RightChild, index * 2, depth - 1, flags)
  
              if node.LeftChild.LeftChild is None and node.RightChild.RightChild is None:
                  node.LeftChild = None
                  node.RightChild = None
docs: Internal helper method to trim a node.
  
          Args:
              node (MerkleTreeNode):
              index (int): flag index.
              depth (int): node tree depth to start trim from.
              flags (bytearray): of left/right pairs. 1 byte for the left node, 1 byte for the right node.
                                  00 to erase, 11 to keep. Will keep the node if either left or right is not-0