Add slice.swap_between

This commit is contained in:
gingerBill
2021-10-26 20:22:39 +01:00
parent 802df73183
commit 9e754cb0f1
2 changed files with 32 additions and 1 deletions
+8 -1
View File
@@ -11,7 +11,7 @@ _ :: bits
_ :: mem
swap :: proc(array: $T/[]$E, a, b: int, loc := #caller_location) {
swap :: proc(array: $T/[]$E, a, b: int) {
when size_of(E) > 8 {
ptr_swap_non_overlapping(&array[a], &array[b], size_of(E))
} else {
@@ -19,6 +19,13 @@ swap :: proc(array: $T/[]$E, a, b: int, loc := #caller_location) {
}
}
swap_between :: proc(a, b: $T/[]$E) {
n := min(len(a), len(b))
if n >= 0 {
ptr_swap_overlapping(&a[0], &b[0], size_of(E)*n)
}
}
reverse :: proc(array: $T/[]$E) {
n := len(array)/2