mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Clear up core:container/queue
This commit is contained in:
@@ -22,7 +22,9 @@ init :: proc(q: ^$Q/Queue($T), capacity := DEFAULT_CAPACITY, allocator := contex
|
|||||||
return reserve(q, capacity)
|
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 {
|
init_from_slice :: proc(q: ^$Q/Queue($T), backing: []T) -> bool {
|
||||||
clear(q)
|
clear(q)
|
||||||
q.data = transmute([dynamic]T)runtime.Raw_Dynamic_Array{
|
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
|
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
|
// Procedure to destroy a queue
|
||||||
destroy :: proc(q: ^$Q/Queue($T)) {
|
destroy :: proc(q: ^$Q/Queue($T)) {
|
||||||
delete(q.data)
|
delete(q.data)
|
||||||
|
|||||||
Reference in New Issue
Block a user