MCPcopy Create free account
hub / github.com/ActiveState/code / removeValue

Method removeValue

recipes/Python/577898_23_Tree/recipe-577898.py:454–466  ·  view source on GitHub ↗

Removes a value from the tree and keeps it balanced

(self, a)

Source from the content-addressed store, hash-verified

452 for item in xs: self.insertValue(item)
453
454 def removeValue(self, a):
455 """ Removes a value from the tree and keeps it balanced """
456 node = self.findNode(a)
457 if not node or not node.contains(a):
458 return None
459 # swap the value we want to delete with its inorder successor (always leaf)
460 succ = self.findInorderSucc(node, a)
461 self.__swapValues(node, a, succ, succ.values[0])
462 # delete leaf node value
463 succ.removeValue(a)
464 # fix tree if needed
465 self.__fixNodeRemove(succ)
466 return self
467
468 def removeList(self, xs):
469 """ Deletes a list of values from a tree """

Callers 1

removeListMethod · 0.95

Calls 6

findNodeMethod · 0.95
findInorderSuccMethod · 0.95
__swapValuesMethod · 0.95
__fixNodeRemoveMethod · 0.95
containsMethod · 0.45
removeValueMethod · 0.45

Tested by

no test coverage detected