3 def bubble_up(heap, i, key):
4 # call with key == tuple(heap[i, :])
7 if key >= tuple(heap[parent, :]):
9 heap[i, :] = heap[parent, :]
11 heap[i, :] = numpy.array(key, heap.dtype)
13 def bubble_down(heap, i, key, n):
14 # call with key == tuple(heap[i, :])
17 child_key = tuple(heap[child, :])
20 child1_key = tuple(heap[child1, :])
21 if child1_key < child_key:
23 child_key = child1_key
26 heap[i, :] = heap[child, :]
29 heap[i, :] = numpy.array(key, heap.dtype)
32 for i in range((n - 1) >> 1, -1, -1):
33 bubble_down(heap, i, tuple(heap[i, :]), n)