aboutsummaryrefslogtreecommitdiff
path: root/core/container/queue/queue.odin
diff options
context:
space:
mode:
authorCiD- <jkercher43@gmail.com>2022-01-14 10:17:49 -0500
committerCiD- <jkercher43@gmail.com>2022-01-14 10:17:49 -0500
commit6cf5371d7d55038c0d0789c240813e1be08c0107 (patch)
tree2f3dc468e6de52480237ff152a26c41bcfd175a0 /core/container/queue/queue.odin
parente15f71466005ff84c6dc97cbfbd10d57f1193e7a (diff)
fix push_back and pop_front
Diffstat (limited to 'core/container/queue/queue.odin')
-rw-r--r--core/container/queue/queue.odin5
1 files changed, 4 insertions, 1 deletions
diff --git a/core/container/queue/queue.odin b/core/container/queue/queue.odin
index ff1e85fbd..feca6934c 100644
--- a/core/container/queue/queue.odin
+++ b/core/container/queue/queue.odin
@@ -86,7 +86,8 @@ push_back :: proc(q: ^$Q/Queue($T), elem: T) -> bool {
if space(q^) == 0 {
_grow(q) or_return
}
- q.data[q.len] = elem
+ idx := (q.offset+uint(q.len))%builtin.len(q.data)
+ q.data[idx] = elem
q.len += 1
return true
}
@@ -126,6 +127,7 @@ pop_back_safe :: proc(q: ^$Q/Queue($T)) -> (elem: T, ok: bool) {
pop_front :: proc(q: ^$Q/Queue($T), loc := #caller_location) -> (elem: T) {
assert(condition=q.len > 0, loc=loc)
elem = q.data[q.offset]
+ q.offset = (q.offset+1)%builtin.len(q.data)
q.len -= 1
return
}
@@ -133,6 +135,7 @@ pop_front :: proc(q: ^$Q/Queue($T), loc := #caller_location) -> (elem: T) {
pop_front_safe :: proc(q: ^$Q/Queue($T)) -> (elem: T, ok: bool) {
if q.len > 0 {
elem = q.data[q.offset]
+ q.offset = (q.offset+1)%builtin.len(q.data)
q.len -= 1
ok = true
}