mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
container/queue: Let queues be re-initialized with different allocators
This commit is contained in:
@@ -23,10 +23,13 @@ DEFAULT_CAPACITY :: 16
|
|||||||
Initialize a `Queue` with a starting `capacity` and an `allocator`.
|
Initialize a `Queue` with a starting `capacity` and an `allocator`.
|
||||||
*/
|
*/
|
||||||
init :: proc(q: ^$Q/Queue($T), capacity := DEFAULT_CAPACITY, allocator := context.allocator) -> runtime.Allocator_Error {
|
init :: proc(q: ^$Q/Queue($T), capacity := DEFAULT_CAPACITY, allocator := context.allocator) -> runtime.Allocator_Error {
|
||||||
if q.data.allocator.procedure == nil {
|
|
||||||
q.data.allocator = allocator
|
|
||||||
}
|
|
||||||
clear(q)
|
clear(q)
|
||||||
|
q.data = transmute([dynamic]T)runtime.Raw_Dynamic_Array{
|
||||||
|
data = nil,
|
||||||
|
len = 0,
|
||||||
|
cap = 0,
|
||||||
|
allocator = allocator,
|
||||||
|
}
|
||||||
return reserve(q, capacity)
|
return reserve(q, capacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user