aboutsummaryrefslogtreecommitdiff
path: root/core/container
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2023-11-15 15:20:52 +0100
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2023-11-15 15:20:52 +0100
commit04c928fb9ed8ab7aca44b0775251c98f8eb4250e (patch)
tree8253a38d8bec853133f5814f1b6953542bb7a171 /core/container
parent354d00963c54d148215a38b3b941f2e5e1910f2b (diff)
Clear up core:container/queue
Diffstat (limited to 'core/container')
-rw-r--r--core/container/queue/queue.odin19
1 files changed, 18 insertions, 1 deletions
diff --git a/core/container/queue/queue.odin b/core/container/queue/queue.odin
index 5783cbc6c..bdc61c2a6 100644
--- a/core/container/queue/queue.odin
+++ b/core/container/queue/queue.odin
@@ -22,7 +22,9 @@ init :: proc(q: ^$Q/Queue($T), capacity := DEFAULT_CAPACITY, allocator := contex
return reserve(q, capacity)
}
-// Procedure to initialize a queue from a fixed backing slice
+// Procedure to initialize a queue from a fixed backing slice.
+// The contents of the `backing` will be overwritten as items are pushed onto the `Queue`.
+// Any previous contents are not available.
init_from_slice :: proc(q: ^$Q/Queue($T), backing: []T) -> bool {
clear(q)
q.data = transmute([dynamic]T)runtime.Raw_Dynamic_Array{
@@ -34,6 +36,21 @@ init_from_slice :: proc(q: ^$Q/Queue($T), backing: []T) -> bool {
return true
}
+// Procedure to initialize a queue from a fixed backing slice.
+// Existing contents are preserved and available on the queue.
+init_with_contents :: proc(q: ^$Q/Queue($T), backing: []T) -> bool {
+ clear(q)
+ q.data = transmute([dynamic]T)runtime.Raw_Dynamic_Array{
+ data = raw_data(backing),
+ len = builtin.len(backing),
+ cap = builtin.len(backing),
+ allocator = {procedure=runtime.nil_allocator_proc, data=nil},
+ }
+ q.len = len(backing)
+ q.offset = len(backing)
+ return true
+}
+
// Procedure to destroy a queue
destroy :: proc(q: ^$Q/Queue($T)) {
delete(q.data)