def construct(self, total_leaves):
    # Ensure that the total number of leaves is a power of two
    depth = np.log(total_leaves) / np.log(2)
    assert depth.is_integer(), 'The total leaves must be a power of two'
    ###
    # Create all the leaf nodes and then combine them until only one exists
    # A B C D
    # C D [A B]
    # [A B] [C D]
    # [[A B] [C D]]
    ###
    queue = [HAMNode(tree=self, left=None, right=None) for leaf in xrange(total_leaves)]
    self.leaves = [leaf for leaf in queue]
    self.nodes = [leaf for leaf in queue]
    while len(queue) > 1:
      l, r = queue.pop(0), queue.pop(0)
      node = HAMNode(tree=self, left=l, right=r)
      queue.append(node)
      self.nodes.append(node)
    self.root = queue[0]
dataset/ETHPy150Open Smerity/tf-ham/ham.py/HAMTree.construct/original