mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 20:58:15 +00:00
Add slice.swap_between
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package slice
|
||||
|
||||
import "core:builtin"
|
||||
import "core:mem"
|
||||
|
||||
ptr_add :: proc(p: $P/^$T, x: int) -> ^T {
|
||||
@@ -43,6 +44,29 @@ ptr_swap_non_overlapping :: proc(x, y: rawptr, len: int) {
|
||||
}
|
||||
}
|
||||
|
||||
ptr_swap_overlapping :: proc(x, y: rawptr, len: int) {
|
||||
if len <= 0 {
|
||||
return
|
||||
}
|
||||
if x == y {
|
||||
return
|
||||
}
|
||||
|
||||
N :: 512
|
||||
buffer: [N]byte = ---
|
||||
|
||||
a, b := ([^]byte)(x), ([^]byte)(y)
|
||||
|
||||
for n := len; n > 0; n -= N {
|
||||
m := builtin.min(n, N)
|
||||
mem.copy(&buffer, a, m)
|
||||
mem.copy(a, b, m)
|
||||
mem.copy(b, &buffer, m)
|
||||
|
||||
a, b = a[N:], b[N:]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ptr_rotate :: proc(left: int, mid: ^$T, right: int) {
|
||||
when size_of(T) != 0 {
|
||||
|
||||
Reference in New Issue
Block a user