mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Merge pull request #1988 from colrdavidson/queue_peek
Add peek_front and peek_back
This commit is contained in:
@@ -99,6 +99,18 @@ get_ptr :: proc(q: ^$Q/Queue($T), #any_int i: int, loc := #caller_location) -> ^
|
|||||||
return &q.data[idx]
|
return &q.data[idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
peek_front :: proc(q: ^$Q/Queue($T), loc := #caller_location) -> ^T {
|
||||||
|
runtime.bounds_check_error_loc(loc, 0, builtin.len(q.data))
|
||||||
|
idx := q.offset%builtin.len(q.data)
|
||||||
|
return &q.data[idx]
|
||||||
|
}
|
||||||
|
|
||||||
|
peek_back :: proc(q: ^$Q/Queue($T), loc := #caller_location) -> ^T {
|
||||||
|
runtime.bounds_check_error_loc(loc, int(q.len - 1), builtin.len(q.data))
|
||||||
|
idx := (uint(q.len - 1)+q.offset)%builtin.len(q.data)
|
||||||
|
return &q.data[idx]
|
||||||
|
}
|
||||||
|
|
||||||
// Push an element to the back of the queue
|
// Push an element to the back of the queue
|
||||||
push_back :: proc(q: ^$Q/Queue($T), elem: T) -> bool {
|
push_back :: proc(q: ^$Q/Queue($T), elem: T) -> bool {
|
||||||
if space(q^) == 0 {
|
if space(q^) == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user