diff options
| author | flysand7 <yyakut.ac@gmail.com> | 2023-12-06 00:23:41 +1100 |
|---|---|---|
| committer | flysand7 <yyakut.ac@gmail.com> | 2023-12-06 00:23:41 +1100 |
| commit | 92d3a681cd6cc2aceb0865d4bffdf8a112f6f0d6 (patch) | |
| tree | 6feb95445ee9f39f3c4e1dadc1ecb9d0410ec0c1 /core/container | |
| parent | cb66ed52cefde3274b9b055a1fecbf938e4b5155 (diff) | |
| parent | 65afe6f70d6baa2d4070791325701e38d6f2df61 (diff) | |
Merge branch 'master' into sys-linux-additions
Diffstat (limited to 'core/container')
| -rw-r--r-- | core/container/queue/queue.odin | 19 | ||||
| -rw-r--r-- | core/container/topological_sort/topological_sort.odin | 12 |
2 files changed, 25 insertions, 6 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) diff --git a/core/container/topological_sort/topological_sort.odin b/core/container/topological_sort/topological_sort.odin index 314e3e070..f1e9bf57b 100644 --- a/core/container/topological_sort/topological_sort.odin +++ b/core/container/topological_sort/topological_sort.odin @@ -80,11 +80,13 @@ sort :: proc(sorter: ^$S/Sorter($K)) -> (sorted, cycled: [dynamic]K) { } } - for root in sorted do for k, _ in relations[root].dependents { - relation := &relations[k] - relation.dependencies -= 1 - if relation.dependencies == 0 { - append(&sorted, k) + for root in sorted { + for k, _ in relations[root].dependents { + relation := &relations[k] + relation.dependencies -= 1 + if relation.dependencies == 0 { + append(&sorted, k) + } } } |