def sift_down()

in heap.py [0:0]


    def sift_down(self, pos):
        root = pos
        if root in self.invalid_pos:
            return
        while self.has_child(root):
            left_child = self.left_child(root)
            right_child = self.right_child(root)

            if left_child in self.invalid_pos:
                self.push_invalid(left_child)
            if right_child < len(self.data) and right_child in self.invalid_pos:
                self.push_invalid(right_child)

            if left_child in self.invalid_pos:
                if right_child >= len(self.data) or right_child in self.invalid_pos:
                    break
                else:
                    child = right_child
            else:
                if right_child >= len(self.data) or right_child in self.invalid_pos:
                    child = left_child
                else:
                    child = left_child if self.cmp(self.data[left_child], self.data[right_child]) else right_child

            if self.cmp(self.data[child], self.data[root]):
                self._swap_pos(root, child)
                root = child
            else:
                break
        self.clean_invalid()