Skip to content

Instantly share code, notes, and snippets.

@gaxiiiiiiiiiiii
Created November 1, 2018 06:47
Show Gist options
  • Save gaxiiiiiiiiiiii/48e81bbfa27768b4d59b2ad91449004b to your computer and use it in GitHub Desktop.
Save gaxiiiiiiiiiiii/48e81bbfa27768b4d59b2ad91449004b to your computer and use it in GitHub Desktop.
def build_layer(self):
new_layer = []
if len(self.layer) % 2 == 1:
self.layer.append(self.layer[-1])
for i in range(0, len(self.layer), 2):
left = self.layer[i]
right = self.layer[i+1]
parent = Node(left.hash + right.hash)
left.parent = parent
left.sibling = right
left.position = "left"
right.parent = parent
right.sibling = left
right.position = "right"
parent.left = left
parent.right = right
new_layer.append(parent)
self.layer = new_layer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment