mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Update path/filepath to use new slice.sort; Add sort.reverse_interface
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package filepath
|
package filepath
|
||||||
|
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:sort"
|
import "core:slice"
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
import "core:unicode/utf8"
|
import "core:unicode/utf8"
|
||||||
|
|
||||||
@@ -284,8 +284,8 @@ _glob :: proc(dir, pattern: string, matches: ^[dynamic]string) -> (m: [dynamic]s
|
|||||||
|
|
||||||
|
|
||||||
fis, _ := os.read_dir(d, -1);
|
fis, _ := os.read_dir(d, -1);
|
||||||
sort.quick_sort_proc(fis, proc(a, b: os.File_Info) -> int {
|
slice.sort_proc(fis, proc(a, b: os.File_Info) -> bool {
|
||||||
return sort.compare_strings(a.name, b.name);
|
return a.name < b.name;
|
||||||
});
|
});
|
||||||
defer {
|
defer {
|
||||||
for fi in fis {
|
for fi in fis {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package filepath
|
package filepath
|
||||||
|
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:sort"
|
import "core:slice"
|
||||||
|
|
||||||
// Walk_Proc is the type of the procedure called for each file or directory visited by 'walk'
|
// Walk_Proc is the type of the procedure called for each file or directory visited by 'walk'
|
||||||
// The 'path' parameter contains the parameter to walk as a prefix (this is the same as info.fullpath except on 'root')
|
// The 'path' parameter contains the parameter to walk as a prefix (this is the same as info.fullpath except on 'root')
|
||||||
@@ -81,8 +81,8 @@ read_dir :: proc(dir_name: string, allocator := context.temp_allocator) -> ([]os
|
|||||||
if err != 0 {
|
if err != 0 {
|
||||||
return nil, err;
|
return nil, err;
|
||||||
}
|
}
|
||||||
sort.quick_sort_proc(fis, proc(a, b: os.File_Info) -> int {
|
slice.sort_proc(fis, proc(a, b: os.File_Info) -> bool {
|
||||||
return sort.compare_strings(a.name, b.name);
|
return a.name < b.name;
|
||||||
});
|
});
|
||||||
return fis, 0;
|
return fis, 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-10
@@ -52,10 +52,9 @@ slice_interface :: proc(s: ^$T/[]$E) -> Interface where ORD(E) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
reverse_sort :: proc(it: Interface) {
|
reverse_interface :: proc(it: ^Interface) -> Interface {
|
||||||
it := it;
|
return Interface{
|
||||||
sort(Interface{
|
collection = it,
|
||||||
collection = &it,
|
|
||||||
|
|
||||||
len = proc(rit: Interface) -> int {
|
len = proc(rit: Interface) -> int {
|
||||||
it := (^Interface)(rit.collection);
|
it := (^Interface)(rit.collection);
|
||||||
@@ -69,7 +68,12 @@ reverse_sort :: proc(it: Interface) {
|
|||||||
it := (^Interface)(rit.collection);
|
it := (^Interface)(rit.collection);
|
||||||
it.swap(it^, i, j);
|
it.swap(it^, i, j);
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
reverse_sort :: proc(it: Interface) {
|
||||||
|
it := it;
|
||||||
|
sort(reverse_interface(&it));
|
||||||
}
|
}
|
||||||
|
|
||||||
reverse_slice :: proc(array: $T/[]$E) where ORD(E) {
|
reverse_slice :: proc(array: $T/[]$E) where ORD(E) {
|
||||||
@@ -269,11 +273,15 @@ _quick_sort :: proc(it: Interface, a, b, max_depth: int) {
|
|||||||
it->swap(i, i-6);
|
it->swap(i, i-6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// insertion sort
|
_insertion_sort(it, a, b);
|
||||||
for i in a+1..<b {
|
}
|
||||||
for j := i; j > a && it->less(j, j-1); j -= 1 {
|
}
|
||||||
it->swap(j, j-1);
|
|
||||||
}
|
@(private)
|
||||||
|
_insertion_sort :: proc(it: Interface, a, b: int) {
|
||||||
|
for i in a+1..<b {
|
||||||
|
for j := i; j > a && it->less(j, j-1); j -= 1 {
|
||||||
|
it->swap(j, j-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user