From 862442511a2684adecafb3688f2b7ad172a3a47d Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Wed, 11 Jun 2025 07:23:05 -0400 Subject: [PATCH] container/queue: Reorganize --- core/container/queue/queue.odin | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/core/container/queue/queue.odin b/core/container/queue/queue.odin index 9e9dec2ec..c58da3e13 100644 --- a/core/container/queue/queue.odin +++ b/core/container/queue/queue.odin @@ -86,12 +86,27 @@ get :: proc(q: ^$Q/Queue($T), #any_int i: int, loc := #caller_location) -> T { return q.data[idx] } +get_ptr :: proc(q: ^$Q/Queue($T), #any_int i: int, loc := #caller_location) -> ^T { + runtime.bounds_check_error_loc(loc, i, int(q.len)) + + idx := (uint(i)+q.offset)%builtin.len(q.data) + return &q.data[idx] +} + +set :: proc(q: ^$Q/Queue($T), #any_int i: int, val: T, loc := #caller_location) { + runtime.bounds_check_error_loc(loc, i, int(q.len)) + + idx := (uint(i)+q.offset)%builtin.len(q.data) + q.data[idx] = val +} + front :: proc(q: ^$Q/Queue($T), loc := #caller_location) -> T { when !ODIN_NO_BOUNDS_CHECK { ensure(q.len > 0, "Queue is empty.", loc) } return q.data[q.offset] } + front_ptr :: proc(q: ^$Q/Queue($T), loc := #caller_location) -> ^T { when !ODIN_NO_BOUNDS_CHECK { ensure(q.len > 0, "Queue is empty.", loc) @@ -114,18 +129,6 @@ back_ptr :: proc(q: ^$Q/Queue($T), loc := #caller_location) -> ^T { return &q.data[idx] } -set :: proc(q: ^$Q/Queue($T), #any_int i: int, val: T, loc := #caller_location) { - runtime.bounds_check_error_loc(loc, i, int(q.len)) - - idx := (uint(i)+q.offset)%builtin.len(q.data) - q.data[idx] = val -} -get_ptr :: proc(q: ^$Q/Queue($T), #any_int i: int, loc := #caller_location) -> ^T { - runtime.bounds_check_error_loc(loc, i, int(q.len)) - - idx := (uint(i)+q.offset)%builtin.len(q.data) - return &q.data[idx] -} @(deprecated="Use `front_ptr` instead") peek_front :: proc(q: ^$Q/Queue($T), loc := #caller_location) -> ^T {