mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 13:00:28 +00:00
Add peek to priority queue.
This commit is contained in:
@@ -140,3 +140,18 @@ remove :: proc(pq: ^$Q/Priority_Queue($T), i: int) -> (value: T, ok: bool) {
|
||||
return
|
||||
}
|
||||
|
||||
peek_safe :: proc(pq: $Q/Priority_Queue($T), loc := #caller_location) -> (res: T, ok: bool) {
|
||||
if builtin.len(pq.queue) > 0 {
|
||||
return pq.queue[0], true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
peek :: proc(pq: $Q/Priority_Queue($T), loc := #caller_location) -> (res: T) {
|
||||
assert(condition=builtin.len(pq.queue)>0, loc=loc)
|
||||
|
||||
if builtin.len(pq.queue) > 0 {
|
||||
return pq.queue[0]
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user