diff options
| author | gingerBill <bill@gingerbill.org> | 2024-01-09 11:01:24 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-01-09 11:01:24 +0000 |
| commit | 72dfb73c9d375e2ee280398e40cdcc2d3415ee24 (patch) | |
| tree | 1a0f772b7ae76132b8fc3167dcd9ed8b2c327110 /core/container | |
| parent | 67dcd916e8f7b1badef5c6beee621557b069db3c (diff) | |
| parent | efb2b050400e7e566d7f4a1e3695c09d75059945 (diff) | |
Merge branch 'master' of https://github.com/odin-lang/Odin
Diffstat (limited to 'core/container')
| -rw-r--r-- | core/container/priority_queue/priority_queue.odin | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/core/container/priority_queue/priority_queue.odin b/core/container/priority_queue/priority_queue.odin index 0c5c4931d..0c43816e1 100644 --- a/core/container/priority_queue/priority_queue.odin +++ b/core/container/priority_queue/priority_queue.odin @@ -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 +}
\ No newline at end of file |