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
292 293 294 |
# File 'lib/containers/heap.rb', line 292 def delete(key) pop if change_key(key, nil, true) end |