diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-01-08 19:33:30 +0100 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-01-08 19:33:30 +0100 |
| commit | 656e62d7242f9b58d152afecacc10de66b700e7f (patch) | |
| tree | b7fdc5ea470968cd7400c19b2a61083432d8a88a /core/container | |
| parent | f3dc1f6e3bc44831864b832153089d009191ce9c (diff) | |
Add `peek` to priority queue.
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 |