Method: Containers::Heap#delete

Defined in:
lib/containers/heap.rb

#delete(key) ⇒ Object

call-seq: delete(key) -> value delete(key) -> nil

Deletes the item with associated key and returns it. nil is returned if the key is not found. In the case of nodes with duplicate keys, an arbitrary one is deleted.

Complexity: amortized O(log n)

minheap = MinHeap.new([1, 2])
minheap.delete(1) #=> 1
minheap.size #=> 1


300
301
302
# File 'lib/containers/heap.rb', line 300

def delete(key)
  pop if change_key(key, nil, true)
end