mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 05:08:14 +00:00
Fix core:slice.rotate_left
This commit includes two fixes: - a temporary cast to make the function compile - a fix to a logic error that caused the function to hang or return incorrect results
This commit is contained in:
+5
-13
@@ -73,25 +73,17 @@ ptr_rotate :: proc(left: int, mid: ^$T, right: int) {
|
||||
left, mid, right := left, mid, right
|
||||
|
||||
// TODO(bill): Optimization with a buffer for smaller ranges
|
||||
if left >= right {
|
||||
for {
|
||||
ptr_swap_non_overlapping(ptr_sub(mid, right), mid, right)
|
||||
for left > 0 && right > 0 {
|
||||
if left >= right {
|
||||
ptr_swap_non_overlapping(ptr_sub(mid, right), mid, right * size_of(T))
|
||||
mid = ptr_sub(mid, right)
|
||||
|
||||
left -= right
|
||||
if left < right {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for {
|
||||
ptr_swap_non_overlapping(ptr_sub(mid, left), mid, left)
|
||||
} else {
|
||||
ptr_swap_non_overlapping(ptr_sub(mid, left), mid, left * size_of(T))
|
||||
mid = ptr_add(mid, left)
|
||||
|
||||
right -= left
|
||||
if right < left {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user