mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Deprecate sort.slice and sort.reverse_slice
This commit is contained in:
+9
-54
@@ -1,6 +1,7 @@
|
|||||||
package sort
|
package sort
|
||||||
|
|
||||||
import "core:mem"
|
import "core:mem"
|
||||||
|
import _slice "core:slice"
|
||||||
import "intrinsics"
|
import "intrinsics"
|
||||||
|
|
||||||
_ :: intrinsics;
|
_ :: intrinsics;
|
||||||
@@ -29,9 +30,11 @@ sort :: proc(it: Interface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@(deprecated="use slice.sort")
|
||||||
slice :: proc(array: $T/[]$E) where ORD(E) {
|
slice :: proc(array: $T/[]$E) where ORD(E) {
|
||||||
s := array;
|
_slice.sort(array);
|
||||||
sort(slice_interface(&s));
|
// s := array;
|
||||||
|
// sort(slice_interface(&s));
|
||||||
}
|
}
|
||||||
|
|
||||||
slice_interface :: proc(s: ^$T/[]$E) -> Interface where ORD(E) {
|
slice_interface :: proc(s: ^$T/[]$E) -> Interface where ORD(E) {
|
||||||
@@ -76,7 +79,10 @@ reverse_sort :: proc(it: Interface) {
|
|||||||
sort(reverse_interface(&it));
|
sort(reverse_interface(&it));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(deprecated="use slice.reverse")
|
||||||
reverse_slice :: proc(array: $T/[]$E) where ORD(E) {
|
reverse_slice :: proc(array: $T/[]$E) where ORD(E) {
|
||||||
|
_slice.reverse(array);
|
||||||
|
/*
|
||||||
s := array;
|
s := array;
|
||||||
sort(Interface{
|
sort(Interface{
|
||||||
collection = rawptr(&s),
|
collection = rawptr(&s),
|
||||||
@@ -93,6 +99,7 @@ reverse_slice :: proc(array: $T/[]$E) where ORD(E) {
|
|||||||
s[i], s[j] = s[j], s[i];
|
s[i], s[j] = s[j], s[i];
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -678,55 +685,3 @@ compare_strings :: proc(a, b: string) -> int {
|
|||||||
y := transmute(mem.Raw_String)b;
|
y := transmute(mem.Raw_String)b;
|
||||||
return mem.compare_byte_ptrs(x.data, y.data, min(x.len, y.len));
|
return mem.compare_byte_ptrs(x.data, y.data, min(x.len, y.len));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@(deprecated="use slice.binary_search")
|
|
||||||
binary_search :: proc(array: $A/[]$T, key: T) -> (index: int, found: bool)
|
|
||||||
where intrinsics.type_is_ordered(T) #no_bounds_check {
|
|
||||||
|
|
||||||
n := len(array);
|
|
||||||
switch n {
|
|
||||||
case 0:
|
|
||||||
return -1, false;
|
|
||||||
case 1:
|
|
||||||
if array[0] == key {
|
|
||||||
return 0, true;
|
|
||||||
}
|
|
||||||
return -1, false;
|
|
||||||
}
|
|
||||||
|
|
||||||
lo, hi := 0, n-1;
|
|
||||||
|
|
||||||
for array[hi] != array[lo] && key >= array[lo] && key <= array[hi] {
|
|
||||||
when intrinsics.type_is_ordered_numeric(T) {
|
|
||||||
// NOTE(bill): This is technically interpolation search
|
|
||||||
m := lo + int((key - array[lo]) * T(hi - lo) / (array[hi] - array[lo]));
|
|
||||||
} else {
|
|
||||||
m := (lo + hi)/2;
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case array[m] < key:
|
|
||||||
lo = m + 1;
|
|
||||||
case key < array[m]:
|
|
||||||
hi = m - 1;
|
|
||||||
case:
|
|
||||||
return m, true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if key == array[lo] {
|
|
||||||
return lo, true;
|
|
||||||
}
|
|
||||||
return -1, false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@(deprecated="use slice.linear_search")
|
|
||||||
linear_search :: proc(array: $A/[]$T, key: T) -> (index: int, found: bool)
|
|
||||||
where intrinsics.type_is_comparable(T) #no_bounds_check {
|
|
||||||
for x, i in array {
|
|
||||||
if x == key {
|
|
||||||
return i, true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1, false;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user