mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-18 20:40:28 +00:00
Add slice.min and add slice.max
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package slice
|
||||
|
||||
import "intrinsics"
|
||||
import "builtin"
|
||||
import "core:math/bits"
|
||||
import "core:mem"
|
||||
|
||||
_ :: intrinsics;
|
||||
_ :: builtin;
|
||||
_ :: bits;
|
||||
_ :: mem;
|
||||
|
||||
@@ -292,6 +294,28 @@ filter :: proc(s: $S/[]$U, f: proc(U) -> bool, allocator := context.allocator) -
|
||||
|
||||
|
||||
|
||||
min :: proc(s: $S/[]$T) -> (res: T, ok: bool) where intrinsics.type_is_ordered(T) #optional_ok {
|
||||
if len(s) != 0 {
|
||||
res = s[0];
|
||||
ok = true;
|
||||
for v in s[1:] {
|
||||
res = min(res, v);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
max :: proc(s: $S/[]$T) -> (res: T, ok: bool) where intrinsics.type_is_ordered(T) #optional_ok {
|
||||
if len(s) != 0 {
|
||||
res = s[0];
|
||||
ok = true;
|
||||
for v in s[1:] {
|
||||
res = max(res, v);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
dot_product :: proc(a, b: $S/[]$T) -> T
|
||||
where intrinsics.type_is_numeric(T) {
|
||||
if len(a) != len(b) {
|
||||
|
||||
Reference in New Issue
Block a user