mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
* fix #14139 * Update lib/pure/collections/heapqueue.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Clyybber <darkmine956@gmail.com>
This commit is contained in:
@@ -156,10 +156,10 @@ proc replace*[T](heap: var HeapQueue[T], item: T): T =
|
||||
|
||||
proc pushpop*[T](heap: var HeapQueue[T], item: T): T =
|
||||
## Fast version of a push followed by a pop.
|
||||
if heap.len > 0 and heapCmp(heap[0], item):
|
||||
swap(item, heap[0])
|
||||
result = item
|
||||
if heap.len > 0 and heapCmp(heap.data[0], item):
|
||||
swap(result, heap.data[0])
|
||||
siftup(heap, 0)
|
||||
return item
|
||||
|
||||
proc clear*[T](heap: var HeapQueue[T]) =
|
||||
## Remove all elements from `heap`, making it empty.
|
||||
|
||||
9
tests/stdlib/t14139.nim
Normal file
9
tests/stdlib/t14139.nim
Normal file
@@ -0,0 +1,9 @@
|
||||
import heapqueue
|
||||
|
||||
var test_queue : HeapQueue[int]
|
||||
|
||||
test_queue.push(7)
|
||||
test_queue.push(3)
|
||||
test_queue.push(9)
|
||||
let i = test_queue.pushpop(10)
|
||||
assert i == 3
|
||||
Reference in New Issue
Block a user