aboutsummaryrefslogtreecommitdiff
path: root/core/container/priority_queue
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-01-01 13:11:53 +0000
committergingerBill <bill@gingerbill.org>2022-01-01 13:11:53 +0000
commit70ed280c5ac47bd96d07878044867ec72ab94391 (patch)
tree3679f025feb91d2a4f01e715c666f3fd92b91132 /core/container/priority_queue
parent0d7cb02386c765f6f4fe343b463e84c3a7c1d1fc (diff)
Fix typo in priority_queue.odin and add `default_swap_proc`
Diffstat (limited to 'core/container/priority_queue')
-rw-r--r--core/container/priority_queue/priority_queue.odin8
1 files changed, 7 insertions, 1 deletions
diff --git a/core/container/priority_queue/priority_queue.odin b/core/container/priority_queue/priority_queue.odin
index df26edb1b..2bdb3c777 100644
--- a/core/container/priority_queue/priority_queue.odin
+++ b/core/container/priority_queue/priority_queue.odin
@@ -11,6 +11,12 @@ Priority_Queue :: struct($T: typeid) {
DEFAULT_CAPACITY :: 16
+default_swap_proc :: proc($T: typeid) -> proc(q: []T, i, j: int) {
+ return proc(q: []T, i, j: int) {
+ q[i], q[j] = q[j], q[i]
+ }
+}
+
init :: proc(pq: ^$Q/Priority_Queue($T), less: proc(a, b: T) -> bool, swap: proc(q: []T, i, j: int), capacity := DEFAULT_CAPACITY, allocator := context.allocator) {
if pq.queue.allocator.procedure == nil {
pq.queue.allocator = allocator
@@ -65,7 +71,7 @@ _shift_down :: proc(pq: ^$Q/Priority_Queue($T), i0, n: int) -> bool {
}
j, j2 = j1, j1+1
if j1 < n && pq.less(queue[j2], queue[j1]) {
- j1 = j2
+ j = j2
}
if !pq.less(queue[i], queue[j]) {
break